UI for Zipcoin Blue

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430
  1. /*
  2. Rollup.js v0.50.0
  3. Sat Sep 16 2017 09:48:09 GMT-0400 (EDT) - commit b949eb08169115ff66648838cbc4833379bf9440
  4. https://github.com/rollup/rollup
  5. Released under the MIT License.
  6. */
  7. import path, { basename, dirname, extname, relative, resolve, sep } from 'path';
  8. import { lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeFile } from 'fs';
  9. import EventEmitter from 'events';
  10. import module$1 from 'module';
  11. const DEBUG = false;
  12. const map = new Map;
  13. let timeStartHelper;
  14. let timeEndHelper;
  15. if ( typeof process === 'undefined' || typeof process.hrtime === 'undefined' ) {
  16. timeStartHelper = function timeStartHelper () {
  17. return window.performance.now();
  18. };
  19. timeEndHelper = function timeEndHelper ( previous ) {
  20. return window.performance.now() - previous;
  21. };
  22. } else {
  23. timeStartHelper = function timeStartHelper () {
  24. return process.hrtime();
  25. };
  26. timeEndHelper = function timeEndHelper ( previous ) {
  27. const hrtime = process.hrtime( previous );
  28. return hrtime[0] * 1e3 + Math.floor( hrtime[1] / 1e6 );
  29. };
  30. }
  31. function timeStart ( label ) {
  32. if ( !map.has( label ) ) {
  33. map.set( label, {
  34. time: 0
  35. });
  36. }
  37. map.get( label ).start = timeStartHelper();
  38. }
  39. function timeEnd ( label ) {
  40. if ( map.has( label ) ) {
  41. const item = map.get( label );
  42. item.time += timeEndHelper( item.start );
  43. }
  44. }
  45. function flushTime ( log ) {
  46. if ( log === void 0 ) log = defaultLog;
  47. for ( const item of map.entries() ) {
  48. log( item[0], item[1].time );
  49. }
  50. map.clear();
  51. }
  52. function defaultLog ( label, time ) {
  53. if ( DEBUG ) {
  54. /* eslint-disable no-console */
  55. console.info( '%dms: %s', time, label );
  56. /* eslint-enable no-console */
  57. }
  58. }
  59. const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;
  60. const relativePath = /^\.?\.\//;
  61. function isAbsolute ( path$$1 ) {
  62. return absolutePath.test( path$$1 );
  63. }
  64. function isRelative ( path$$1 ) {
  65. return relativePath.test( path$$1 );
  66. }
  67. function normalize ( path$$1 ) {
  68. return path$$1.replace( /\\/g, '/' );
  69. }
  70. function mkdirpath ( path$$1 ) {
  71. const dir = dirname( path$$1 );
  72. try {
  73. readdirSync( dir );
  74. } catch ( err ) {
  75. mkdirpath( dir );
  76. try {
  77. mkdirSync( dir );
  78. } catch (err2) {
  79. if (err2.code !== 'EEXIST') {
  80. throw err2;
  81. }
  82. }
  83. }
  84. }
  85. function writeFile$1 ( dest, data ) {
  86. return new Promise( ( fulfil, reject ) => {
  87. mkdirpath( dest );
  88. writeFile( dest, data, err => {
  89. if ( err ) {
  90. reject( err );
  91. } else {
  92. fulfil();
  93. }
  94. });
  95. });
  96. }
  97. var keys = Object.keys;
  98. function blank () {
  99. return Object.create( null );
  100. }
  101. function forOwn ( object, func ) {
  102. Object.keys( object ).forEach( key => func( object[ key ], key ) );
  103. }
  104. function assign ( target ) {
  105. var sources = [], len = arguments.length - 1;
  106. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  107. sources.forEach( source => {
  108. for ( const key in source ) {
  109. if ( source.hasOwnProperty( key ) ) { target[ key ] = source[ key ]; }
  110. }
  111. });
  112. return target;
  113. }
  114. function mapSequence ( array, fn ) {
  115. const results = [];
  116. let promise = Promise.resolve();
  117. function next ( member, i ) {
  118. return Promise.resolve( fn( member ) ).then( value => results[i] = value );
  119. }
  120. for ( let i = 0; i < array.length; i += 1 ) {
  121. promise = promise.then( () => next( array[i], i ) );
  122. }
  123. return promise.then( () => results );
  124. }
  125. function validateKeys ( actualKeys, allowedKeys ) {
  126. let i = actualKeys.length;
  127. while ( i-- ) {
  128. const key = actualKeys[i];
  129. if ( allowedKeys.indexOf( key ) === -1 ) {
  130. return new Error(
  131. `Unexpected key '${ key }' found, expected one of: ${ allowedKeys.join( ', ' ) }`
  132. );
  133. }
  134. }
  135. }
  136. function error ( props ) {
  137. // use the same constructor as props (if it's an error object)
  138. // so that err.name is preserved etc
  139. // (Object.keys below does not update these values because they
  140. // are properties on the prototype chain)
  141. // basically if props is a SyntaxError it will not be overriden as a generic Error
  142. const constructor = (props instanceof Error) ? props.constructor : Error;
  143. const err = new constructor( props.message );
  144. Object.keys( props ).forEach( key => {
  145. err[ key ] = props[ key ];
  146. });
  147. throw err;
  148. }
  149. // this looks ridiculous, but it prevents sourcemap tooling from mistaking
  150. // this for an actual sourceMappingURL
  151. let SOURCEMAPPING_URL = 'sourceMa';
  152. SOURCEMAPPING_URL += 'ppingURL';
  153. const SOURCEMAPPING_URL_RE = new RegExp( `^#\\s+${SOURCEMAPPING_URL}=.+\\n?` );
  154. var charToInteger = {};
  155. var integerToChar = {};
  156. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
  157. charToInteger[ char ] = i;
  158. integerToChar[ i ] = char;
  159. });
  160. function decode$1 ( string ) {
  161. var result = [],
  162. len = string.length,
  163. i,
  164. hasContinuationBit,
  165. shift = 0,
  166. value = 0,
  167. integer,
  168. shouldNegate;
  169. for ( i = 0; i < len; i += 1 ) {
  170. integer = charToInteger[ string[i] ];
  171. if ( integer === undefined ) {
  172. throw new Error( 'Invalid character (' + string[i] + ')' );
  173. }
  174. hasContinuationBit = integer & 32;
  175. integer &= 31;
  176. value += integer << shift;
  177. if ( hasContinuationBit ) {
  178. shift += 5;
  179. } else {
  180. shouldNegate = value & 1;
  181. value >>= 1;
  182. result.push( shouldNegate ? -value : value );
  183. // reset
  184. value = shift = 0;
  185. }
  186. }
  187. return result;
  188. }
  189. function encode$1 ( value ) {
  190. var result, i;
  191. if ( typeof value === 'number' ) {
  192. result = encodeInteger( value );
  193. } else {
  194. result = '';
  195. for ( i = 0; i < value.length; i += 1 ) {
  196. result += encodeInteger( value[i] );
  197. }
  198. }
  199. return result;
  200. }
  201. function encodeInteger ( num ) {
  202. var result = '', clamped;
  203. if ( num < 0 ) {
  204. num = ( -num << 1 ) | 1;
  205. } else {
  206. num <<= 1;
  207. }
  208. do {
  209. clamped = num & 31;
  210. num >>= 5;
  211. if ( num > 0 ) {
  212. clamped |= 32;
  213. }
  214. result += integerToChar[ clamped ];
  215. } while ( num > 0 );
  216. return result;
  217. }
  218. function decodeSegments ( encodedSegments ) {
  219. var i = encodedSegments.length;
  220. var segments = new Array( i );
  221. while ( i-- ) { segments[i] = decode$1( encodedSegments[i] ); }
  222. return segments;
  223. }
  224. function decode$$1 ( mappings ) {
  225. var sourceFileIndex = 0; // second field
  226. var sourceCodeLine = 0; // third field
  227. var sourceCodeColumn = 0; // fourth field
  228. var nameIndex = 0; // fifth field
  229. var lines = mappings.split( ';' );
  230. var numLines = lines.length;
  231. var decoded = new Array( numLines );
  232. var i;
  233. var j;
  234. var line;
  235. var generatedCodeColumn;
  236. var decodedLine;
  237. var segments;
  238. var segment;
  239. var result;
  240. for ( i = 0; i < numLines; i += 1 ) {
  241. line = lines[i];
  242. generatedCodeColumn = 0; // first field - reset each time
  243. decodedLine = [];
  244. segments = decodeSegments( line.split( ',' ) );
  245. for ( j = 0; j < segments.length; j += 1 ) {
  246. segment = segments[j];
  247. if ( !segment.length ) {
  248. break;
  249. }
  250. generatedCodeColumn += segment[0];
  251. result = [ generatedCodeColumn ];
  252. decodedLine.push( result );
  253. if ( segment.length === 1 ) {
  254. // only one field!
  255. continue;
  256. }
  257. sourceFileIndex += segment[1];
  258. sourceCodeLine += segment[2];
  259. sourceCodeColumn += segment[3];
  260. result.push( sourceFileIndex, sourceCodeLine, sourceCodeColumn );
  261. if ( segment.length === 5 ) {
  262. nameIndex += segment[4];
  263. result.push( nameIndex );
  264. }
  265. }
  266. decoded[i] = decodedLine;
  267. }
  268. return decoded;
  269. }
  270. function encode$$1 ( decoded ) {
  271. var offsets = {
  272. generatedCodeColumn: 0,
  273. sourceFileIndex: 0, // second field
  274. sourceCodeLine: 0, // third field
  275. sourceCodeColumn: 0, // fourth field
  276. nameIndex: 0 // fifth field
  277. };
  278. return decoded.map( function (line) {
  279. offsets.generatedCodeColumn = 0; // first field - reset each time
  280. return line.map( encodeSegment ).join( ',' );
  281. }).join( ';' );
  282. function encodeSegment ( segment ) {
  283. if ( !segment.length ) {
  284. return segment;
  285. }
  286. var result = new Array( segment.length );
  287. result[0] = segment[0] - offsets.generatedCodeColumn;
  288. offsets.generatedCodeColumn = segment[0];
  289. if ( segment.length === 1 ) {
  290. // only one field!
  291. return encode$1( result );
  292. }
  293. result[1] = segment[1] - offsets.sourceFileIndex;
  294. result[2] = segment[2] - offsets.sourceCodeLine;
  295. result[3] = segment[3] - offsets.sourceCodeColumn;
  296. offsets.sourceFileIndex = segment[1];
  297. offsets.sourceCodeLine = segment[2];
  298. offsets.sourceCodeColumn = segment[3];
  299. if ( segment.length === 5 ) {
  300. result[4] = segment[4] - offsets.nameIndex;
  301. offsets.nameIndex = segment[4];
  302. }
  303. return encode$1( result );
  304. }
  305. }
  306. var charToInteger$1 = {};
  307. var integerToChar$1 = {};
  308. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
  309. charToInteger$1[ char ] = i;
  310. integerToChar$1[ i ] = char;
  311. });
  312. function encode ( value ) {
  313. var result;
  314. if ( typeof value === 'number' ) {
  315. result = encodeInteger$1( value );
  316. } else {
  317. result = '';
  318. for ( var i = 0; i < value.length; i += 1 ) {
  319. result += encodeInteger$1( value[i] );
  320. }
  321. }
  322. return result;
  323. }
  324. function encodeInteger$1 ( num ) {
  325. var result = '';
  326. if ( num < 0 ) {
  327. num = ( -num << 1 ) | 1;
  328. } else {
  329. num <<= 1;
  330. }
  331. do {
  332. var clamped = num & 31;
  333. num >>= 5;
  334. if ( num > 0 ) {
  335. clamped |= 32;
  336. }
  337. result += integerToChar$1[ clamped ];
  338. } while ( num > 0 );
  339. return result;
  340. }
  341. function Chunk ( start, end, content ) {
  342. this.start = start;
  343. this.end = end;
  344. this.original = content;
  345. this.intro = '';
  346. this.outro = '';
  347. this.content = content;
  348. this.storeName = false;
  349. this.edited = false;
  350. // we make these non-enumerable, for sanity while debugging
  351. Object.defineProperties( this, {
  352. previous: { writable: true, value: null },
  353. next: { writable: true, value: null }
  354. });
  355. }
  356. Chunk.prototype = {
  357. appendLeft: function appendLeft ( content ) {
  358. this.outro += content;
  359. },
  360. appendRight: function appendRight ( content ) {
  361. this.intro = this.intro + content;
  362. },
  363. clone: function clone () {
  364. var chunk = new Chunk( this.start, this.end, this.original );
  365. chunk.intro = this.intro;
  366. chunk.outro = this.outro;
  367. chunk.content = this.content;
  368. chunk.storeName = this.storeName;
  369. chunk.edited = this.edited;
  370. return chunk;
  371. },
  372. contains: function contains ( index ) {
  373. return this.start < index && index < this.end;
  374. },
  375. eachNext: function eachNext ( fn ) {
  376. var chunk = this;
  377. while ( chunk ) {
  378. fn( chunk );
  379. chunk = chunk.next;
  380. }
  381. },
  382. eachPrevious: function eachPrevious ( fn ) {
  383. var chunk = this;
  384. while ( chunk ) {
  385. fn( chunk );
  386. chunk = chunk.previous;
  387. }
  388. },
  389. edit: function edit ( content, storeName, contentOnly ) {
  390. this.content = content;
  391. if ( !contentOnly ) {
  392. this.intro = '';
  393. this.outro = '';
  394. }
  395. this.storeName = storeName;
  396. this.edited = true;
  397. return this;
  398. },
  399. prependLeft: function prependLeft ( content ) {
  400. this.outro = content + this.outro;
  401. },
  402. prependRight: function prependRight ( content ) {
  403. this.intro = content + this.intro;
  404. },
  405. split: function split ( index ) {
  406. var sliceIndex = index - this.start;
  407. var originalBefore = this.original.slice( 0, sliceIndex );
  408. var originalAfter = this.original.slice( sliceIndex );
  409. this.original = originalBefore;
  410. var newChunk = new Chunk( index, this.end, originalAfter );
  411. newChunk.outro = this.outro;
  412. this.outro = '';
  413. this.end = index;
  414. if ( this.edited ) {
  415. // TODO is this block necessary?...
  416. newChunk.edit( '', false );
  417. this.content = '';
  418. } else {
  419. this.content = originalBefore;
  420. }
  421. newChunk.next = this.next;
  422. if ( newChunk.next ) { newChunk.next.previous = newChunk; }
  423. newChunk.previous = this;
  424. this.next = newChunk;
  425. return newChunk;
  426. },
  427. toString: function toString () {
  428. return this.intro + this.content + this.outro;
  429. },
  430. trimEnd: function trimEnd ( rx ) {
  431. this.outro = this.outro.replace( rx, '' );
  432. if ( this.outro.length ) { return true; }
  433. var trimmed = this.content.replace( rx, '' );
  434. if ( trimmed.length ) {
  435. if ( trimmed !== this.content ) {
  436. this.split( this.start + trimmed.length ).edit( '', false );
  437. }
  438. return true;
  439. } else {
  440. this.edit( '', false );
  441. this.intro = this.intro.replace( rx, '' );
  442. if ( this.intro.length ) { return true; }
  443. }
  444. },
  445. trimStart: function trimStart ( rx ) {
  446. this.intro = this.intro.replace( rx, '' );
  447. if ( this.intro.length ) { return true; }
  448. var trimmed = this.content.replace( rx, '' );
  449. if ( trimmed.length ) {
  450. if ( trimmed !== this.content ) {
  451. this.split( this.end - trimmed.length );
  452. this.edit( '', false );
  453. }
  454. return true;
  455. } else {
  456. this.edit( '', false );
  457. this.outro = this.outro.replace( rx, '' );
  458. if ( this.outro.length ) { return true; }
  459. }
  460. }
  461. };
  462. var _btoa;
  463. if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
  464. _btoa = window.btoa;
  465. } else if ( typeof Buffer === 'function' ) {
  466. _btoa = function (str) { return new Buffer( str ).toString( 'base64' ); };
  467. } else {
  468. _btoa = function () {
  469. throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
  470. };
  471. }
  472. var btoa = _btoa;
  473. function SourceMap ( properties ) {
  474. this.version = 3;
  475. this.file = properties.file;
  476. this.sources = properties.sources;
  477. this.sourcesContent = properties.sourcesContent;
  478. this.names = properties.names;
  479. this.mappings = properties.mappings;
  480. }
  481. SourceMap.prototype = {
  482. toString: function toString () {
  483. return JSON.stringify( this );
  484. },
  485. toUrl: function toUrl () {
  486. return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
  487. }
  488. };
  489. function guessIndent ( code ) {
  490. var lines = code.split( '\n' );
  491. var tabbed = lines.filter( function (line) { return /^\t+/.test( line ); } );
  492. var spaced = lines.filter( function (line) { return /^ {2,}/.test( line ); } );
  493. if ( tabbed.length === 0 && spaced.length === 0 ) {
  494. return null;
  495. }
  496. // More lines tabbed than spaced? Assume tabs, and
  497. // default to tabs in the case of a tie (or nothing
  498. // to go on)
  499. if ( tabbed.length >= spaced.length ) {
  500. return '\t';
  501. }
  502. // Otherwise, we need to guess the multiple
  503. var min = spaced.reduce( function ( previous, current ) {
  504. var numSpaces = /^ +/.exec( current )[0].length;
  505. return Math.min( numSpaces, previous );
  506. }, Infinity );
  507. return new Array( min + 1 ).join( ' ' );
  508. }
  509. function getRelativePath ( from, to ) {
  510. var fromParts = from.split( /[\/\\]/ );
  511. var toParts = to.split( /[\/\\]/ );
  512. fromParts.pop(); // get dirname
  513. while ( fromParts[0] === toParts[0] ) {
  514. fromParts.shift();
  515. toParts.shift();
  516. }
  517. if ( fromParts.length ) {
  518. var i = fromParts.length;
  519. while ( i-- ) { fromParts[i] = '..'; }
  520. }
  521. return fromParts.concat( toParts ).join( '/' );
  522. }
  523. var toString$1 = Object.prototype.toString;
  524. function isObject ( thing ) {
  525. return toString$1.call( thing ) === '[object Object]';
  526. }
  527. function getLocator ( source ) {
  528. var originalLines = source.split( '\n' );
  529. var start = 0;
  530. var lineRanges = originalLines.map( function ( line, i ) {
  531. var end = start + line.length + 1;
  532. var range = { start: start, end: end, line: i };
  533. start = end;
  534. return range;
  535. });
  536. var i = 0;
  537. function rangeContains ( range, index ) {
  538. return range.start <= index && index < range.end;
  539. }
  540. function getLocation ( range, index ) {
  541. return { line: range.line, column: index - range.start };
  542. }
  543. return function locate ( index ) {
  544. var range = lineRanges[i];
  545. var d = index >= range.end ? 1 : -1;
  546. while ( range ) {
  547. if ( rangeContains( range, index ) ) { return getLocation( range, index ); }
  548. i += d;
  549. range = lineRanges[i];
  550. }
  551. };
  552. }
  553. function Mappings ( hires ) {
  554. var this$1 = this;
  555. var offsets = {
  556. generatedCodeColumn: 0,
  557. sourceIndex: 0,
  558. sourceCodeLine: 0,
  559. sourceCodeColumn: 0,
  560. sourceCodeName: 0
  561. };
  562. var generatedCodeLine = 0;
  563. var generatedCodeColumn = 0;
  564. this.raw = [];
  565. var rawSegments = this.raw[ generatedCodeLine ] = [];
  566. var pending = null;
  567. this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
  568. if ( content.length ) {
  569. rawSegments.push([
  570. generatedCodeColumn,
  571. sourceIndex,
  572. loc.line,
  573. loc.column,
  574. nameIndex ]);
  575. } else if ( pending ) {
  576. rawSegments.push( pending );
  577. }
  578. this$1.advance( content );
  579. pending = null;
  580. };
  581. this.addUneditedChunk = function ( sourceIndex, chunk, original, loc, sourcemapLocations ) {
  582. var originalCharIndex = chunk.start;
  583. var first = true;
  584. while ( originalCharIndex < chunk.end ) {
  585. if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
  586. rawSegments.push([
  587. generatedCodeColumn,
  588. sourceIndex,
  589. loc.line,
  590. loc.column,
  591. -1
  592. ]);
  593. }
  594. if ( original[ originalCharIndex ] === '\n' ) {
  595. loc.line += 1;
  596. loc.column = 0;
  597. generatedCodeLine += 1;
  598. this$1.raw[ generatedCodeLine ] = rawSegments = [];
  599. generatedCodeColumn = 0;
  600. } else {
  601. loc.column += 1;
  602. generatedCodeColumn += 1;
  603. }
  604. originalCharIndex += 1;
  605. first = false;
  606. }
  607. pending = [
  608. generatedCodeColumn,
  609. sourceIndex,
  610. loc.line,
  611. loc.column,
  612. -1 ];
  613. };
  614. this.advance = function (str) {
  615. if ( !str ) { return; }
  616. var lines = str.split( '\n' );
  617. var lastLine = lines.pop();
  618. if ( lines.length ) {
  619. generatedCodeLine += lines.length;
  620. this$1.raw[ generatedCodeLine ] = rawSegments = [];
  621. generatedCodeColumn = lastLine.length;
  622. } else {
  623. generatedCodeColumn += lastLine.length;
  624. }
  625. };
  626. this.encode = function () {
  627. return this$1.raw.map( function (segments) {
  628. var generatedCodeColumn = 0;
  629. return segments.map( function (segment) {
  630. var arr = [
  631. segment[0] - generatedCodeColumn,
  632. segment[1] - offsets.sourceIndex,
  633. segment[2] - offsets.sourceCodeLine,
  634. segment[3] - offsets.sourceCodeColumn
  635. ];
  636. generatedCodeColumn = segment[0];
  637. offsets.sourceIndex = segment[1];
  638. offsets.sourceCodeLine = segment[2];
  639. offsets.sourceCodeColumn = segment[3];
  640. if ( ~segment[4] ) {
  641. arr.push( segment[4] - offsets.sourceCodeName );
  642. offsets.sourceCodeName = segment[4];
  643. }
  644. return encode( arr );
  645. }).join( ',' );
  646. }).join( ';' );
  647. };
  648. }
  649. var Stats = function Stats () {
  650. Object.defineProperties( this, {
  651. startTimes: { value: {} }
  652. });
  653. };
  654. Stats.prototype.time = function time ( label ) {
  655. this.startTimes[ label ] = process.hrtime();
  656. };
  657. Stats.prototype.timeEnd = function timeEnd ( label ) {
  658. var elapsed = process.hrtime( this.startTimes[ label ] );
  659. if ( !this[ label ] ) { this[ label ] = 0; }
  660. this[ label ] += elapsed[0] * 1e3 + elapsed[1] * 1e-6;
  661. };
  662. var warned = {
  663. insertLeft: false,
  664. insertRight: false,
  665. storeName: false
  666. };
  667. function MagicString$1 ( string, options ) {
  668. if ( options === void 0 ) options = {};
  669. var chunk = new Chunk( 0, string.length, string );
  670. Object.defineProperties( this, {
  671. original: { writable: true, value: string },
  672. outro: { writable: true, value: '' },
  673. intro: { writable: true, value: '' },
  674. firstChunk: { writable: true, value: chunk },
  675. lastChunk: { writable: true, value: chunk },
  676. lastSearchedChunk: { writable: true, value: chunk },
  677. byStart: { writable: true, value: {} },
  678. byEnd: { writable: true, value: {} },
  679. filename: { writable: true, value: options.filename },
  680. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  681. sourcemapLocations: { writable: true, value: {} },
  682. storedNames: { writable: true, value: {} },
  683. indentStr: { writable: true, value: guessIndent( string ) }
  684. });
  685. this.byStart[ 0 ] = chunk;
  686. this.byEnd[ string.length ] = chunk;
  687. }
  688. MagicString$1.prototype = {
  689. addSourcemapLocation: function addSourcemapLocation ( char ) {
  690. this.sourcemapLocations[ char ] = true;
  691. },
  692. append: function append ( content ) {
  693. if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
  694. this.outro += content;
  695. return this;
  696. },
  697. appendLeft: function appendLeft ( index, content ) {
  698. if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
  699. this._split( index );
  700. var chunk = this.byEnd[ index ];
  701. if ( chunk ) {
  702. chunk.appendLeft( content );
  703. } else {
  704. this.intro += content;
  705. }
  706. return this;
  707. },
  708. appendRight: function appendRight ( index, content ) {
  709. if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
  710. this._split( index );
  711. var chunk = this.byStart[ index ];
  712. if ( chunk ) {
  713. chunk.appendRight( content );
  714. } else {
  715. this.outro += content;
  716. }
  717. return this;
  718. },
  719. clone: function clone () {
  720. var cloned = new MagicString$1( this.original, { filename: this.filename });
  721. var originalChunk = this.firstChunk;
  722. var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
  723. while ( originalChunk ) {
  724. cloned.byStart[ clonedChunk.start ] = clonedChunk;
  725. cloned.byEnd[ clonedChunk.end ] = clonedChunk;
  726. var nextOriginalChunk = originalChunk.next;
  727. var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  728. if ( nextClonedChunk ) {
  729. clonedChunk.next = nextClonedChunk;
  730. nextClonedChunk.previous = clonedChunk;
  731. clonedChunk = nextClonedChunk;
  732. }
  733. originalChunk = nextOriginalChunk;
  734. }
  735. cloned.lastChunk = clonedChunk;
  736. if ( this.indentExclusionRanges ) {
  737. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  738. }
  739. Object.keys( this.sourcemapLocations ).forEach( function (loc) {
  740. cloned.sourcemapLocations[ loc ] = true;
  741. });
  742. return cloned;
  743. },
  744. generateMap: function generateMap ( options ) {
  745. var this$1 = this;
  746. options = options || {};
  747. var sourceIndex = 0;
  748. var names = Object.keys( this.storedNames );
  749. var mappings = new Mappings( options.hires );
  750. var locate = getLocator( this.original );
  751. if ( this.intro ) {
  752. mappings.advance( this.intro );
  753. }
  754. this.firstChunk.eachNext( function (chunk) {
  755. var loc = locate( chunk.start );
  756. if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
  757. if ( chunk.edited ) {
  758. mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
  759. } else {
  760. mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );
  761. }
  762. if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
  763. });
  764. var map = new SourceMap({
  765. file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
  766. sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
  767. sourcesContent: options.includeContent ? [ this.original ] : [ null ],
  768. names: names,
  769. mappings: mappings.encode()
  770. });
  771. return map;
  772. },
  773. getIndentString: function getIndentString () {
  774. return this.indentStr === null ? '\t' : this.indentStr;
  775. },
  776. indent: function indent ( indentStr, options ) {
  777. var this$1 = this;
  778. var pattern = /^[^\r\n]/gm;
  779. if ( isObject( indentStr ) ) {
  780. options = indentStr;
  781. indentStr = undefined;
  782. }
  783. indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
  784. if ( indentStr === '' ) { return this; } // noop
  785. options = options || {};
  786. // Process exclusion ranges
  787. var isExcluded = {};
  788. if ( options.exclude ) {
  789. var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
  790. exclusions.forEach( function (exclusion) {
  791. for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
  792. isExcluded[i] = true;
  793. }
  794. });
  795. }
  796. var shouldIndentNextCharacter = options.indentStart !== false;
  797. var replacer = function (match) {
  798. if ( shouldIndentNextCharacter ) { return ("" + indentStr + match); }
  799. shouldIndentNextCharacter = true;
  800. return match;
  801. };
  802. this.intro = this.intro.replace( pattern, replacer );
  803. var charIndex = 0;
  804. var chunk = this.firstChunk;
  805. while ( chunk ) {
  806. var end = chunk.end;
  807. if ( chunk.edited ) {
  808. if ( !isExcluded[ charIndex ] ) {
  809. chunk.content = chunk.content.replace( pattern, replacer );
  810. if ( chunk.content.length ) {
  811. shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
  812. }
  813. }
  814. } else {
  815. charIndex = chunk.start;
  816. while ( charIndex < end ) {
  817. if ( !isExcluded[ charIndex ] ) {
  818. var char = this$1.original[ charIndex ];
  819. if ( char === '\n' ) {
  820. shouldIndentNextCharacter = true;
  821. } else if ( char !== '\r' && shouldIndentNextCharacter ) {
  822. shouldIndentNextCharacter = false;
  823. if ( charIndex === chunk.start ) {
  824. chunk.prependRight( indentStr );
  825. } else {
  826. this$1._splitChunk( chunk, charIndex );
  827. chunk = chunk.next;
  828. chunk.prependRight( indentStr );
  829. }
  830. }
  831. }
  832. charIndex += 1;
  833. }
  834. }
  835. charIndex = chunk.end;
  836. chunk = chunk.next;
  837. }
  838. this.outro = this.outro.replace( pattern, replacer );
  839. return this;
  840. },
  841. insert: function insert () {
  842. throw new Error( 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)' );
  843. },
  844. insertLeft: function insertLeft ( index, content ) {
  845. if ( !warned.insertLeft ) {
  846. console.warn( 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead' ); // eslint-disable-line no-console
  847. warned.insertLeft = true;
  848. }
  849. return this.appendLeft( index, content );
  850. },
  851. insertRight: function insertRight ( index, content ) {
  852. if ( !warned.insertRight ) {
  853. console.warn( 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead' ); // eslint-disable-line no-console
  854. warned.insertRight = true;
  855. }
  856. return this.prependRight( index, content );
  857. },
  858. move: function move ( start, end, index ) {
  859. if ( index >= start && index <= end ) { throw new Error( 'Cannot move a selection inside itself' ); }
  860. this._split( start );
  861. this._split( end );
  862. this._split( index );
  863. var first = this.byStart[ start ];
  864. var last = this.byEnd[ end ];
  865. var oldLeft = first.previous;
  866. var oldRight = last.next;
  867. var newRight = this.byStart[ index ];
  868. if ( !newRight && last === this.lastChunk ) { return this; }
  869. var newLeft = newRight ? newRight.previous : this.lastChunk;
  870. if ( oldLeft ) { oldLeft.next = oldRight; }
  871. if ( oldRight ) { oldRight.previous = oldLeft; }
  872. if ( newLeft ) { newLeft.next = first; }
  873. if ( newRight ) { newRight.previous = last; }
  874. if ( !first.previous ) { this.firstChunk = last.next; }
  875. if ( !last.next ) {
  876. this.lastChunk = first.previous;
  877. this.lastChunk.next = null;
  878. }
  879. first.previous = newLeft;
  880. last.next = newRight || null;
  881. if ( !newLeft ) { this.firstChunk = first; }
  882. if ( !newRight ) { this.lastChunk = last; }
  883. return this;
  884. },
  885. overwrite: function overwrite ( start, end, content, options ) {
  886. var this$1 = this;
  887. if ( typeof content !== 'string' ) { throw new TypeError( 'replacement content must be a string' ); }
  888. while ( start < 0 ) { start += this$1.original.length; }
  889. while ( end < 0 ) { end += this$1.original.length; }
  890. if ( end > this.original.length ) { throw new Error( 'end is out of bounds' ); }
  891. if ( start === end ) { throw new Error( 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead' ); }
  892. this._split( start );
  893. this._split( end );
  894. if ( options === true ) {
  895. if ( !warned.storeName ) {
  896. console.warn( 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string' ); // eslint-disable-line no-console
  897. warned.storeName = true;
  898. }
  899. options = { storeName: true };
  900. }
  901. var storeName = options !== undefined ? options.storeName : false;
  902. var contentOnly = options !== undefined ? options.contentOnly : false;
  903. if ( storeName ) {
  904. var original = this.original.slice( start, end );
  905. this.storedNames[ original ] = true;
  906. }
  907. var first = this.byStart[ start ];
  908. var last = this.byEnd[ end ];
  909. if ( first ) {
  910. if ( end > first.end && first.next !== this.byStart[ first.end ] ) {
  911. throw new Error( 'Cannot overwrite across a split point' );
  912. }
  913. first.edit( content, storeName, contentOnly );
  914. if ( first !== last ) {
  915. var chunk = first.next;
  916. while ( chunk !== last ) {
  917. chunk.edit( '', false );
  918. chunk = chunk.next;
  919. }
  920. chunk.edit( '', false );
  921. }
  922. }
  923. else {
  924. // must be inserting at the end
  925. var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
  926. // TODO last chunk in the array may not be the last chunk, if it's moved...
  927. last.next = newChunk;
  928. newChunk.previous = last;
  929. }
  930. return this;
  931. },
  932. prepend: function prepend ( content ) {
  933. if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
  934. this.intro = content + this.intro;
  935. return this;
  936. },
  937. prependLeft: function prependLeft ( index, content ) {
  938. if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
  939. this._split( index );
  940. var chunk = this.byEnd[ index ];
  941. if ( chunk ) {
  942. chunk.prependLeft( content );
  943. } else {
  944. this.intro = content + this.intro;
  945. }
  946. return this;
  947. },
  948. prependRight: function prependRight ( index, content ) {
  949. if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
  950. this._split( index );
  951. var chunk = this.byStart[ index ];
  952. if ( chunk ) {
  953. chunk.prependRight( content );
  954. } else {
  955. this.outro = content + this.outro;
  956. }
  957. return this;
  958. },
  959. remove: function remove ( start, end ) {
  960. var this$1 = this;
  961. while ( start < 0 ) { start += this$1.original.length; }
  962. while ( end < 0 ) { end += this$1.original.length; }
  963. if ( start === end ) { return this; }
  964. if ( start < 0 || end > this.original.length ) { throw new Error( 'Character is out of bounds' ); }
  965. if ( start > end ) { throw new Error( 'end must be greater than start' ); }
  966. this._split( start );
  967. this._split( end );
  968. var chunk = this.byStart[ start ];
  969. while ( chunk ) {
  970. chunk.intro = '';
  971. chunk.outro = '';
  972. chunk.edit( '' );
  973. chunk = end > chunk.end ? this$1.byStart[ chunk.end ] : null;
  974. }
  975. return this;
  976. },
  977. slice: function slice ( start, end ) {
  978. var this$1 = this;
  979. if ( start === void 0 ) start = 0;
  980. if ( end === void 0 ) end = this.original.length;
  981. while ( start < 0 ) { start += this$1.original.length; }
  982. while ( end < 0 ) { end += this$1.original.length; }
  983. var result = '';
  984. // find start chunk
  985. var chunk = this.firstChunk;
  986. while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
  987. // found end chunk before start
  988. if ( chunk.start < end && chunk.end >= end ) {
  989. return result;
  990. }
  991. chunk = chunk.next;
  992. }
  993. if ( chunk && chunk.edited && chunk.start !== start ) { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
  994. var startChunk = chunk;
  995. while ( chunk ) {
  996. if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
  997. result += chunk.intro;
  998. }
  999. var containsEnd = chunk.start < end && chunk.end >= end;
  1000. if ( containsEnd && chunk.edited && chunk.end !== end ) { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
  1001. var sliceStart = startChunk === chunk ? start - chunk.start : 0;
  1002. var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  1003. result += chunk.content.slice( sliceStart, sliceEnd );
  1004. if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
  1005. result += chunk.outro;
  1006. }
  1007. if ( containsEnd ) {
  1008. break;
  1009. }
  1010. chunk = chunk.next;
  1011. }
  1012. return result;
  1013. },
  1014. // TODO deprecate this? not really very useful
  1015. snip: function snip ( start, end ) {
  1016. var clone = this.clone();
  1017. clone.remove( 0, start );
  1018. clone.remove( end, clone.original.length );
  1019. return clone;
  1020. },
  1021. _split: function _split ( index ) {
  1022. var this$1 = this;
  1023. if ( this.byStart[ index ] || this.byEnd[ index ] ) { return; }
  1024. var chunk = this.lastSearchedChunk;
  1025. var searchForward = index > chunk.end;
  1026. while ( true ) {
  1027. if ( chunk.contains( index ) ) { return this$1._splitChunk( chunk, index ); }
  1028. chunk = searchForward ?
  1029. this$1.byStart[ chunk.end ] :
  1030. this$1.byEnd[ chunk.start ];
  1031. }
  1032. },
  1033. _splitChunk: function _splitChunk ( chunk, index ) {
  1034. if ( chunk.edited && chunk.content.length ) { // zero-length edited chunks are a special case (overlapping replacements)
  1035. var loc = getLocator( this.original )( index );
  1036. throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
  1037. }
  1038. var newChunk = chunk.split( index );
  1039. this.byEnd[ index ] = chunk;
  1040. this.byStart[ index ] = newChunk;
  1041. this.byEnd[ newChunk.end ] = newChunk;
  1042. if ( chunk === this.lastChunk ) { this.lastChunk = newChunk; }
  1043. this.lastSearchedChunk = chunk;
  1044. return true;
  1045. },
  1046. toString: function toString () {
  1047. var str = this.intro;
  1048. var chunk = this.firstChunk;
  1049. while ( chunk ) {
  1050. str += chunk.toString();
  1051. chunk = chunk.next;
  1052. }
  1053. return str + this.outro;
  1054. },
  1055. trimLines: function trimLines () {
  1056. return this.trim('[\\r\\n]');
  1057. },
  1058. trim: function trim ( charType ) {
  1059. return this.trimStart( charType ).trimEnd( charType );
  1060. },
  1061. trimEnd: function trimEnd ( charType ) {
  1062. var this$1 = this;
  1063. var rx = new RegExp( ( charType || '\\s' ) + '+$' );
  1064. this.outro = this.outro.replace( rx, '' );
  1065. if ( this.outro.length ) { return this; }
  1066. var chunk = this.lastChunk;
  1067. do {
  1068. var end = chunk.end;
  1069. var aborted = chunk.trimEnd( rx );
  1070. // if chunk was trimmed, we have a new lastChunk
  1071. if ( chunk.end !== end ) {
  1072. if ( this$1.lastChunk === chunk ) {
  1073. this$1.lastChunk = chunk.next;
  1074. }
  1075. this$1.byEnd[ chunk.end ] = chunk;
  1076. this$1.byStart[ chunk.next.start ] = chunk.next;
  1077. this$1.byEnd[ chunk.next.end ] = chunk.next;
  1078. }
  1079. if ( aborted ) { return this$1; }
  1080. chunk = chunk.previous;
  1081. } while ( chunk );
  1082. return this;
  1083. },
  1084. trimStart: function trimStart ( charType ) {
  1085. var this$1 = this;
  1086. var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
  1087. this.intro = this.intro.replace( rx, '' );
  1088. if ( this.intro.length ) { return this; }
  1089. var chunk = this.firstChunk;
  1090. do {
  1091. var end = chunk.end;
  1092. var aborted = chunk.trimStart( rx );
  1093. if ( chunk.end !== end ) {
  1094. // special case...
  1095. if ( chunk === this$1.lastChunk ) { this$1.lastChunk = chunk.next; }
  1096. this$1.byEnd[ chunk.end ] = chunk;
  1097. this$1.byStart[ chunk.next.start ] = chunk.next;
  1098. this$1.byEnd[ chunk.next.end ] = chunk.next;
  1099. }
  1100. if ( aborted ) { return this$1; }
  1101. chunk = chunk.next;
  1102. } while ( chunk );
  1103. return this;
  1104. }
  1105. };
  1106. var hasOwnProp = Object.prototype.hasOwnProperty;
  1107. function Bundle$1 ( options ) {
  1108. if ( options === void 0 ) options = {};
  1109. this.intro = options.intro || '';
  1110. this.separator = options.separator !== undefined ? options.separator : '\n';
  1111. this.sources = [];
  1112. this.uniqueSources = [];
  1113. this.uniqueSourceIndexByFilename = {};
  1114. }
  1115. Bundle$1.prototype = {
  1116. addSource: function addSource ( source ) {
  1117. if ( source instanceof MagicString$1 ) {
  1118. return this.addSource({
  1119. content: source,
  1120. filename: source.filename,
  1121. separator: this.separator
  1122. });
  1123. }
  1124. if ( !isObject( source ) || !source.content ) {
  1125. throw new Error( 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`' );
  1126. }
  1127. [ 'filename', 'indentExclusionRanges', 'separator' ].forEach( function (option) {
  1128. if ( !hasOwnProp.call( source, option ) ) { source[ option ] = source.content[ option ]; }
  1129. });
  1130. if ( source.separator === undefined ) { // TODO there's a bunch of this sort of thing, needs cleaning up
  1131. source.separator = this.separator;
  1132. }
  1133. if ( source.filename ) {
  1134. if ( !hasOwnProp.call( this.uniqueSourceIndexByFilename, source.filename ) ) {
  1135. this.uniqueSourceIndexByFilename[ source.filename ] = this.uniqueSources.length;
  1136. this.uniqueSources.push({ filename: source.filename, content: source.content.original });
  1137. } else {
  1138. var uniqueSource = this.uniqueSources[ this.uniqueSourceIndexByFilename[ source.filename ] ];
  1139. if ( source.content.original !== uniqueSource.content ) {
  1140. throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
  1141. }
  1142. }
  1143. }
  1144. this.sources.push( source );
  1145. return this;
  1146. },
  1147. append: function append ( str, options ) {
  1148. this.addSource({
  1149. content: new MagicString$1( str ),
  1150. separator: ( options && options.separator ) || ''
  1151. });
  1152. return this;
  1153. },
  1154. clone: function clone () {
  1155. var bundle = new Bundle$1({
  1156. intro: this.intro,
  1157. separator: this.separator
  1158. });
  1159. this.sources.forEach( function (source) {
  1160. bundle.addSource({
  1161. filename: source.filename,
  1162. content: source.content.clone(),
  1163. separator: source.separator
  1164. });
  1165. });
  1166. return bundle;
  1167. },
  1168. generateMap: function generateMap ( options ) {
  1169. var this$1 = this;
  1170. if ( options === void 0 ) options = {};
  1171. var names = [];
  1172. this.sources.forEach( function (source) {
  1173. Object.keys( source.content.storedNames ).forEach( function (name) {
  1174. if ( !~names.indexOf( name ) ) { names.push( name ); }
  1175. });
  1176. });
  1177. var mappings = new Mappings( options.hires );
  1178. if ( this.intro ) {
  1179. mappings.advance( this.intro );
  1180. }
  1181. this.sources.forEach( function ( source, i ) {
  1182. if ( i > 0 ) {
  1183. mappings.advance( this$1.separator );
  1184. }
  1185. var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[ source.filename ] : -1;
  1186. var magicString = source.content;
  1187. var locate = getLocator( magicString.original );
  1188. if ( magicString.intro ) {
  1189. mappings.advance( magicString.intro );
  1190. }
  1191. magicString.firstChunk.eachNext( function (chunk) {
  1192. var loc = locate( chunk.start );
  1193. if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
  1194. if ( source.filename ) {
  1195. if ( chunk.edited ) {
  1196. mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
  1197. } else {
  1198. mappings.addUneditedChunk( sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations );
  1199. }
  1200. }
  1201. else {
  1202. mappings.advance( chunk.content );
  1203. }
  1204. if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
  1205. });
  1206. if ( magicString.outro ) {
  1207. mappings.advance( magicString.outro );
  1208. }
  1209. });
  1210. return new SourceMap({
  1211. file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
  1212. sources: this.uniqueSources.map( function (source) {
  1213. return options.file ? getRelativePath( options.file, source.filename ) : source.filename;
  1214. }),
  1215. sourcesContent: this.uniqueSources.map( function (source) {
  1216. return options.includeContent ? source.content : null;
  1217. }),
  1218. names: names,
  1219. mappings: mappings.encode()
  1220. });
  1221. },
  1222. getIndentString: function getIndentString () {
  1223. var indentStringCounts = {};
  1224. this.sources.forEach( function (source) {
  1225. var indentStr = source.content.indentStr;
  1226. if ( indentStr === null ) { return; }
  1227. if ( !indentStringCounts[ indentStr ] ) { indentStringCounts[ indentStr ] = 0; }
  1228. indentStringCounts[ indentStr ] += 1;
  1229. });
  1230. return ( Object.keys( indentStringCounts ).sort( function ( a, b ) {
  1231. return indentStringCounts[a] - indentStringCounts[b];
  1232. })[0] ) || '\t';
  1233. },
  1234. indent: function indent ( indentStr ) {
  1235. var this$1 = this;
  1236. if ( !arguments.length ) {
  1237. indentStr = this.getIndentString();
  1238. }
  1239. if ( indentStr === '' ) { return this; } // noop
  1240. var trailingNewline = !this.intro || this.intro.slice( -1 ) === '\n';
  1241. this.sources.forEach( function ( source, i ) {
  1242. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  1243. var indentStart = trailingNewline || ( i > 0 && /\r?\n$/.test( separator ) );
  1244. source.content.indent( indentStr, {
  1245. exclude: source.indentExclusionRanges,
  1246. indentStart: indentStart//: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
  1247. });
  1248. // TODO this is a very slow way to determine this
  1249. trailingNewline = source.content.toString().slice( 0, -1 ) === '\n';
  1250. });
  1251. if ( this.intro ) {
  1252. this.intro = indentStr + this.intro.replace( /^[^\n]/gm, function ( match, index ) {
  1253. return index > 0 ? indentStr + match : match;
  1254. });
  1255. }
  1256. return this;
  1257. },
  1258. prepend: function prepend ( str ) {
  1259. this.intro = str + this.intro;
  1260. return this;
  1261. },
  1262. toString: function toString () {
  1263. var this$1 = this;
  1264. var body = this.sources.map( function ( source, i ) {
  1265. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  1266. var str = ( i > 0 ? separator : '' ) + source.content.toString();
  1267. return str;
  1268. }).join( '' );
  1269. return this.intro + body;
  1270. },
  1271. trimLines: function trimLines () {
  1272. return this.trim('[\\r\\n]');
  1273. },
  1274. trim: function trim ( charType ) {
  1275. return this.trimStart( charType ).trimEnd( charType );
  1276. },
  1277. trimStart: function trimStart ( charType ) {
  1278. var this$1 = this;
  1279. var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
  1280. this.intro = this.intro.replace( rx, '' );
  1281. if ( !this.intro ) {
  1282. var source;
  1283. var i = 0;
  1284. do {
  1285. source = this$1.sources[i];
  1286. if ( !source ) {
  1287. break;
  1288. }
  1289. source.content.trimStart( charType );
  1290. i += 1;
  1291. } while ( source.content.toString() === '' ); // TODO faster way to determine non-empty source?
  1292. }
  1293. return this;
  1294. },
  1295. trimEnd: function trimEnd ( charType ) {
  1296. var this$1 = this;
  1297. var rx = new RegExp( ( charType || '\\s' ) + '+$' );
  1298. var source;
  1299. var i = this.sources.length - 1;
  1300. do {
  1301. source = this$1.sources[i];
  1302. if ( !source ) {
  1303. this$1.intro = this$1.intro.replace( rx, '' );
  1304. break;
  1305. }
  1306. source.content.trimEnd( charType );
  1307. i -= 1;
  1308. } while ( source.content.toString() === '' ); // TODO faster way to determine non-empty source?
  1309. return this;
  1310. }
  1311. };
  1312. // Return the first non-falsy result from an array of
  1313. // maybe-sync, maybe-promise-returning functions
  1314. function first ( candidates ) {
  1315. return function () {
  1316. var args = [], len = arguments.length;
  1317. while ( len-- ) args[ len ] = arguments[ len ];
  1318. return candidates.reduce( ( promise, candidate ) => {
  1319. return promise.then( result => result != null ?
  1320. result :
  1321. Promise.resolve( candidate.apply( void 0, args ) ) );
  1322. }, Promise.resolve() );
  1323. };
  1324. }
  1325. function find ( array, fn ) {
  1326. for ( let i = 0; i < array.length; i += 1 ) {
  1327. if ( fn( array[i], i ) ) { return array[i]; }
  1328. }
  1329. return null;
  1330. }
  1331. // Reserved word lists for various dialects of the language
  1332. var reservedWords = {
  1333. 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
  1334. 5: "class enum extends super const export import",
  1335. 6: "enum",
  1336. strict: "implements interface let package private protected public static yield",
  1337. strictBind: "eval arguments"
  1338. };
  1339. // And the keywords
  1340. var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
  1341. var keywords = {
  1342. 5: ecma5AndLessKeywords,
  1343. 6: ecma5AndLessKeywords + " const class extends export import super"
  1344. };
  1345. // ## Character categories
  1346. // Big ugly regular expressions that match characters in the
  1347. // whitespace, identifier, and identifier-start categories. These
  1348. // are only applied when a character is found to actually have a
  1349. // code point above 128.
  1350. // Generated by `bin/generate-identifier-regex.js`.
  1351. var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ae\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  1352. var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d01-\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf8\u1cf9\u1dc0-\u1df5\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  1353. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1354. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1355. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1356. // These are a run-length and offset encoded representation of the
  1357. // >0xffff code points that are a valid part of identifiers. The
  1358. // offset starts at 0x10000, and each pair of numbers represents an
  1359. // offset to the next range, and then a size of the range. They were
  1360. // generated by bin/generate-identifier-regex.js
  1361. // eslint-disable-next-line comma-spacing
  1362. var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,0,32,6124,20,754,9486,1,3071,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,10591,541];
  1363. // eslint-disable-next-line comma-spacing
  1364. var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,838,7,2,7,17,9,57,21,2,13,19882,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239];
  1365. // This has a complexity linear to the value of the code. The
  1366. // assumption is that looking up astral identifier characters is
  1367. // rare.
  1368. function isInAstralSet(code, set) {
  1369. var pos = 0x10000;
  1370. for (var i = 0; i < set.length; i += 2) {
  1371. pos += set[i];
  1372. if (pos > code) { return false }
  1373. pos += set[i + 1];
  1374. if (pos >= code) { return true }
  1375. }
  1376. }
  1377. // Test whether a given character code starts an identifier.
  1378. function isIdentifierStart(code, astral) {
  1379. if (code < 65) { return code === 36 }
  1380. if (code < 91) { return true }
  1381. if (code < 97) { return code === 95 }
  1382. if (code < 123) { return true }
  1383. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  1384. if (astral === false) { return false }
  1385. return isInAstralSet(code, astralIdentifierStartCodes)
  1386. }
  1387. // Test whether a given character is part of an identifier.
  1388. function isIdentifierChar(code, astral) {
  1389. if (code < 48) { return code === 36 }
  1390. if (code < 58) { return true }
  1391. if (code < 65) { return false }
  1392. if (code < 91) { return true }
  1393. if (code < 97) { return code === 95 }
  1394. if (code < 123) { return true }
  1395. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  1396. if (astral === false) { return false }
  1397. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  1398. }
  1399. // ## Token types
  1400. // The assignment of fine-grained, information-carrying type objects
  1401. // allows the tokenizer to store the information it has about a
  1402. // token in a way that is very cheap for the parser to look up.
  1403. // All token type variables start with an underscore, to make them
  1404. // easy to recognize.
  1405. // The `beforeExpr` property is used to disambiguate between regular
  1406. // expressions and divisions. It is set on all token types that can
  1407. // be followed by an expression (thus, a slash after them would be a
  1408. // regular expression).
  1409. //
  1410. // The `startsExpr` property is used to check if the token ends a
  1411. // `yield` expression. It is set on all token types that either can
  1412. // directly start an expression (like a quotation mark) or can
  1413. // continue an expression (like the body of a string).
  1414. //
  1415. // `isLoop` marks a keyword as starting a loop, which is important
  1416. // to know when parsing a label, in order to allow or disallow
  1417. // continue jumps to that label.
  1418. var TokenType = function TokenType(label, conf) {
  1419. if ( conf === void 0 ) { conf = {}; }
  1420. this.label = label;
  1421. this.keyword = conf.keyword;
  1422. this.beforeExpr = !!conf.beforeExpr;
  1423. this.startsExpr = !!conf.startsExpr;
  1424. this.isLoop = !!conf.isLoop;
  1425. this.isAssign = !!conf.isAssign;
  1426. this.prefix = !!conf.prefix;
  1427. this.postfix = !!conf.postfix;
  1428. this.binop = conf.binop || null;
  1429. this.updateContext = null;
  1430. };
  1431. function binop(name, prec) {
  1432. return new TokenType(name, {beforeExpr: true, binop: prec})
  1433. }
  1434. var beforeExpr = {beforeExpr: true};
  1435. var startsExpr = {startsExpr: true};
  1436. // Map keyword names to token types.
  1437. var keywords$1 = {};
  1438. // Succinct definitions of keyword token types
  1439. function kw(name, options) {
  1440. if ( options === void 0 ) { options = {}; }
  1441. options.keyword = name;
  1442. return keywords$1[name] = new TokenType(name, options)
  1443. }
  1444. var types = {
  1445. num: new TokenType("num", startsExpr),
  1446. regexp: new TokenType("regexp", startsExpr),
  1447. string: new TokenType("string", startsExpr),
  1448. name: new TokenType("name", startsExpr),
  1449. eof: new TokenType("eof"),
  1450. // Punctuation token types.
  1451. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  1452. bracketR: new TokenType("]"),
  1453. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  1454. braceR: new TokenType("}"),
  1455. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  1456. parenR: new TokenType(")"),
  1457. comma: new TokenType(",", beforeExpr),
  1458. semi: new TokenType(";", beforeExpr),
  1459. colon: new TokenType(":", beforeExpr),
  1460. dot: new TokenType("."),
  1461. question: new TokenType("?", beforeExpr),
  1462. arrow: new TokenType("=>", beforeExpr),
  1463. template: new TokenType("template"),
  1464. invalidTemplate: new TokenType("invalidTemplate"),
  1465. ellipsis: new TokenType("...", beforeExpr),
  1466. backQuote: new TokenType("`", startsExpr),
  1467. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  1468. // Operators. These carry several kinds of properties to help the
  1469. // parser use them properly (the presence of these properties is
  1470. // what categorizes them as operators).
  1471. //
  1472. // `binop`, when present, specifies that this operator is a binary
  1473. // operator, and will refer to its precedence.
  1474. //
  1475. // `prefix` and `postfix` mark the operator as a prefix or postfix
  1476. // unary operator.
  1477. //
  1478. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  1479. // binary operators with a very low precedence, that should result
  1480. // in AssignmentExpression nodes.
  1481. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  1482. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  1483. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  1484. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  1485. logicalOR: binop("||", 1),
  1486. logicalAND: binop("&&", 2),
  1487. bitwiseOR: binop("|", 3),
  1488. bitwiseXOR: binop("^", 4),
  1489. bitwiseAND: binop("&", 5),
  1490. equality: binop("==/!=/===/!==", 6),
  1491. relational: binop("</>/<=/>=", 7),
  1492. bitShift: binop("<</>>/>>>", 8),
  1493. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  1494. modulo: binop("%", 10),
  1495. star: binop("*", 10),
  1496. slash: binop("/", 10),
  1497. starstar: new TokenType("**", {beforeExpr: true}),
  1498. // Keyword token types.
  1499. _break: kw("break"),
  1500. _case: kw("case", beforeExpr),
  1501. _catch: kw("catch"),
  1502. _continue: kw("continue"),
  1503. _debugger: kw("debugger"),
  1504. _default: kw("default", beforeExpr),
  1505. _do: kw("do", {isLoop: true, beforeExpr: true}),
  1506. _else: kw("else", beforeExpr),
  1507. _finally: kw("finally"),
  1508. _for: kw("for", {isLoop: true}),
  1509. _function: kw("function", startsExpr),
  1510. _if: kw("if"),
  1511. _return: kw("return", beforeExpr),
  1512. _switch: kw("switch"),
  1513. _throw: kw("throw", beforeExpr),
  1514. _try: kw("try"),
  1515. _var: kw("var"),
  1516. _const: kw("const"),
  1517. _while: kw("while", {isLoop: true}),
  1518. _with: kw("with"),
  1519. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  1520. _this: kw("this", startsExpr),
  1521. _super: kw("super", startsExpr),
  1522. _class: kw("class", startsExpr),
  1523. _extends: kw("extends", beforeExpr),
  1524. _export: kw("export"),
  1525. _import: kw("import"),
  1526. _null: kw("null", startsExpr),
  1527. _true: kw("true", startsExpr),
  1528. _false: kw("false", startsExpr),
  1529. _in: kw("in", {beforeExpr: true, binop: 7}),
  1530. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  1531. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  1532. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  1533. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  1534. };
  1535. // Matches a whole line break (where CRLF is considered a single
  1536. // line break). Used to count lines.
  1537. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  1538. var lineBreakG = new RegExp(lineBreak.source, "g");
  1539. function isNewLine(code) {
  1540. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  1541. }
  1542. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  1543. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1544. var ref = Object.prototype;
  1545. var hasOwnProperty = ref.hasOwnProperty;
  1546. var toString = ref.toString;
  1547. // Checks if an object has a property.
  1548. function has(obj, propName) {
  1549. return hasOwnProperty.call(obj, propName)
  1550. }
  1551. var isArray = Array.isArray || (function (obj) { return (
  1552. toString.call(obj) === "[object Array]"
  1553. ); });
  1554. // These are used when `options.locations` is on, for the
  1555. // `startLoc` and `endLoc` properties.
  1556. var Position = function Position(line, col) {
  1557. this.line = line;
  1558. this.column = col;
  1559. };
  1560. Position.prototype.offset = function offset (n) {
  1561. return new Position(this.line, this.column + n)
  1562. };
  1563. var SourceLocation = function SourceLocation(p, start, end) {
  1564. this.start = start;
  1565. this.end = end;
  1566. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  1567. };
  1568. // The `getLineInfo` function is mostly useful when the
  1569. // `locations` option is off (for performance reasons) and you
  1570. // want to find the line/column position for a given character
  1571. // offset. `input` should be the code string that the offset refers
  1572. // into.
  1573. function getLineInfo(input, offset) {
  1574. for (var line = 1, cur = 0;;) {
  1575. lineBreakG.lastIndex = cur;
  1576. var match = lineBreakG.exec(input);
  1577. if (match && match.index < offset) {
  1578. ++line;
  1579. cur = match.index + match[0].length;
  1580. } else {
  1581. return new Position(line, offset - cur)
  1582. }
  1583. }
  1584. }
  1585. // A second optional argument can be given to further configure
  1586. // the parser process. These options are recognized:
  1587. var defaultOptions = {
  1588. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  1589. // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
  1590. // for strict mode, the set of reserved words, and support for
  1591. // new syntax features. The default is 7.
  1592. ecmaVersion: 7,
  1593. // `sourceType` indicates the mode the code should be parsed in.
  1594. // Can be either `"script"` or `"module"`. This influences global
  1595. // strict mode and parsing of `import` and `export` declarations.
  1596. sourceType: "script",
  1597. // `onInsertedSemicolon` can be a callback that will be called
  1598. // when a semicolon is automatically inserted. It will be passed
  1599. // th position of the comma as an offset, and if `locations` is
  1600. // enabled, it is given the location as a `{line, column}` object
  1601. // as second argument.
  1602. onInsertedSemicolon: null,
  1603. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  1604. // trailing commas.
  1605. onTrailingComma: null,
  1606. // By default, reserved words are only enforced if ecmaVersion >= 5.
  1607. // Set `allowReserved` to a boolean value to explicitly turn this on
  1608. // an off. When this option has the value "never", reserved words
  1609. // and keywords can also not be used as property names.
  1610. allowReserved: null,
  1611. // When enabled, a return at the top level is not considered an
  1612. // error.
  1613. allowReturnOutsideFunction: false,
  1614. // When enabled, import/export statements are not constrained to
  1615. // appearing at the top of the program.
  1616. allowImportExportEverywhere: false,
  1617. // When enabled, hashbang directive in the beginning of file
  1618. // is allowed and treated as a line comment.
  1619. allowHashBang: false,
  1620. // When `locations` is on, `loc` properties holding objects with
  1621. // `start` and `end` properties in `{line, column}` form (with
  1622. // line being 1-based and column 0-based) will be attached to the
  1623. // nodes.
  1624. locations: false,
  1625. // A function can be passed as `onToken` option, which will
  1626. // cause Acorn to call that function with object in the same
  1627. // format as tokens returned from `tokenizer().getToken()`. Note
  1628. // that you are not allowed to call the parser from the
  1629. // callback—that will corrupt its internal state.
  1630. onToken: null,
  1631. // A function can be passed as `onComment` option, which will
  1632. // cause Acorn to call that function with `(block, text, start,
  1633. // end)` parameters whenever a comment is skipped. `block` is a
  1634. // boolean indicating whether this is a block (`/* */`) comment,
  1635. // `text` is the content of the comment, and `start` and `end` are
  1636. // character offsets that denote the start and end of the comment.
  1637. // When the `locations` option is on, two more parameters are
  1638. // passed, the full `{line, column}` locations of the start and
  1639. // end of the comments. Note that you are not allowed to call the
  1640. // parser from the callback—that will corrupt its internal state.
  1641. onComment: null,
  1642. // Nodes have their start and end characters offsets recorded in
  1643. // `start` and `end` properties (directly on the node, rather than
  1644. // the `loc` object, which holds line/column data. To also add a
  1645. // [semi-standardized][range] `range` property holding a `[start,
  1646. // end]` array with the same numbers, set the `ranges` option to
  1647. // `true`.
  1648. //
  1649. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  1650. ranges: false,
  1651. // It is possible to parse multiple files into a single AST by
  1652. // passing the tree produced by parsing the first file as
  1653. // `program` option in subsequent parses. This will add the
  1654. // toplevel forms of the parsed file to the `Program` (top) node
  1655. // of an existing parse tree.
  1656. program: null,
  1657. // When `locations` is on, you can pass this to record the source
  1658. // file in every node's `loc` object.
  1659. sourceFile: null,
  1660. // This value, if given, is stored in every node, whether
  1661. // `locations` is on or off.
  1662. directSourceFile: null,
  1663. // When enabled, parenthesized expressions are represented by
  1664. // (non-standard) ParenthesizedExpression nodes
  1665. preserveParens: false,
  1666. plugins: {}
  1667. };
  1668. // Interpret and default an options object
  1669. function getOptions(opts) {
  1670. var options = {};
  1671. for (var opt in defaultOptions)
  1672. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  1673. if (options.ecmaVersion >= 2015)
  1674. { options.ecmaVersion -= 2009; }
  1675. if (options.allowReserved == null)
  1676. { options.allowReserved = options.ecmaVersion < 5; }
  1677. if (isArray(options.onToken)) {
  1678. var tokens = options.onToken;
  1679. options.onToken = function (token) { return tokens.push(token); };
  1680. }
  1681. if (isArray(options.onComment))
  1682. { options.onComment = pushComment(options, options.onComment); }
  1683. return options
  1684. }
  1685. function pushComment(options, array) {
  1686. return function(block, text, start, end, startLoc, endLoc) {
  1687. var comment = {
  1688. type: block ? "Block" : "Line",
  1689. value: text,
  1690. start: start,
  1691. end: end
  1692. };
  1693. if (options.locations)
  1694. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  1695. if (options.ranges)
  1696. { comment.range = [start, end]; }
  1697. array.push(comment);
  1698. }
  1699. }
  1700. // Registered plugins
  1701. var plugins = {};
  1702. function keywordRegexp(words) {
  1703. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  1704. }
  1705. var Parser = function Parser(options, input, startPos) {
  1706. this.options = options = getOptions(options);
  1707. this.sourceFile = options.sourceFile;
  1708. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  1709. var reserved = "";
  1710. if (!options.allowReserved) {
  1711. for (var v = options.ecmaVersion;; v--)
  1712. { if (reserved = reservedWords[v]) { break } }
  1713. if (options.sourceType == "module") { reserved += " await"; }
  1714. }
  1715. this.reservedWords = keywordRegexp(reserved);
  1716. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  1717. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  1718. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  1719. this.input = String(input);
  1720. // Used to signal to callers of `readWord1` whether the word
  1721. // contained any escape sequences. This is needed because words with
  1722. // escape sequences must not be interpreted as keywords.
  1723. this.containsEsc = false;
  1724. // Load plugins
  1725. this.loadPlugins(options.plugins);
  1726. // Set up token state
  1727. // The current position of the tokenizer in the input.
  1728. if (startPos) {
  1729. this.pos = startPos;
  1730. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  1731. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  1732. } else {
  1733. this.pos = this.lineStart = 0;
  1734. this.curLine = 1;
  1735. }
  1736. // Properties of the current token:
  1737. // Its type
  1738. this.type = types.eof;
  1739. // For tokens that include more information than their type, the value
  1740. this.value = null;
  1741. // Its start and end offset
  1742. this.start = this.end = this.pos;
  1743. // And, if locations are used, the {line, column} object
  1744. // corresponding to those offsets
  1745. this.startLoc = this.endLoc = this.curPosition();
  1746. // Position information for the previous token
  1747. this.lastTokEndLoc = this.lastTokStartLoc = null;
  1748. this.lastTokStart = this.lastTokEnd = this.pos;
  1749. // The context stack is used to superficially track syntactic
  1750. // context to predict whether a regular expression is allowed in a
  1751. // given position.
  1752. this.context = this.initialContext();
  1753. this.exprAllowed = true;
  1754. // Figure out if it's a module code.
  1755. this.inModule = options.sourceType === "module";
  1756. this.strict = this.inModule || this.strictDirective(this.pos);
  1757. // Used to signify the start of a potential arrow function
  1758. this.potentialArrowAt = -1;
  1759. // Flags to track whether we are in a function, a generator, an async function.
  1760. this.inFunction = this.inGenerator = this.inAsync = false;
  1761. // Positions to delayed-check that yield/await does not exist in default parameters.
  1762. this.yieldPos = this.awaitPos = 0;
  1763. // Labels in scope.
  1764. this.labels = [];
  1765. // If enabled, skip leading hashbang line.
  1766. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  1767. { this.skipLineComment(2); }
  1768. // Scope tracking for duplicate variable names (see scope.js)
  1769. this.scopeStack = [];
  1770. this.enterFunctionScope();
  1771. };
  1772. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  1773. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  1774. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  1775. Parser.prototype.extend = function extend (name, f) {
  1776. this[name] = f(this[name]);
  1777. };
  1778. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  1779. var this$1 = this;
  1780. for (var name in pluginConfigs) {
  1781. var plugin = plugins[name];
  1782. if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
  1783. plugin(this$1, pluginConfigs[name]);
  1784. }
  1785. };
  1786. Parser.prototype.parse = function parse () {
  1787. var node = this.options.program || this.startNode();
  1788. this.nextToken();
  1789. return this.parseTopLevel(node)
  1790. };
  1791. var pp = Parser.prototype;
  1792. // ## Parser utilities
  1793. var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
  1794. pp.strictDirective = function(start) {
  1795. var this$1 = this;
  1796. for (;;) {
  1797. skipWhiteSpace.lastIndex = start;
  1798. start += skipWhiteSpace.exec(this$1.input)[0].length;
  1799. var match = literal.exec(this$1.input.slice(start));
  1800. if (!match) { return false }
  1801. if ((match[1] || match[2]) == "use strict") { return true }
  1802. start += match[0].length;
  1803. }
  1804. };
  1805. // Predicate that tests whether the next token is of the given
  1806. // type, and if yes, consumes it as a side effect.
  1807. pp.eat = function(type) {
  1808. if (this.type === type) {
  1809. this.next();
  1810. return true
  1811. } else {
  1812. return false
  1813. }
  1814. };
  1815. // Tests whether parsed token is a contextual keyword.
  1816. pp.isContextual = function(name) {
  1817. return this.type === types.name && this.value === name
  1818. };
  1819. // Consumes contextual keyword if possible.
  1820. pp.eatContextual = function(name) {
  1821. return this.value === name && this.eat(types.name)
  1822. };
  1823. // Asserts that following token is given contextual keyword.
  1824. pp.expectContextual = function(name) {
  1825. if (!this.eatContextual(name)) { this.unexpected(); }
  1826. };
  1827. // Test whether a semicolon can be inserted at the current position.
  1828. pp.canInsertSemicolon = function() {
  1829. return this.type === types.eof ||
  1830. this.type === types.braceR ||
  1831. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  1832. };
  1833. pp.insertSemicolon = function() {
  1834. if (this.canInsertSemicolon()) {
  1835. if (this.options.onInsertedSemicolon)
  1836. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  1837. return true
  1838. }
  1839. };
  1840. // Consume a semicolon, or, failing that, see if we are allowed to
  1841. // pretend that there is a semicolon at this position.
  1842. pp.semicolon = function() {
  1843. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  1844. };
  1845. pp.afterTrailingComma = function(tokType, notNext) {
  1846. if (this.type == tokType) {
  1847. if (this.options.onTrailingComma)
  1848. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  1849. if (!notNext)
  1850. { this.next(); }
  1851. return true
  1852. }
  1853. };
  1854. // Expect a token of a given type. If found, consume it, otherwise,
  1855. // raise an unexpected token error.
  1856. pp.expect = function(type) {
  1857. this.eat(type) || this.unexpected();
  1858. };
  1859. // Raise an unexpected token error.
  1860. pp.unexpected = function(pos) {
  1861. this.raise(pos != null ? pos : this.start, "Unexpected token");
  1862. };
  1863. function DestructuringErrors() {
  1864. this.shorthandAssign =
  1865. this.trailingComma =
  1866. this.parenthesizedAssign =
  1867. this.parenthesizedBind =
  1868. -1;
  1869. }
  1870. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  1871. if (!refDestructuringErrors) { return }
  1872. if (refDestructuringErrors.trailingComma > -1)
  1873. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  1874. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  1875. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  1876. };
  1877. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  1878. var pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1;
  1879. if (!andThrow) { return pos >= 0 }
  1880. if (pos > -1) { this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); }
  1881. };
  1882. pp.checkYieldAwaitInDefaultParams = function() {
  1883. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  1884. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  1885. if (this.awaitPos)
  1886. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  1887. };
  1888. pp.isSimpleAssignTarget = function(expr) {
  1889. if (expr.type === "ParenthesizedExpression")
  1890. { return this.isSimpleAssignTarget(expr.expression) }
  1891. return expr.type === "Identifier" || expr.type === "MemberExpression"
  1892. };
  1893. var pp$1 = Parser.prototype;
  1894. // ### Statement parsing
  1895. // Parse a program. Initializes the parser, reads any number of
  1896. // statements, and wraps them in a Program node. Optionally takes a
  1897. // `program` argument. If present, the statements will be appended
  1898. // to its body instead of creating a new node.
  1899. pp$1.parseTopLevel = function(node) {
  1900. var this$1 = this;
  1901. var exports = {};
  1902. if (!node.body) { node.body = []; }
  1903. while (this.type !== types.eof) {
  1904. var stmt = this$1.parseStatement(true, true, exports);
  1905. node.body.push(stmt);
  1906. }
  1907. this.next();
  1908. if (this.options.ecmaVersion >= 6) {
  1909. node.sourceType = this.options.sourceType;
  1910. }
  1911. return this.finishNode(node, "Program")
  1912. };
  1913. var loopLabel = {kind: "loop"};
  1914. var switchLabel = {kind: "switch"};
  1915. pp$1.isLet = function() {
  1916. if (this.type !== types.name || this.options.ecmaVersion < 6 || this.value != "let") { return false }
  1917. skipWhiteSpace.lastIndex = this.pos;
  1918. var skip = skipWhiteSpace.exec(this.input);
  1919. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  1920. if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
  1921. if (isIdentifierStart(nextCh, true)) {
  1922. var pos = next + 1;
  1923. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  1924. var ident = this.input.slice(next, pos);
  1925. if (!this.isKeyword(ident)) { return true }
  1926. }
  1927. return false
  1928. };
  1929. // check 'async [no LineTerminator here] function'
  1930. // - 'async /*foo*/ function' is OK.
  1931. // - 'async /*\n*/ function' is invalid.
  1932. pp$1.isAsyncFunction = function() {
  1933. if (this.type !== types.name || this.options.ecmaVersion < 8 || this.value != "async")
  1934. { return false }
  1935. skipWhiteSpace.lastIndex = this.pos;
  1936. var skip = skipWhiteSpace.exec(this.input);
  1937. var next = this.pos + skip[0].length;
  1938. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  1939. this.input.slice(next, next + 8) === "function" &&
  1940. (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  1941. };
  1942. // Parse a single statement.
  1943. //
  1944. // If expecting a statement and finding a slash operator, parse a
  1945. // regular expression literal. This is to handle cases like
  1946. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  1947. // does not help.
  1948. pp$1.parseStatement = function(declaration, topLevel, exports) {
  1949. var starttype = this.type, node = this.startNode(), kind;
  1950. if (this.isLet()) {
  1951. starttype = types._var;
  1952. kind = "let";
  1953. }
  1954. // Most types of statements are recognized by the keyword they
  1955. // start with. Many are trivial to parse, some require a bit of
  1956. // complexity.
  1957. switch (starttype) {
  1958. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  1959. case types._debugger: return this.parseDebuggerStatement(node)
  1960. case types._do: return this.parseDoStatement(node)
  1961. case types._for: return this.parseForStatement(node)
  1962. case types._function:
  1963. if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
  1964. return this.parseFunctionStatement(node, false)
  1965. case types._class:
  1966. if (!declaration) { this.unexpected(); }
  1967. return this.parseClass(node, true)
  1968. case types._if: return this.parseIfStatement(node)
  1969. case types._return: return this.parseReturnStatement(node)
  1970. case types._switch: return this.parseSwitchStatement(node)
  1971. case types._throw: return this.parseThrowStatement(node)
  1972. case types._try: return this.parseTryStatement(node)
  1973. case types._const: case types._var:
  1974. kind = kind || this.value;
  1975. if (!declaration && kind != "var") { this.unexpected(); }
  1976. return this.parseVarStatement(node, kind)
  1977. case types._while: return this.parseWhileStatement(node)
  1978. case types._with: return this.parseWithStatement(node)
  1979. case types.braceL: return this.parseBlock()
  1980. case types.semi: return this.parseEmptyStatement(node)
  1981. case types._export:
  1982. case types._import:
  1983. if (!this.options.allowImportExportEverywhere) {
  1984. if (!topLevel)
  1985. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  1986. if (!this.inModule)
  1987. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  1988. }
  1989. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  1990. // If the statement does not start with a statement keyword or a
  1991. // brace, it's an ExpressionStatement or LabeledStatement. We
  1992. // simply start parsing an expression, and afterwards, if the
  1993. // next token is a colon and the expression was a simple
  1994. // Identifier node, we switch to interpreting it as a label.
  1995. default:
  1996. if (this.isAsyncFunction() && declaration) {
  1997. this.next();
  1998. return this.parseFunctionStatement(node, true)
  1999. }
  2000. var maybeName = this.value, expr = this.parseExpression();
  2001. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  2002. { return this.parseLabeledStatement(node, maybeName, expr) }
  2003. else { return this.parseExpressionStatement(node, expr) }
  2004. }
  2005. };
  2006. pp$1.parseBreakContinueStatement = function(node, keyword) {
  2007. var this$1 = this;
  2008. var isBreak = keyword == "break";
  2009. this.next();
  2010. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  2011. else if (this.type !== types.name) { this.unexpected(); }
  2012. else {
  2013. node.label = this.parseIdent();
  2014. this.semicolon();
  2015. }
  2016. // Verify that there is an actual destination to break or
  2017. // continue to.
  2018. var i = 0;
  2019. for (; i < this.labels.length; ++i) {
  2020. var lab = this$1.labels[i];
  2021. if (node.label == null || lab.name === node.label.name) {
  2022. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  2023. if (node.label && isBreak) { break }
  2024. }
  2025. }
  2026. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  2027. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  2028. };
  2029. pp$1.parseDebuggerStatement = function(node) {
  2030. this.next();
  2031. this.semicolon();
  2032. return this.finishNode(node, "DebuggerStatement")
  2033. };
  2034. pp$1.parseDoStatement = function(node) {
  2035. this.next();
  2036. this.labels.push(loopLabel);
  2037. node.body = this.parseStatement(false);
  2038. this.labels.pop();
  2039. this.expect(types._while);
  2040. node.test = this.parseParenExpression();
  2041. if (this.options.ecmaVersion >= 6)
  2042. { this.eat(types.semi); }
  2043. else
  2044. { this.semicolon(); }
  2045. return this.finishNode(node, "DoWhileStatement")
  2046. };
  2047. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  2048. // loop is non-trivial. Basically, we have to parse the init `var`
  2049. // statement or expression, disallowing the `in` operator (see
  2050. // the second parameter to `parseExpression`), and then check
  2051. // whether the next token is `in` or `of`. When there is no init
  2052. // part (semicolon immediately after the opening parenthesis), it
  2053. // is a regular `for` loop.
  2054. pp$1.parseForStatement = function(node) {
  2055. this.next();
  2056. this.labels.push(loopLabel);
  2057. this.enterLexicalScope();
  2058. this.expect(types.parenL);
  2059. if (this.type === types.semi) { return this.parseFor(node, null) }
  2060. var isLet = this.isLet();
  2061. if (this.type === types._var || this.type === types._const || isLet) {
  2062. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  2063. this.next();
  2064. this.parseVar(init$1, true, kind);
  2065. this.finishNode(init$1, "VariableDeclaration");
  2066. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  2067. !(kind !== "var" && init$1.declarations[0].init))
  2068. { return this.parseForIn(node, init$1) }
  2069. return this.parseFor(node, init$1)
  2070. }
  2071. var refDestructuringErrors = new DestructuringErrors;
  2072. var init = this.parseExpression(true, refDestructuringErrors);
  2073. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  2074. this.toAssignable(init);
  2075. this.checkLVal(init);
  2076. this.checkPatternErrors(refDestructuringErrors, true);
  2077. return this.parseForIn(node, init)
  2078. } else {
  2079. this.checkExpressionErrors(refDestructuringErrors, true);
  2080. }
  2081. return this.parseFor(node, init)
  2082. };
  2083. pp$1.parseFunctionStatement = function(node, isAsync) {
  2084. this.next();
  2085. return this.parseFunction(node, true, false, isAsync)
  2086. };
  2087. pp$1.isFunction = function() {
  2088. return this.type === types._function || this.isAsyncFunction()
  2089. };
  2090. pp$1.parseIfStatement = function(node) {
  2091. this.next();
  2092. node.test = this.parseParenExpression();
  2093. // allow function declarations in branches, but only in non-strict mode
  2094. node.consequent = this.parseStatement(!this.strict && this.isFunction());
  2095. node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.isFunction()) : null;
  2096. return this.finishNode(node, "IfStatement")
  2097. };
  2098. pp$1.parseReturnStatement = function(node) {
  2099. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  2100. { this.raise(this.start, "'return' outside of function"); }
  2101. this.next();
  2102. // In `return` (and `break`/`continue`), the keywords with
  2103. // optional arguments, we eagerly look for a semicolon or the
  2104. // possibility to insert one.
  2105. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  2106. else { node.argument = this.parseExpression(); this.semicolon(); }
  2107. return this.finishNode(node, "ReturnStatement")
  2108. };
  2109. pp$1.parseSwitchStatement = function(node) {
  2110. var this$1 = this;
  2111. this.next();
  2112. node.discriminant = this.parseParenExpression();
  2113. node.cases = [];
  2114. this.expect(types.braceL);
  2115. this.labels.push(switchLabel);
  2116. this.enterLexicalScope();
  2117. // Statements under must be grouped (by label) in SwitchCase
  2118. // nodes. `cur` is used to keep the node that we are currently
  2119. // adding statements to.
  2120. var cur;
  2121. for (var sawDefault = false; this.type != types.braceR;) {
  2122. if (this$1.type === types._case || this$1.type === types._default) {
  2123. var isCase = this$1.type === types._case;
  2124. if (cur) { this$1.finishNode(cur, "SwitchCase"); }
  2125. node.cases.push(cur = this$1.startNode());
  2126. cur.consequent = [];
  2127. this$1.next();
  2128. if (isCase) {
  2129. cur.test = this$1.parseExpression();
  2130. } else {
  2131. if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
  2132. sawDefault = true;
  2133. cur.test = null;
  2134. }
  2135. this$1.expect(types.colon);
  2136. } else {
  2137. if (!cur) { this$1.unexpected(); }
  2138. cur.consequent.push(this$1.parseStatement(true));
  2139. }
  2140. }
  2141. this.exitLexicalScope();
  2142. if (cur) { this.finishNode(cur, "SwitchCase"); }
  2143. this.next(); // Closing brace
  2144. this.labels.pop();
  2145. return this.finishNode(node, "SwitchStatement")
  2146. };
  2147. pp$1.parseThrowStatement = function(node) {
  2148. this.next();
  2149. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  2150. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  2151. node.argument = this.parseExpression();
  2152. this.semicolon();
  2153. return this.finishNode(node, "ThrowStatement")
  2154. };
  2155. // Reused empty array added for node fields that are always empty.
  2156. var empty = [];
  2157. pp$1.parseTryStatement = function(node) {
  2158. this.next();
  2159. node.block = this.parseBlock();
  2160. node.handler = null;
  2161. if (this.type === types._catch) {
  2162. var clause = this.startNode();
  2163. this.next();
  2164. this.expect(types.parenL);
  2165. clause.param = this.parseBindingAtom();
  2166. this.enterLexicalScope();
  2167. this.checkLVal(clause.param, "let");
  2168. this.expect(types.parenR);
  2169. clause.body = this.parseBlock(false);
  2170. this.exitLexicalScope();
  2171. node.handler = this.finishNode(clause, "CatchClause");
  2172. }
  2173. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  2174. if (!node.handler && !node.finalizer)
  2175. { this.raise(node.start, "Missing catch or finally clause"); }
  2176. return this.finishNode(node, "TryStatement")
  2177. };
  2178. pp$1.parseVarStatement = function(node, kind) {
  2179. this.next();
  2180. this.parseVar(node, false, kind);
  2181. this.semicolon();
  2182. return this.finishNode(node, "VariableDeclaration")
  2183. };
  2184. pp$1.parseWhileStatement = function(node) {
  2185. this.next();
  2186. node.test = this.parseParenExpression();
  2187. this.labels.push(loopLabel);
  2188. node.body = this.parseStatement(false);
  2189. this.labels.pop();
  2190. return this.finishNode(node, "WhileStatement")
  2191. };
  2192. pp$1.parseWithStatement = function(node) {
  2193. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  2194. this.next();
  2195. node.object = this.parseParenExpression();
  2196. node.body = this.parseStatement(false);
  2197. return this.finishNode(node, "WithStatement")
  2198. };
  2199. pp$1.parseEmptyStatement = function(node) {
  2200. this.next();
  2201. return this.finishNode(node, "EmptyStatement")
  2202. };
  2203. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  2204. var this$1 = this;
  2205. for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
  2206. {
  2207. var label = list[i$1];
  2208. if (label.name === maybeName)
  2209. { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  2210. } }
  2211. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  2212. for (var i = this.labels.length - 1; i >= 0; i--) {
  2213. var label$1 = this$1.labels[i];
  2214. if (label$1.statementStart == node.start) {
  2215. label$1.statementStart = this$1.start;
  2216. label$1.kind = kind;
  2217. } else { break }
  2218. }
  2219. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  2220. node.body = this.parseStatement(true);
  2221. if (node.body.type == "ClassDeclaration" ||
  2222. node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
  2223. node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
  2224. { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
  2225. this.labels.pop();
  2226. node.label = expr;
  2227. return this.finishNode(node, "LabeledStatement")
  2228. };
  2229. pp$1.parseExpressionStatement = function(node, expr) {
  2230. node.expression = expr;
  2231. this.semicolon();
  2232. return this.finishNode(node, "ExpressionStatement")
  2233. };
  2234. // Parse a semicolon-enclosed block of statements, handling `"use
  2235. // strict"` declarations when `allowStrict` is true (used for
  2236. // function bodies).
  2237. pp$1.parseBlock = function(createNewLexicalScope) {
  2238. var this$1 = this;
  2239. if ( createNewLexicalScope === void 0 ) { createNewLexicalScope = true; }
  2240. var node = this.startNode();
  2241. node.body = [];
  2242. this.expect(types.braceL);
  2243. if (createNewLexicalScope) {
  2244. this.enterLexicalScope();
  2245. }
  2246. while (!this.eat(types.braceR)) {
  2247. var stmt = this$1.parseStatement(true);
  2248. node.body.push(stmt);
  2249. }
  2250. if (createNewLexicalScope) {
  2251. this.exitLexicalScope();
  2252. }
  2253. return this.finishNode(node, "BlockStatement")
  2254. };
  2255. // Parse a regular `for` loop. The disambiguation code in
  2256. // `parseStatement` will already have parsed the init statement or
  2257. // expression.
  2258. pp$1.parseFor = function(node, init) {
  2259. node.init = init;
  2260. this.expect(types.semi);
  2261. node.test = this.type === types.semi ? null : this.parseExpression();
  2262. this.expect(types.semi);
  2263. node.update = this.type === types.parenR ? null : this.parseExpression();
  2264. this.expect(types.parenR);
  2265. this.exitLexicalScope();
  2266. node.body = this.parseStatement(false);
  2267. this.labels.pop();
  2268. return this.finishNode(node, "ForStatement")
  2269. };
  2270. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  2271. // same from parser's perspective.
  2272. pp$1.parseForIn = function(node, init) {
  2273. var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
  2274. this.next();
  2275. node.left = init;
  2276. node.right = this.parseExpression();
  2277. this.expect(types.parenR);
  2278. this.exitLexicalScope();
  2279. node.body = this.parseStatement(false);
  2280. this.labels.pop();
  2281. return this.finishNode(node, type)
  2282. };
  2283. // Parse a list of variable declarations.
  2284. pp$1.parseVar = function(node, isFor, kind) {
  2285. var this$1 = this;
  2286. node.declarations = [];
  2287. node.kind = kind;
  2288. for (;;) {
  2289. var decl = this$1.startNode();
  2290. this$1.parseVarId(decl, kind);
  2291. if (this$1.eat(types.eq)) {
  2292. decl.init = this$1.parseMaybeAssign(isFor);
  2293. } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  2294. this$1.unexpected();
  2295. } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
  2296. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  2297. } else {
  2298. decl.init = null;
  2299. }
  2300. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  2301. if (!this$1.eat(types.comma)) { break }
  2302. }
  2303. return node
  2304. };
  2305. pp$1.parseVarId = function(decl, kind) {
  2306. decl.id = this.parseBindingAtom(kind);
  2307. this.checkLVal(decl.id, kind, false);
  2308. };
  2309. // Parse a function declaration or literal (depending on the
  2310. // `isStatement` parameter).
  2311. pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
  2312. this.initFunction(node);
  2313. if (this.options.ecmaVersion >= 6 && !isAsync)
  2314. { node.generator = this.eat(types.star); }
  2315. if (this.options.ecmaVersion >= 8)
  2316. { node.async = !!isAsync; }
  2317. if (isStatement) {
  2318. node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
  2319. if (node.id) {
  2320. this.checkLVal(node.id, "var");
  2321. }
  2322. }
  2323. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2324. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2325. this.inGenerator = node.generator;
  2326. this.inAsync = node.async;
  2327. this.yieldPos = 0;
  2328. this.awaitPos = 0;
  2329. this.inFunction = true;
  2330. this.enterFunctionScope();
  2331. if (!isStatement)
  2332. { node.id = this.type == types.name ? this.parseIdent() : null; }
  2333. this.parseFunctionParams(node);
  2334. this.parseFunctionBody(node, allowExpressionBody);
  2335. this.inGenerator = oldInGen;
  2336. this.inAsync = oldInAsync;
  2337. this.yieldPos = oldYieldPos;
  2338. this.awaitPos = oldAwaitPos;
  2339. this.inFunction = oldInFunc;
  2340. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  2341. };
  2342. pp$1.parseFunctionParams = function(node) {
  2343. this.expect(types.parenL);
  2344. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2345. this.checkYieldAwaitInDefaultParams();
  2346. };
  2347. // Parse a class declaration or literal (depending on the
  2348. // `isStatement` parameter).
  2349. pp$1.parseClass = function(node, isStatement) {
  2350. var this$1 = this;
  2351. this.next();
  2352. this.parseClassId(node, isStatement);
  2353. this.parseClassSuper(node);
  2354. var classBody = this.startNode();
  2355. var hadConstructor = false;
  2356. classBody.body = [];
  2357. this.expect(types.braceL);
  2358. while (!this.eat(types.braceR)) {
  2359. if (this$1.eat(types.semi)) { continue }
  2360. var method = this$1.startNode();
  2361. var isGenerator = this$1.eat(types.star);
  2362. var isAsync = false;
  2363. var isMaybeStatic = this$1.type === types.name && this$1.value === "static";
  2364. this$1.parsePropertyName(method);
  2365. method.static = isMaybeStatic && this$1.type !== types.parenL;
  2366. if (method.static) {
  2367. if (isGenerator) { this$1.unexpected(); }
  2368. isGenerator = this$1.eat(types.star);
  2369. this$1.parsePropertyName(method);
  2370. }
  2371. if (this$1.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
  2372. method.key.type === "Identifier" && method.key.name === "async" && this$1.type !== types.parenL &&
  2373. !this$1.canInsertSemicolon()) {
  2374. isAsync = true;
  2375. this$1.parsePropertyName(method);
  2376. }
  2377. method.kind = "method";
  2378. var isGetSet = false;
  2379. if (!method.computed) {
  2380. var key = method.key;
  2381. if (!isGenerator && !isAsync && key.type === "Identifier" && this$1.type !== types.parenL && (key.name === "get" || key.name === "set")) {
  2382. isGetSet = true;
  2383. method.kind = key.name;
  2384. key = this$1.parsePropertyName(method);
  2385. }
  2386. if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
  2387. key.type === "Literal" && key.value === "constructor")) {
  2388. if (hadConstructor) { this$1.raise(key.start, "Duplicate constructor in the same class"); }
  2389. if (isGetSet) { this$1.raise(key.start, "Constructor can't have get/set modifier"); }
  2390. if (isGenerator) { this$1.raise(key.start, "Constructor can't be a generator"); }
  2391. if (isAsync) { this$1.raise(key.start, "Constructor can't be an async method"); }
  2392. method.kind = "constructor";
  2393. hadConstructor = true;
  2394. }
  2395. }
  2396. this$1.parseClassMethod(classBody, method, isGenerator, isAsync);
  2397. if (isGetSet) {
  2398. var paramCount = method.kind === "get" ? 0 : 1;
  2399. if (method.value.params.length !== paramCount) {
  2400. var start = method.value.start;
  2401. if (method.kind === "get")
  2402. { this$1.raiseRecoverable(start, "getter should have no params"); }
  2403. else
  2404. { this$1.raiseRecoverable(start, "setter should have exactly one param"); }
  2405. } else {
  2406. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  2407. { this$1.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  2408. }
  2409. }
  2410. }
  2411. node.body = this.finishNode(classBody, "ClassBody");
  2412. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  2413. };
  2414. pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
  2415. method.value = this.parseMethod(isGenerator, isAsync);
  2416. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  2417. };
  2418. pp$1.parseClassId = function(node, isStatement) {
  2419. node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
  2420. };
  2421. pp$1.parseClassSuper = function(node) {
  2422. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  2423. };
  2424. // Parses module export declaration.
  2425. pp$1.parseExport = function(node, exports) {
  2426. var this$1 = this;
  2427. this.next();
  2428. // export * from '...'
  2429. if (this.eat(types.star)) {
  2430. this.expectContextual("from");
  2431. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  2432. this.semicolon();
  2433. return this.finishNode(node, "ExportAllDeclaration")
  2434. }
  2435. if (this.eat(types._default)) { // export default ...
  2436. this.checkExport(exports, "default", this.lastTokStart);
  2437. var isAsync;
  2438. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  2439. var fNode = this.startNode();
  2440. this.next();
  2441. if (isAsync) { this.next(); }
  2442. node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
  2443. } else if (this.type === types._class) {
  2444. var cNode = this.startNode();
  2445. node.declaration = this.parseClass(cNode, "nullableID");
  2446. } else {
  2447. node.declaration = this.parseMaybeAssign();
  2448. this.semicolon();
  2449. }
  2450. return this.finishNode(node, "ExportDefaultDeclaration")
  2451. }
  2452. // export var|const|let|function|class ...
  2453. if (this.shouldParseExportStatement()) {
  2454. node.declaration = this.parseStatement(true);
  2455. if (node.declaration.type === "VariableDeclaration")
  2456. { this.checkVariableExport(exports, node.declaration.declarations); }
  2457. else
  2458. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  2459. node.specifiers = [];
  2460. node.source = null;
  2461. } else { // export { x, y as z } [from '...']
  2462. node.declaration = null;
  2463. node.specifiers = this.parseExportSpecifiers(exports);
  2464. if (this.eatContextual("from")) {
  2465. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  2466. } else {
  2467. // check for keywords used as local names
  2468. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  2469. var spec = list[i];
  2470. this$1.checkUnreserved(spec.local);
  2471. }
  2472. node.source = null;
  2473. }
  2474. this.semicolon();
  2475. }
  2476. return this.finishNode(node, "ExportNamedDeclaration")
  2477. };
  2478. pp$1.checkExport = function(exports, name, pos) {
  2479. if (!exports) { return }
  2480. if (has(exports, name))
  2481. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  2482. exports[name] = true;
  2483. };
  2484. pp$1.checkPatternExport = function(exports, pat) {
  2485. var this$1 = this;
  2486. var type = pat.type;
  2487. if (type == "Identifier")
  2488. { this.checkExport(exports, pat.name, pat.start); }
  2489. else if (type == "ObjectPattern")
  2490. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  2491. {
  2492. var prop = list[i];
  2493. this$1.checkPatternExport(exports, prop.value);
  2494. } }
  2495. else if (type == "ArrayPattern")
  2496. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  2497. var elt = list$1[i$1];
  2498. if (elt) { this$1.checkPatternExport(exports, elt); }
  2499. } }
  2500. else if (type == "AssignmentPattern")
  2501. { this.checkPatternExport(exports, pat.left); }
  2502. else if (type == "ParenthesizedExpression")
  2503. { this.checkPatternExport(exports, pat.expression); }
  2504. };
  2505. pp$1.checkVariableExport = function(exports, decls) {
  2506. var this$1 = this;
  2507. if (!exports) { return }
  2508. for (var i = 0, list = decls; i < list.length; i += 1)
  2509. {
  2510. var decl = list[i];
  2511. this$1.checkPatternExport(exports, decl.id);
  2512. }
  2513. };
  2514. pp$1.shouldParseExportStatement = function() {
  2515. return this.type.keyword === "var" ||
  2516. this.type.keyword === "const" ||
  2517. this.type.keyword === "class" ||
  2518. this.type.keyword === "function" ||
  2519. this.isLet() ||
  2520. this.isAsyncFunction()
  2521. };
  2522. // Parses a comma-separated list of module exports.
  2523. pp$1.parseExportSpecifiers = function(exports) {
  2524. var this$1 = this;
  2525. var nodes = [], first = true;
  2526. // export { x, y as z } [from '...']
  2527. this.expect(types.braceL);
  2528. while (!this.eat(types.braceR)) {
  2529. if (!first) {
  2530. this$1.expect(types.comma);
  2531. if (this$1.afterTrailingComma(types.braceR)) { break }
  2532. } else { first = false; }
  2533. var node = this$1.startNode();
  2534. node.local = this$1.parseIdent(true);
  2535. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  2536. this$1.checkExport(exports, node.exported.name, node.exported.start);
  2537. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  2538. }
  2539. return nodes
  2540. };
  2541. // Parses import declaration.
  2542. pp$1.parseImport = function(node) {
  2543. this.next();
  2544. // import '...'
  2545. if (this.type === types.string) {
  2546. node.specifiers = empty;
  2547. node.source = this.parseExprAtom();
  2548. } else {
  2549. node.specifiers = this.parseImportSpecifiers();
  2550. this.expectContextual("from");
  2551. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  2552. }
  2553. this.semicolon();
  2554. return this.finishNode(node, "ImportDeclaration")
  2555. };
  2556. // Parses a comma-separated list of module imports.
  2557. pp$1.parseImportSpecifiers = function() {
  2558. var this$1 = this;
  2559. var nodes = [], first = true;
  2560. if (this.type === types.name) {
  2561. // import defaultObj, { x, y as z } from '...'
  2562. var node = this.startNode();
  2563. node.local = this.parseIdent();
  2564. this.checkLVal(node.local, "let");
  2565. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  2566. if (!this.eat(types.comma)) { return nodes }
  2567. }
  2568. if (this.type === types.star) {
  2569. var node$1 = this.startNode();
  2570. this.next();
  2571. this.expectContextual("as");
  2572. node$1.local = this.parseIdent();
  2573. this.checkLVal(node$1.local, "let");
  2574. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  2575. return nodes
  2576. }
  2577. this.expect(types.braceL);
  2578. while (!this.eat(types.braceR)) {
  2579. if (!first) {
  2580. this$1.expect(types.comma);
  2581. if (this$1.afterTrailingComma(types.braceR)) { break }
  2582. } else { first = false; }
  2583. var node$2 = this$1.startNode();
  2584. node$2.imported = this$1.parseIdent(true);
  2585. if (this$1.eatContextual("as")) {
  2586. node$2.local = this$1.parseIdent();
  2587. } else {
  2588. this$1.checkUnreserved(node$2.imported);
  2589. node$2.local = node$2.imported;
  2590. }
  2591. this$1.checkLVal(node$2.local, "let");
  2592. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  2593. }
  2594. return nodes
  2595. };
  2596. var pp$2 = Parser.prototype;
  2597. // Convert existing expression atom to assignable pattern
  2598. // if possible.
  2599. pp$2.toAssignable = function(node, isBinding) {
  2600. var this$1 = this;
  2601. if (this.options.ecmaVersion >= 6 && node) {
  2602. switch (node.type) {
  2603. case "Identifier":
  2604. if (this.inAsync && node.name === "await")
  2605. { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
  2606. break
  2607. case "ObjectPattern":
  2608. case "ArrayPattern":
  2609. break
  2610. case "ObjectExpression":
  2611. node.type = "ObjectPattern";
  2612. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  2613. var prop = list[i];
  2614. if (prop.kind !== "init") { this$1.raise(prop.key.start, "Object pattern can't contain getter or setter"); }
  2615. this$1.toAssignable(prop.value, isBinding);
  2616. }
  2617. break
  2618. case "ArrayExpression":
  2619. node.type = "ArrayPattern";
  2620. this.toAssignableList(node.elements, isBinding);
  2621. break
  2622. case "AssignmentExpression":
  2623. if (node.operator === "=") {
  2624. node.type = "AssignmentPattern";
  2625. delete node.operator;
  2626. this.toAssignable(node.left, isBinding);
  2627. // falls through to AssignmentPattern
  2628. } else {
  2629. this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
  2630. break
  2631. }
  2632. case "AssignmentPattern":
  2633. break
  2634. case "ParenthesizedExpression":
  2635. this.toAssignable(node.expression, isBinding);
  2636. break
  2637. case "MemberExpression":
  2638. if (!isBinding) { break }
  2639. default:
  2640. this.raise(node.start, "Assigning to rvalue");
  2641. }
  2642. }
  2643. return node
  2644. };
  2645. // Convert list of expression atoms to binding list.
  2646. pp$2.toAssignableList = function(exprList, isBinding) {
  2647. var this$1 = this;
  2648. var end = exprList.length;
  2649. if (end) {
  2650. var last = exprList[end - 1];
  2651. if (last && last.type == "RestElement") {
  2652. --end;
  2653. } else if (last && last.type == "SpreadElement") {
  2654. last.type = "RestElement";
  2655. var arg = last.argument;
  2656. this.toAssignable(arg, isBinding);
  2657. --end;
  2658. }
  2659. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  2660. { this.unexpected(last.argument.start); }
  2661. }
  2662. for (var i = 0; i < end; i++) {
  2663. var elt = exprList[i];
  2664. if (elt) { this$1.toAssignable(elt, isBinding); }
  2665. }
  2666. return exprList
  2667. };
  2668. // Parses spread element.
  2669. pp$2.parseSpread = function(refDestructuringErrors) {
  2670. var node = this.startNode();
  2671. this.next();
  2672. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2673. return this.finishNode(node, "SpreadElement")
  2674. };
  2675. pp$2.parseRestBinding = function() {
  2676. var node = this.startNode();
  2677. this.next();
  2678. // RestElement inside of a function parameter must be an identifier
  2679. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  2680. { this.unexpected(); }
  2681. node.argument = this.parseBindingAtom();
  2682. return this.finishNode(node, "RestElement")
  2683. };
  2684. // Parses lvalue (assignable) atom.
  2685. pp$2.parseBindingAtom = function() {
  2686. if (this.options.ecmaVersion < 6) { return this.parseIdent() }
  2687. switch (this.type) {
  2688. case types.name:
  2689. return this.parseIdent()
  2690. case types.bracketL:
  2691. var node = this.startNode();
  2692. this.next();
  2693. node.elements = this.parseBindingList(types.bracketR, true, true);
  2694. return this.finishNode(node, "ArrayPattern")
  2695. case types.braceL:
  2696. return this.parseObj(true)
  2697. default:
  2698. this.unexpected();
  2699. }
  2700. };
  2701. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  2702. var this$1 = this;
  2703. var elts = [], first = true;
  2704. while (!this.eat(close)) {
  2705. if (first) { first = false; }
  2706. else { this$1.expect(types.comma); }
  2707. if (allowEmpty && this$1.type === types.comma) {
  2708. elts.push(null);
  2709. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  2710. break
  2711. } else if (this$1.type === types.ellipsis) {
  2712. var rest = this$1.parseRestBinding();
  2713. this$1.parseBindingListItem(rest);
  2714. elts.push(rest);
  2715. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  2716. this$1.expect(close);
  2717. break
  2718. } else {
  2719. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  2720. this$1.parseBindingListItem(elem);
  2721. elts.push(elem);
  2722. }
  2723. }
  2724. return elts
  2725. };
  2726. pp$2.parseBindingListItem = function(param) {
  2727. return param
  2728. };
  2729. // Parses assignment pattern around given atom if possible.
  2730. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  2731. left = left || this.parseBindingAtom();
  2732. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  2733. var node = this.startNodeAt(startPos, startLoc);
  2734. node.left = left;
  2735. node.right = this.parseMaybeAssign();
  2736. return this.finishNode(node, "AssignmentPattern")
  2737. };
  2738. // Verify that a node is an lval — something that can be assigned
  2739. // to.
  2740. // bindingType can be either:
  2741. // 'var' indicating that the lval creates a 'var' binding
  2742. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  2743. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  2744. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  2745. var this$1 = this;
  2746. switch (expr.type) {
  2747. case "Identifier":
  2748. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  2749. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  2750. if (checkClashes) {
  2751. if (has(checkClashes, expr.name))
  2752. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  2753. checkClashes[expr.name] = true;
  2754. }
  2755. if (bindingType && bindingType !== "none") {
  2756. if (
  2757. bindingType === "var" && !this.canDeclareVarName(expr.name) ||
  2758. bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
  2759. ) {
  2760. this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
  2761. }
  2762. if (bindingType === "var") {
  2763. this.declareVarName(expr.name);
  2764. } else {
  2765. this.declareLexicalName(expr.name);
  2766. }
  2767. }
  2768. break
  2769. case "MemberExpression":
  2770. if (bindingType) { this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression"); }
  2771. break
  2772. case "ObjectPattern":
  2773. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  2774. {
  2775. var prop = list[i];
  2776. this$1.checkLVal(prop.value, bindingType, checkClashes);
  2777. }
  2778. break
  2779. case "ArrayPattern":
  2780. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  2781. var elem = list$1[i$1];
  2782. if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
  2783. }
  2784. break
  2785. case "AssignmentPattern":
  2786. this.checkLVal(expr.left, bindingType, checkClashes);
  2787. break
  2788. case "RestElement":
  2789. this.checkLVal(expr.argument, bindingType, checkClashes);
  2790. break
  2791. case "ParenthesizedExpression":
  2792. this.checkLVal(expr.expression, bindingType, checkClashes);
  2793. break
  2794. default:
  2795. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  2796. }
  2797. };
  2798. // A recursive descent parser operates by defining functions for all
  2799. // syntactic elements, and recursively calling those, each function
  2800. // advancing the input stream and returning an AST node. Precedence
  2801. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  2802. // instead of `(!x)[1]` is handled by the fact that the parser
  2803. // function that parses unary prefix operators is called first, and
  2804. // in turn calls the function that parses `[]` subscripts — that
  2805. // way, it'll receive the node for `x[1]` already parsed, and wraps
  2806. // *that* in the unary operator node.
  2807. //
  2808. // Acorn uses an [operator precedence parser][opp] to handle binary
  2809. // operator precedence, because it is much more compact than using
  2810. // the technique outlined above, which uses different, nesting
  2811. // functions to specify precedence, for all of the ten binary
  2812. // precedence levels that JavaScript defines.
  2813. //
  2814. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  2815. var pp$3 = Parser.prototype;
  2816. // Check if property name clashes with already added.
  2817. // Object/class getters and setters are not allowed to clash —
  2818. // either with each other or with an init property — and in
  2819. // strict mode, init properties are also not allowed to be repeated.
  2820. pp$3.checkPropClash = function(prop, propHash) {
  2821. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  2822. { return }
  2823. var key = prop.key;
  2824. var name;
  2825. switch (key.type) {
  2826. case "Identifier": name = key.name; break
  2827. case "Literal": name = String(key.value); break
  2828. default: return
  2829. }
  2830. var kind = prop.kind;
  2831. if (this.options.ecmaVersion >= 6) {
  2832. if (name === "__proto__" && kind === "init") {
  2833. if (propHash.proto) { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  2834. propHash.proto = true;
  2835. }
  2836. return
  2837. }
  2838. name = "$" + name;
  2839. var other = propHash[name];
  2840. if (other) {
  2841. var redefinition;
  2842. if (kind === "init") {
  2843. redefinition = this.strict && other.init || other.get || other.set;
  2844. } else {
  2845. redefinition = other.init || other[kind];
  2846. }
  2847. if (redefinition)
  2848. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  2849. } else {
  2850. other = propHash[name] = {
  2851. init: false,
  2852. get: false,
  2853. set: false
  2854. };
  2855. }
  2856. other[kind] = true;
  2857. };
  2858. // ### Expression parsing
  2859. // These nest, from the most general expression type at the top to
  2860. // 'atomic', nondivisible expression types at the bottom. Most of
  2861. // the functions will simply let the function(s) below them parse,
  2862. // and, *if* the syntactic construct they handle is present, wrap
  2863. // the AST node that the inner parser gave them in another node.
  2864. // Parse a full expression. The optional arguments are used to
  2865. // forbid the `in` operator (in for loops initalization expressions)
  2866. // and provide reference for storing '=' operator inside shorthand
  2867. // property assignment in contexts where both object expression
  2868. // and object pattern might appear (so it's possible to raise
  2869. // delayed syntax error at correct position).
  2870. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  2871. var this$1 = this;
  2872. var startPos = this.start, startLoc = this.startLoc;
  2873. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  2874. if (this.type === types.comma) {
  2875. var node = this.startNodeAt(startPos, startLoc);
  2876. node.expressions = [expr];
  2877. while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
  2878. return this.finishNode(node, "SequenceExpression")
  2879. }
  2880. return expr
  2881. };
  2882. // Parse an assignment expression. This includes applications of
  2883. // operators like `+=`.
  2884. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  2885. if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
  2886. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  2887. if (refDestructuringErrors) {
  2888. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  2889. oldTrailingComma = refDestructuringErrors.trailingComma;
  2890. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  2891. } else {
  2892. refDestructuringErrors = new DestructuringErrors;
  2893. ownDestructuringErrors = true;
  2894. }
  2895. var startPos = this.start, startLoc = this.startLoc;
  2896. if (this.type == types.parenL || this.type == types.name)
  2897. { this.potentialArrowAt = this.start; }
  2898. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  2899. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  2900. if (this.type.isAssign) {
  2901. this.checkPatternErrors(refDestructuringErrors, true);
  2902. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  2903. var node = this.startNodeAt(startPos, startLoc);
  2904. node.operator = this.value;
  2905. node.left = this.type === types.eq ? this.toAssignable(left) : left;
  2906. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  2907. this.checkLVal(left);
  2908. this.next();
  2909. node.right = this.parseMaybeAssign(noIn);
  2910. return this.finishNode(node, "AssignmentExpression")
  2911. } else {
  2912. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  2913. }
  2914. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  2915. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  2916. return left
  2917. };
  2918. // Parse a ternary conditional (`?:`) operator.
  2919. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  2920. var startPos = this.start, startLoc = this.startLoc;
  2921. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  2922. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2923. if (this.eat(types.question)) {
  2924. var node = this.startNodeAt(startPos, startLoc);
  2925. node.test = expr;
  2926. node.consequent = this.parseMaybeAssign();
  2927. this.expect(types.colon);
  2928. node.alternate = this.parseMaybeAssign(noIn);
  2929. return this.finishNode(node, "ConditionalExpression")
  2930. }
  2931. return expr
  2932. };
  2933. // Start the precedence parser.
  2934. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  2935. var startPos = this.start, startLoc = this.startLoc;
  2936. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  2937. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2938. return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  2939. };
  2940. // Parse binary operators with the operator precedence parsing
  2941. // algorithm. `left` is the left-hand side of the operator.
  2942. // `minPrec` provides context that allows the function to stop and
  2943. // defer further parser to one of its callers when it encounters an
  2944. // operator that has a lower precedence than the set it is parsing.
  2945. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  2946. var prec = this.type.binop;
  2947. if (prec != null && (!noIn || this.type !== types._in)) {
  2948. if (prec > minPrec) {
  2949. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  2950. var op = this.value;
  2951. this.next();
  2952. var startPos = this.start, startLoc = this.startLoc;
  2953. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  2954. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  2955. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  2956. }
  2957. }
  2958. return left
  2959. };
  2960. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  2961. var node = this.startNodeAt(startPos, startLoc);
  2962. node.left = left;
  2963. node.operator = op;
  2964. node.right = right;
  2965. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  2966. };
  2967. // Parse unary operators, both prefix and postfix.
  2968. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  2969. var this$1 = this;
  2970. var startPos = this.start, startLoc = this.startLoc, expr;
  2971. if (this.inAsync && this.isContextual("await")) {
  2972. expr = this.parseAwait(refDestructuringErrors);
  2973. sawUnary = true;
  2974. } else if (this.type.prefix) {
  2975. var node = this.startNode(), update = this.type === types.incDec;
  2976. node.operator = this.value;
  2977. node.prefix = true;
  2978. this.next();
  2979. node.argument = this.parseMaybeUnary(null, true);
  2980. this.checkExpressionErrors(refDestructuringErrors, true);
  2981. if (update) { this.checkLVal(node.argument); }
  2982. else if (this.strict && node.operator === "delete" &&
  2983. node.argument.type === "Identifier")
  2984. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  2985. else { sawUnary = true; }
  2986. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  2987. } else {
  2988. expr = this.parseExprSubscripts(refDestructuringErrors);
  2989. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2990. while (this.type.postfix && !this.canInsertSemicolon()) {
  2991. var node$1 = this$1.startNodeAt(startPos, startLoc);
  2992. node$1.operator = this$1.value;
  2993. node$1.prefix = false;
  2994. node$1.argument = expr;
  2995. this$1.checkLVal(expr);
  2996. this$1.next();
  2997. expr = this$1.finishNode(node$1, "UpdateExpression");
  2998. }
  2999. }
  3000. if (!sawUnary && this.eat(types.starstar))
  3001. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  3002. else
  3003. { return expr }
  3004. };
  3005. // Parse call, dot, and `[]`-subscript expressions.
  3006. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  3007. var startPos = this.start, startLoc = this.startLoc;
  3008. var expr = this.parseExprAtom(refDestructuringErrors);
  3009. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  3010. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  3011. var result = this.parseSubscripts(expr, startPos, startLoc);
  3012. if (refDestructuringErrors && result.type === "MemberExpression") {
  3013. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  3014. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  3015. }
  3016. return result
  3017. };
  3018. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  3019. var this$1 = this;
  3020. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  3021. this.lastTokEnd == base.end && !this.canInsertSemicolon();
  3022. for (var computed = (void 0);;) {
  3023. if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
  3024. var node = this$1.startNodeAt(startPos, startLoc);
  3025. node.object = base;
  3026. node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
  3027. node.computed = !!computed;
  3028. if (computed) { this$1.expect(types.bracketR); }
  3029. base = this$1.finishNode(node, "MemberExpression");
  3030. } else if (!noCalls && this$1.eat(types.parenL)) {
  3031. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
  3032. this$1.yieldPos = 0;
  3033. this$1.awaitPos = 0;
  3034. var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
  3035. if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
  3036. this$1.checkPatternErrors(refDestructuringErrors, false);
  3037. this$1.checkYieldAwaitInDefaultParams();
  3038. this$1.yieldPos = oldYieldPos;
  3039. this$1.awaitPos = oldAwaitPos;
  3040. return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
  3041. }
  3042. this$1.checkExpressionErrors(refDestructuringErrors, true);
  3043. this$1.yieldPos = oldYieldPos || this$1.yieldPos;
  3044. this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
  3045. var node$1 = this$1.startNodeAt(startPos, startLoc);
  3046. node$1.callee = base;
  3047. node$1.arguments = exprList;
  3048. base = this$1.finishNode(node$1, "CallExpression");
  3049. } else if (this$1.type === types.backQuote) {
  3050. var node$2 = this$1.startNodeAt(startPos, startLoc);
  3051. node$2.tag = base;
  3052. node$2.quasi = this$1.parseTemplate({isTagged: true});
  3053. base = this$1.finishNode(node$2, "TaggedTemplateExpression");
  3054. } else {
  3055. return base
  3056. }
  3057. }
  3058. };
  3059. // Parse an atomic expression — either a single token that is an
  3060. // expression, an expression started by a keyword like `function` or
  3061. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  3062. // or `{}`.
  3063. pp$3.parseExprAtom = function(refDestructuringErrors) {
  3064. var node, canBeArrow = this.potentialArrowAt == this.start;
  3065. switch (this.type) {
  3066. case types._super:
  3067. if (!this.inFunction)
  3068. { this.raise(this.start, "'super' outside of function or class"); }
  3069. case types._this:
  3070. var type = this.type === types._this ? "ThisExpression" : "Super";
  3071. node = this.startNode();
  3072. this.next();
  3073. return this.finishNode(node, type)
  3074. case types.name:
  3075. var startPos = this.start, startLoc = this.startLoc;
  3076. var id = this.parseIdent(this.type !== types.name);
  3077. if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  3078. { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
  3079. if (canBeArrow && !this.canInsertSemicolon()) {
  3080. if (this.eat(types.arrow))
  3081. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  3082. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name) {
  3083. id = this.parseIdent();
  3084. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  3085. { this.unexpected(); }
  3086. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  3087. }
  3088. }
  3089. return id
  3090. case types.regexp:
  3091. var value = this.value;
  3092. node = this.parseLiteral(value.value);
  3093. node.regex = {pattern: value.pattern, flags: value.flags};
  3094. return node
  3095. case types.num: case types.string:
  3096. return this.parseLiteral(this.value)
  3097. case types._null: case types._true: case types._false:
  3098. node = this.startNode();
  3099. node.value = this.type === types._null ? null : this.type === types._true;
  3100. node.raw = this.type.keyword;
  3101. this.next();
  3102. return this.finishNode(node, "Literal")
  3103. case types.parenL:
  3104. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  3105. if (refDestructuringErrors) {
  3106. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  3107. { refDestructuringErrors.parenthesizedAssign = start; }
  3108. if (refDestructuringErrors.parenthesizedBind < 0)
  3109. { refDestructuringErrors.parenthesizedBind = start; }
  3110. }
  3111. return expr
  3112. case types.bracketL:
  3113. node = this.startNode();
  3114. this.next();
  3115. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  3116. return this.finishNode(node, "ArrayExpression")
  3117. case types.braceL:
  3118. return this.parseObj(false, refDestructuringErrors)
  3119. case types._function:
  3120. node = this.startNode();
  3121. this.next();
  3122. return this.parseFunction(node, false)
  3123. case types._class:
  3124. return this.parseClass(this.startNode(), false)
  3125. case types._new:
  3126. return this.parseNew()
  3127. case types.backQuote:
  3128. return this.parseTemplate()
  3129. default:
  3130. this.unexpected();
  3131. }
  3132. };
  3133. pp$3.parseLiteral = function(value) {
  3134. var node = this.startNode();
  3135. node.value = value;
  3136. node.raw = this.input.slice(this.start, this.end);
  3137. this.next();
  3138. return this.finishNode(node, "Literal")
  3139. };
  3140. pp$3.parseParenExpression = function() {
  3141. this.expect(types.parenL);
  3142. var val = this.parseExpression();
  3143. this.expect(types.parenR);
  3144. return val
  3145. };
  3146. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  3147. var this$1 = this;
  3148. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  3149. if (this.options.ecmaVersion >= 6) {
  3150. this.next();
  3151. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  3152. var exprList = [], first = true, lastIsComma = false;
  3153. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart;
  3154. this.yieldPos = 0;
  3155. this.awaitPos = 0;
  3156. while (this.type !== types.parenR) {
  3157. first ? first = false : this$1.expect(types.comma);
  3158. if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
  3159. lastIsComma = true;
  3160. break
  3161. } else if (this$1.type === types.ellipsis) {
  3162. spreadStart = this$1.start;
  3163. exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
  3164. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  3165. break
  3166. } else {
  3167. if (this$1.type === types.parenL && !innerParenStart) {
  3168. innerParenStart = this$1.start;
  3169. }
  3170. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  3171. }
  3172. }
  3173. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  3174. this.expect(types.parenR);
  3175. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  3176. this.checkPatternErrors(refDestructuringErrors, false);
  3177. this.checkYieldAwaitInDefaultParams();
  3178. if (innerParenStart) { this.unexpected(innerParenStart); }
  3179. this.yieldPos = oldYieldPos;
  3180. this.awaitPos = oldAwaitPos;
  3181. return this.parseParenArrowList(startPos, startLoc, exprList)
  3182. }
  3183. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  3184. if (spreadStart) { this.unexpected(spreadStart); }
  3185. this.checkExpressionErrors(refDestructuringErrors, true);
  3186. this.yieldPos = oldYieldPos || this.yieldPos;
  3187. this.awaitPos = oldAwaitPos || this.awaitPos;
  3188. if (exprList.length > 1) {
  3189. val = this.startNodeAt(innerStartPos, innerStartLoc);
  3190. val.expressions = exprList;
  3191. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  3192. } else {
  3193. val = exprList[0];
  3194. }
  3195. } else {
  3196. val = this.parseParenExpression();
  3197. }
  3198. if (this.options.preserveParens) {
  3199. var par = this.startNodeAt(startPos, startLoc);
  3200. par.expression = val;
  3201. return this.finishNode(par, "ParenthesizedExpression")
  3202. } else {
  3203. return val
  3204. }
  3205. };
  3206. pp$3.parseParenItem = function(item) {
  3207. return item
  3208. };
  3209. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  3210. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  3211. };
  3212. // New's precedence is slightly tricky. It must allow its argument to
  3213. // be a `[]` or dot subscript expression, but not a call — at least,
  3214. // not without wrapping it in parentheses. Thus, it uses the noCalls
  3215. // argument to parseSubscripts to prevent it from consuming the
  3216. // argument list.
  3217. var empty$1 = [];
  3218. pp$3.parseNew = function() {
  3219. var node = this.startNode();
  3220. var meta = this.parseIdent(true);
  3221. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  3222. node.meta = meta;
  3223. node.property = this.parseIdent(true);
  3224. if (node.property.name !== "target")
  3225. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  3226. if (!this.inFunction)
  3227. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  3228. return this.finishNode(node, "MetaProperty")
  3229. }
  3230. var startPos = this.start, startLoc = this.startLoc;
  3231. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  3232. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  3233. else { node.arguments = empty$1; }
  3234. return this.finishNode(node, "NewExpression")
  3235. };
  3236. // Parse template expression.
  3237. pp$3.parseTemplateElement = function(ref) {
  3238. var isTagged = ref.isTagged;
  3239. var elem = this.startNode();
  3240. if (this.type === types.invalidTemplate) {
  3241. if (!isTagged) {
  3242. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  3243. }
  3244. elem.value = {
  3245. raw: this.value,
  3246. cooked: null
  3247. };
  3248. } else {
  3249. elem.value = {
  3250. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  3251. cooked: this.value
  3252. };
  3253. }
  3254. this.next();
  3255. elem.tail = this.type === types.backQuote;
  3256. return this.finishNode(elem, "TemplateElement")
  3257. };
  3258. pp$3.parseTemplate = function(ref) {
  3259. var this$1 = this;
  3260. if ( ref === void 0 ) { ref = {}; }
  3261. var isTagged = ref.isTagged; if ( isTagged === void 0 ) { isTagged = false; }
  3262. var node = this.startNode();
  3263. this.next();
  3264. node.expressions = [];
  3265. var curElt = this.parseTemplateElement({isTagged: isTagged});
  3266. node.quasis = [curElt];
  3267. while (!curElt.tail) {
  3268. this$1.expect(types.dollarBraceL);
  3269. node.expressions.push(this$1.parseExpression());
  3270. this$1.expect(types.braceR);
  3271. node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
  3272. }
  3273. this.next();
  3274. return this.finishNode(node, "TemplateLiteral")
  3275. };
  3276. // Parse an object literal or binding pattern.
  3277. pp$3.isAsyncProp = function(prop) {
  3278. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  3279. (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword) &&
  3280. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  3281. };
  3282. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  3283. var this$1 = this;
  3284. var node = this.startNode(), first = true, propHash = {};
  3285. node.properties = [];
  3286. this.next();
  3287. while (!this.eat(types.braceR)) {
  3288. if (!first) {
  3289. this$1.expect(types.comma);
  3290. if (this$1.afterTrailingComma(types.braceR)) { break }
  3291. } else { first = false; }
  3292. var prop = this$1.startNode(), isGenerator = (void 0), isAsync = (void 0), startPos = (void 0), startLoc = (void 0);
  3293. if (this$1.options.ecmaVersion >= 6) {
  3294. prop.method = false;
  3295. prop.shorthand = false;
  3296. if (isPattern || refDestructuringErrors) {
  3297. startPos = this$1.start;
  3298. startLoc = this$1.startLoc;
  3299. }
  3300. if (!isPattern)
  3301. { isGenerator = this$1.eat(types.star); }
  3302. }
  3303. this$1.parsePropertyName(prop);
  3304. if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && this$1.isAsyncProp(prop)) {
  3305. isAsync = true;
  3306. this$1.parsePropertyName(prop, refDestructuringErrors);
  3307. } else {
  3308. isAsync = false;
  3309. }
  3310. this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
  3311. this$1.checkPropClash(prop, propHash);
  3312. node.properties.push(this$1.finishNode(prop, "Property"));
  3313. }
  3314. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  3315. };
  3316. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
  3317. if ((isGenerator || isAsync) && this.type === types.colon)
  3318. { this.unexpected(); }
  3319. if (this.eat(types.colon)) {
  3320. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  3321. prop.kind = "init";
  3322. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  3323. if (isPattern) { this.unexpected(); }
  3324. prop.kind = "init";
  3325. prop.method = true;
  3326. prop.value = this.parseMethod(isGenerator, isAsync);
  3327. } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  3328. (prop.key.name === "get" || prop.key.name === "set") &&
  3329. (this.type != types.comma && this.type != types.braceR)) {
  3330. if (isGenerator || isAsync || isPattern) { this.unexpected(); }
  3331. prop.kind = prop.key.name;
  3332. this.parsePropertyName(prop);
  3333. prop.value = this.parseMethod(false);
  3334. var paramCount = prop.kind === "get" ? 0 : 1;
  3335. if (prop.value.params.length !== paramCount) {
  3336. var start = prop.value.start;
  3337. if (prop.kind === "get")
  3338. { this.raiseRecoverable(start, "getter should have no params"); }
  3339. else
  3340. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  3341. } else {
  3342. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  3343. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  3344. }
  3345. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  3346. this.checkUnreserved(prop.key);
  3347. prop.kind = "init";
  3348. if (isPattern) {
  3349. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  3350. } else if (this.type === types.eq && refDestructuringErrors) {
  3351. if (refDestructuringErrors.shorthandAssign < 0)
  3352. { refDestructuringErrors.shorthandAssign = this.start; }
  3353. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  3354. } else {
  3355. prop.value = prop.key;
  3356. }
  3357. prop.shorthand = true;
  3358. } else { this.unexpected(); }
  3359. };
  3360. pp$3.parsePropertyName = function(prop) {
  3361. if (this.options.ecmaVersion >= 6) {
  3362. if (this.eat(types.bracketL)) {
  3363. prop.computed = true;
  3364. prop.key = this.parseMaybeAssign();
  3365. this.expect(types.bracketR);
  3366. return prop.key
  3367. } else {
  3368. prop.computed = false;
  3369. }
  3370. }
  3371. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
  3372. };
  3373. // Initialize empty function node.
  3374. pp$3.initFunction = function(node) {
  3375. node.id = null;
  3376. if (this.options.ecmaVersion >= 6) {
  3377. node.generator = false;
  3378. node.expression = false;
  3379. }
  3380. if (this.options.ecmaVersion >= 8)
  3381. { node.async = false; }
  3382. };
  3383. // Parse object or class method.
  3384. pp$3.parseMethod = function(isGenerator, isAsync) {
  3385. var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  3386. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  3387. this.initFunction(node);
  3388. if (this.options.ecmaVersion >= 6)
  3389. { node.generator = isGenerator; }
  3390. if (this.options.ecmaVersion >= 8)
  3391. { node.async = !!isAsync; }
  3392. this.inGenerator = node.generator;
  3393. this.inAsync = node.async;
  3394. this.yieldPos = 0;
  3395. this.awaitPos = 0;
  3396. this.inFunction = true;
  3397. this.enterFunctionScope();
  3398. this.expect(types.parenL);
  3399. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  3400. this.checkYieldAwaitInDefaultParams();
  3401. this.parseFunctionBody(node, false);
  3402. this.inGenerator = oldInGen;
  3403. this.inAsync = oldInAsync;
  3404. this.yieldPos = oldYieldPos;
  3405. this.awaitPos = oldAwaitPos;
  3406. this.inFunction = oldInFunc;
  3407. return this.finishNode(node, "FunctionExpression")
  3408. };
  3409. // Parse arrow function expression with given parameters.
  3410. pp$3.parseArrowExpression = function(node, params, isAsync) {
  3411. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  3412. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  3413. this.enterFunctionScope();
  3414. this.initFunction(node);
  3415. if (this.options.ecmaVersion >= 8)
  3416. { node.async = !!isAsync; }
  3417. this.inGenerator = false;
  3418. this.inAsync = node.async;
  3419. this.yieldPos = 0;
  3420. this.awaitPos = 0;
  3421. this.inFunction = true;
  3422. node.params = this.toAssignableList(params, true);
  3423. this.parseFunctionBody(node, true);
  3424. this.inGenerator = oldInGen;
  3425. this.inAsync = oldInAsync;
  3426. this.yieldPos = oldYieldPos;
  3427. this.awaitPos = oldAwaitPos;
  3428. this.inFunction = oldInFunc;
  3429. return this.finishNode(node, "ArrowFunctionExpression")
  3430. };
  3431. // Parse function body and check parameters.
  3432. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  3433. var isExpression = isArrowFunction && this.type !== types.braceL;
  3434. var oldStrict = this.strict, useStrict = false;
  3435. if (isExpression) {
  3436. node.body = this.parseMaybeAssign();
  3437. node.expression = true;
  3438. this.checkParams(node, false);
  3439. } else {
  3440. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  3441. if (!oldStrict || nonSimple) {
  3442. useStrict = this.strictDirective(this.end);
  3443. // If this is a strict mode function, verify that argument names
  3444. // are not repeated, and it does not try to bind the words `eval`
  3445. // or `arguments`.
  3446. if (useStrict && nonSimple)
  3447. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  3448. }
  3449. // Start a new scope with regard to labels and the `inFunction`
  3450. // flag (restore them to their old value afterwards).
  3451. var oldLabels = this.labels;
  3452. this.labels = [];
  3453. if (useStrict) { this.strict = true; }
  3454. // Add the params to varDeclaredNames to ensure that an error is thrown
  3455. // if a let/const declaration in the function clashes with one of the params.
  3456. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
  3457. node.body = this.parseBlock(false);
  3458. node.expression = false;
  3459. this.labels = oldLabels;
  3460. }
  3461. this.exitFunctionScope();
  3462. if (this.strict && node.id) {
  3463. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  3464. this.checkLVal(node.id, "none");
  3465. }
  3466. this.strict = oldStrict;
  3467. };
  3468. pp$3.isSimpleParamList = function(params) {
  3469. for (var i = 0, list = params; i < list.length; i += 1)
  3470. {
  3471. var param = list[i];
  3472. if (param.type !== "Identifier") { return false
  3473. } }
  3474. return true
  3475. };
  3476. // Checks function params for various disallowed patterns such as using "eval"
  3477. // or "arguments" and duplicate parameters.
  3478. pp$3.checkParams = function(node, allowDuplicates) {
  3479. var this$1 = this;
  3480. var nameHash = {};
  3481. for (var i = 0, list = node.params; i < list.length; i += 1)
  3482. {
  3483. var param = list[i];
  3484. this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
  3485. }
  3486. };
  3487. // Parses a comma-separated list of expressions, and returns them as
  3488. // an array. `close` is the token type that ends the list, and
  3489. // `allowEmpty` can be turned on to allow subsequent commas with
  3490. // nothing in between them to be parsed as `null` (which is needed
  3491. // for array literals).
  3492. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  3493. var this$1 = this;
  3494. var elts = [], first = true;
  3495. while (!this.eat(close)) {
  3496. if (!first) {
  3497. this$1.expect(types.comma);
  3498. if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
  3499. } else { first = false; }
  3500. var elt = (void 0);
  3501. if (allowEmpty && this$1.type === types.comma)
  3502. { elt = null; }
  3503. else if (this$1.type === types.ellipsis) {
  3504. elt = this$1.parseSpread(refDestructuringErrors);
  3505. if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
  3506. { refDestructuringErrors.trailingComma = this$1.start; }
  3507. } else {
  3508. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  3509. }
  3510. elts.push(elt);
  3511. }
  3512. return elts
  3513. };
  3514. // Parse the next token as an identifier. If `liberal` is true (used
  3515. // when parsing properties), it will also convert keywords into
  3516. // identifiers.
  3517. pp$3.checkUnreserved = function(ref) {
  3518. var start = ref.start;
  3519. var end = ref.end;
  3520. var name = ref.name;
  3521. if (this.inGenerator && name === "yield")
  3522. { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
  3523. if (this.inAsync && name === "await")
  3524. { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
  3525. if (this.isKeyword(name))
  3526. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  3527. if (this.options.ecmaVersion < 6 &&
  3528. this.input.slice(start, end).indexOf("\\") != -1) { return }
  3529. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  3530. if (re.test(name))
  3531. { this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); }
  3532. };
  3533. pp$3.parseIdent = function(liberal, isBinding) {
  3534. var node = this.startNode();
  3535. if (liberal && this.options.allowReserved == "never") { liberal = false; }
  3536. if (this.type === types.name) {
  3537. node.name = this.value;
  3538. } else if (this.type.keyword) {
  3539. node.name = this.type.keyword;
  3540. } else {
  3541. this.unexpected();
  3542. }
  3543. this.next();
  3544. this.finishNode(node, "Identifier");
  3545. if (!liberal) { this.checkUnreserved(node); }
  3546. return node
  3547. };
  3548. // Parses yield expression inside generator.
  3549. pp$3.parseYield = function() {
  3550. if (!this.yieldPos) { this.yieldPos = this.start; }
  3551. var node = this.startNode();
  3552. this.next();
  3553. if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
  3554. node.delegate = false;
  3555. node.argument = null;
  3556. } else {
  3557. node.delegate = this.eat(types.star);
  3558. node.argument = this.parseMaybeAssign();
  3559. }
  3560. return this.finishNode(node, "YieldExpression")
  3561. };
  3562. pp$3.parseAwait = function() {
  3563. if (!this.awaitPos) { this.awaitPos = this.start; }
  3564. var node = this.startNode();
  3565. this.next();
  3566. node.argument = this.parseMaybeUnary(null, true);
  3567. return this.finishNode(node, "AwaitExpression")
  3568. };
  3569. var pp$4 = Parser.prototype;
  3570. // This function is used to raise exceptions on parse errors. It
  3571. // takes an offset integer (into the current `input`) to indicate
  3572. // the location of the error, attaches the position to the end
  3573. // of the error message, and then raises a `SyntaxError` with that
  3574. // message.
  3575. pp$4.raise = function(pos, message) {
  3576. var loc = getLineInfo(this.input, pos);
  3577. message += " (" + loc.line + ":" + loc.column + ")";
  3578. var err = new SyntaxError(message);
  3579. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  3580. throw err
  3581. };
  3582. pp$4.raiseRecoverable = pp$4.raise;
  3583. pp$4.curPosition = function() {
  3584. if (this.options.locations) {
  3585. return new Position(this.curLine, this.pos - this.lineStart)
  3586. }
  3587. };
  3588. var pp$5 = Parser.prototype;
  3589. // Object.assign polyfill
  3590. var assign$1 = Object.assign || function(target) {
  3591. var sources = [], len = arguments.length - 1;
  3592. while ( len-- > 0 ) { sources[ len ] = arguments[ len + 1 ]; }
  3593. for (var i = 0, list = sources; i < list.length; i += 1) {
  3594. var source = list[i];
  3595. for (var key in source) {
  3596. if (has(source, key)) {
  3597. target[key] = source[key];
  3598. }
  3599. }
  3600. }
  3601. return target
  3602. };
  3603. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  3604. pp$5.enterFunctionScope = function() {
  3605. // var: a hash of var-declared names in the current lexical scope
  3606. // lexical: a hash of lexically-declared names in the current lexical scope
  3607. // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
  3608. // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
  3609. this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
  3610. };
  3611. pp$5.exitFunctionScope = function() {
  3612. this.scopeStack.pop();
  3613. };
  3614. pp$5.enterLexicalScope = function() {
  3615. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  3616. var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
  3617. this.scopeStack.push(childScope);
  3618. assign$1(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
  3619. };
  3620. pp$5.exitLexicalScope = function() {
  3621. var childScope = this.scopeStack.pop();
  3622. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  3623. assign$1(parentScope.childVar, childScope.var, childScope.childVar);
  3624. };
  3625. /**
  3626. * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
  3627. * in the current lexical scope or any of the parent lexical scopes in this function.
  3628. */
  3629. pp$5.canDeclareVarName = function(name) {
  3630. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  3631. return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
  3632. };
  3633. /**
  3634. * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
  3635. * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
  3636. * any child lexical scopes in this function.
  3637. */
  3638. pp$5.canDeclareLexicalName = function(name) {
  3639. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  3640. return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
  3641. };
  3642. pp$5.declareVarName = function(name) {
  3643. this.scopeStack[this.scopeStack.length - 1].var[name] = true;
  3644. };
  3645. pp$5.declareLexicalName = function(name) {
  3646. this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
  3647. };
  3648. var Node = function Node(parser, pos, loc) {
  3649. this.type = "";
  3650. this.start = pos;
  3651. this.end = 0;
  3652. if (parser.options.locations)
  3653. { this.loc = new SourceLocation(parser, loc); }
  3654. if (parser.options.directSourceFile)
  3655. { this.sourceFile = parser.options.directSourceFile; }
  3656. if (parser.options.ranges)
  3657. { this.range = [pos, 0]; }
  3658. };
  3659. // Start an AST node, attaching a start offset.
  3660. var pp$6 = Parser.prototype;
  3661. pp$6.startNode = function() {
  3662. return new Node(this, this.start, this.startLoc)
  3663. };
  3664. pp$6.startNodeAt = function(pos, loc) {
  3665. return new Node(this, pos, loc)
  3666. };
  3667. // Finish an AST node, adding `type` and `end` properties.
  3668. function finishNodeAt(node, type, pos, loc) {
  3669. node.type = type;
  3670. node.end = pos;
  3671. if (this.options.locations)
  3672. { node.loc.end = loc; }
  3673. if (this.options.ranges)
  3674. { node.range[1] = pos; }
  3675. return node
  3676. }
  3677. pp$6.finishNode = function(node, type) {
  3678. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  3679. };
  3680. // Finish node at given position
  3681. pp$6.finishNodeAt = function(node, type, pos, loc) {
  3682. return finishNodeAt.call(this, node, type, pos, loc)
  3683. };
  3684. // The algorithm used to determine whether a regexp can appear at a
  3685. // given point in the program is loosely based on sweet.js' approach.
  3686. // See https://github.com/mozilla/sweet.js/wiki/design
  3687. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  3688. this.token = token;
  3689. this.isExpr = !!isExpr;
  3690. this.preserveSpace = !!preserveSpace;
  3691. this.override = override;
  3692. this.generator = !!generator;
  3693. };
  3694. var types$1 = {
  3695. b_stat: new TokContext("{", false),
  3696. b_expr: new TokContext("{", true),
  3697. b_tmpl: new TokContext("${", false),
  3698. p_stat: new TokContext("(", false),
  3699. p_expr: new TokContext("(", true),
  3700. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  3701. f_stat: new TokContext("function", false),
  3702. f_expr: new TokContext("function", true),
  3703. f_expr_gen: new TokContext("function", true, false, null, true),
  3704. f_gen: new TokContext("function", false, false, null, true)
  3705. };
  3706. var pp$7 = Parser.prototype;
  3707. pp$7.initialContext = function() {
  3708. return [types$1.b_stat]
  3709. };
  3710. pp$7.braceIsBlock = function(prevType) {
  3711. var parent = this.curContext();
  3712. if (parent === types$1.f_expr || parent === types$1.f_stat)
  3713. { return true }
  3714. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  3715. { return !parent.isExpr }
  3716. // The check for `tt.name && exprAllowed` detects whether we are
  3717. // after a `yield` or `of` construct. See the `updateContext` for
  3718. // `tt.name`.
  3719. if (prevType === types._return || prevType == types.name && this.exprAllowed)
  3720. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  3721. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
  3722. { return true }
  3723. if (prevType == types.braceL)
  3724. { return parent === types$1.b_stat }
  3725. if (prevType == types._var || prevType == types.name)
  3726. { return false }
  3727. return !this.exprAllowed
  3728. };
  3729. pp$7.inGeneratorContext = function() {
  3730. var this$1 = this;
  3731. for (var i = this.context.length - 1; i >= 1; i--) {
  3732. var context = this$1.context[i];
  3733. if (context.token === "function")
  3734. { return context.generator }
  3735. }
  3736. return false
  3737. };
  3738. pp$7.updateContext = function(prevType) {
  3739. var update, type = this.type;
  3740. if (type.keyword && prevType == types.dot)
  3741. { this.exprAllowed = false; }
  3742. else if (update = type.updateContext)
  3743. { update.call(this, prevType); }
  3744. else
  3745. { this.exprAllowed = type.beforeExpr; }
  3746. };
  3747. // Token-specific context update code
  3748. types.parenR.updateContext = types.braceR.updateContext = function() {
  3749. if (this.context.length == 1) {
  3750. this.exprAllowed = true;
  3751. return
  3752. }
  3753. var out = this.context.pop();
  3754. if (out === types$1.b_stat && this.curContext().token === "function") {
  3755. out = this.context.pop();
  3756. }
  3757. this.exprAllowed = !out.isExpr;
  3758. };
  3759. types.braceL.updateContext = function(prevType) {
  3760. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  3761. this.exprAllowed = true;
  3762. };
  3763. types.dollarBraceL.updateContext = function() {
  3764. this.context.push(types$1.b_tmpl);
  3765. this.exprAllowed = true;
  3766. };
  3767. types.parenL.updateContext = function(prevType) {
  3768. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  3769. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  3770. this.exprAllowed = true;
  3771. };
  3772. types.incDec.updateContext = function() {
  3773. // tokExprAllowed stays unchanged
  3774. };
  3775. types._function.updateContext = types._class.updateContext = function(prevType) {
  3776. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  3777. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  3778. { this.context.push(types$1.f_expr); }
  3779. else
  3780. { this.context.push(types$1.f_stat); }
  3781. this.exprAllowed = false;
  3782. };
  3783. types.backQuote.updateContext = function() {
  3784. if (this.curContext() === types$1.q_tmpl)
  3785. { this.context.pop(); }
  3786. else
  3787. { this.context.push(types$1.q_tmpl); }
  3788. this.exprAllowed = false;
  3789. };
  3790. types.star.updateContext = function(prevType) {
  3791. if (prevType == types._function) {
  3792. var index = this.context.length - 1;
  3793. if (this.context[index] === types$1.f_expr)
  3794. { this.context[index] = types$1.f_expr_gen; }
  3795. else
  3796. { this.context[index] = types$1.f_gen; }
  3797. }
  3798. this.exprAllowed = true;
  3799. };
  3800. types.name.updateContext = function(prevType) {
  3801. var allowed = false;
  3802. if (this.options.ecmaVersion >= 6) {
  3803. if (this.value == "of" && !this.exprAllowed ||
  3804. this.value == "yield" && this.inGeneratorContext())
  3805. { allowed = true; }
  3806. }
  3807. this.exprAllowed = allowed;
  3808. };
  3809. // Object type used to represent tokens. Note that normally, tokens
  3810. // simply exist as properties on the parser object. This is only
  3811. // used for the onToken callback and the external tokenizer.
  3812. var Token = function Token(p) {
  3813. this.type = p.type;
  3814. this.value = p.value;
  3815. this.start = p.start;
  3816. this.end = p.end;
  3817. if (p.options.locations)
  3818. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  3819. if (p.options.ranges)
  3820. { this.range = [p.start, p.end]; }
  3821. };
  3822. // ## Tokenizer
  3823. var pp$8 = Parser.prototype;
  3824. // Are we running under Rhino?
  3825. var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
  3826. // Move to the next token
  3827. pp$8.next = function() {
  3828. if (this.options.onToken)
  3829. { this.options.onToken(new Token(this)); }
  3830. this.lastTokEnd = this.end;
  3831. this.lastTokStart = this.start;
  3832. this.lastTokEndLoc = this.endLoc;
  3833. this.lastTokStartLoc = this.startLoc;
  3834. this.nextToken();
  3835. };
  3836. pp$8.getToken = function() {
  3837. this.next();
  3838. return new Token(this)
  3839. };
  3840. // If we're in an ES6 environment, make parsers iterable
  3841. if (typeof Symbol !== "undefined")
  3842. { pp$8[Symbol.iterator] = function() {
  3843. var this$1 = this;
  3844. return {
  3845. next: function () {
  3846. var token = this$1.getToken();
  3847. return {
  3848. done: token.type === types.eof,
  3849. value: token
  3850. }
  3851. }
  3852. }
  3853. }; }
  3854. // Toggle strict mode. Re-reads the next number or string to please
  3855. // pedantic tests (`"use strict"; 010;` should fail).
  3856. pp$8.curContext = function() {
  3857. return this.context[this.context.length - 1]
  3858. };
  3859. // Read a single token, updating the parser object's token-related
  3860. // properties.
  3861. pp$8.nextToken = function() {
  3862. var curContext = this.curContext();
  3863. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  3864. this.start = this.pos;
  3865. if (this.options.locations) { this.startLoc = this.curPosition(); }
  3866. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  3867. if (curContext.override) { return curContext.override(this) }
  3868. else { this.readToken(this.fullCharCodeAtPos()); }
  3869. };
  3870. pp$8.readToken = function(code) {
  3871. // Identifier or keyword. '\uXXXX' sequences are allowed in
  3872. // identifiers, so '\' also dispatches to that.
  3873. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  3874. { return this.readWord() }
  3875. return this.getTokenFromCode(code)
  3876. };
  3877. pp$8.fullCharCodeAtPos = function() {
  3878. var code = this.input.charCodeAt(this.pos);
  3879. if (code <= 0xd7ff || code >= 0xe000) { return code }
  3880. var next = this.input.charCodeAt(this.pos + 1);
  3881. return (code << 10) + next - 0x35fdc00
  3882. };
  3883. pp$8.skipBlockComment = function() {
  3884. var this$1 = this;
  3885. var startLoc = this.options.onComment && this.curPosition();
  3886. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  3887. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  3888. this.pos = end + 2;
  3889. if (this.options.locations) {
  3890. lineBreakG.lastIndex = start;
  3891. var match;
  3892. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  3893. ++this$1.curLine;
  3894. this$1.lineStart = match.index + match[0].length;
  3895. }
  3896. }
  3897. if (this.options.onComment)
  3898. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  3899. startLoc, this.curPosition()); }
  3900. };
  3901. pp$8.skipLineComment = function(startSkip) {
  3902. var this$1 = this;
  3903. var start = this.pos;
  3904. var startLoc = this.options.onComment && this.curPosition();
  3905. var ch = this.input.charCodeAt(this.pos += startSkip);
  3906. while (this.pos < this.input.length && !isNewLine(ch)) {
  3907. ch = this$1.input.charCodeAt(++this$1.pos);
  3908. }
  3909. if (this.options.onComment)
  3910. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  3911. startLoc, this.curPosition()); }
  3912. };
  3913. // Called at the start of the parse and after every token. Skips
  3914. // whitespace and comments, and.
  3915. pp$8.skipSpace = function() {
  3916. var this$1 = this;
  3917. loop: while (this.pos < this.input.length) {
  3918. var ch = this$1.input.charCodeAt(this$1.pos);
  3919. switch (ch) {
  3920. case 32: case 160: // ' '
  3921. ++this$1.pos;
  3922. break
  3923. case 13:
  3924. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  3925. ++this$1.pos;
  3926. }
  3927. case 10: case 8232: case 8233:
  3928. ++this$1.pos;
  3929. if (this$1.options.locations) {
  3930. ++this$1.curLine;
  3931. this$1.lineStart = this$1.pos;
  3932. }
  3933. break
  3934. case 47: // '/'
  3935. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  3936. case 42: // '*'
  3937. this$1.skipBlockComment();
  3938. break
  3939. case 47:
  3940. this$1.skipLineComment(2);
  3941. break
  3942. default:
  3943. break loop
  3944. }
  3945. break
  3946. default:
  3947. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  3948. ++this$1.pos;
  3949. } else {
  3950. break loop
  3951. }
  3952. }
  3953. }
  3954. };
  3955. // Called at the end of every token. Sets `end`, `val`, and
  3956. // maintains `context` and `exprAllowed`, and skips the space after
  3957. // the token, so that the next one's `start` will point at the
  3958. // right position.
  3959. pp$8.finishToken = function(type, val) {
  3960. this.end = this.pos;
  3961. if (this.options.locations) { this.endLoc = this.curPosition(); }
  3962. var prevType = this.type;
  3963. this.type = type;
  3964. this.value = val;
  3965. this.updateContext(prevType);
  3966. };
  3967. // ### Token reading
  3968. // This is the function that is called to fetch the next token. It
  3969. // is somewhat obscure, because it works in character codes rather
  3970. // than characters, and because operator parsing has been inlined
  3971. // into it.
  3972. //
  3973. // All in the name of speed.
  3974. //
  3975. pp$8.readToken_dot = function() {
  3976. var next = this.input.charCodeAt(this.pos + 1);
  3977. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  3978. var next2 = this.input.charCodeAt(this.pos + 2);
  3979. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  3980. this.pos += 3;
  3981. return this.finishToken(types.ellipsis)
  3982. } else {
  3983. ++this.pos;
  3984. return this.finishToken(types.dot)
  3985. }
  3986. };
  3987. pp$8.readToken_slash = function() { // '/'
  3988. var next = this.input.charCodeAt(this.pos + 1);
  3989. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  3990. if (next === 61) { return this.finishOp(types.assign, 2) }
  3991. return this.finishOp(types.slash, 1)
  3992. };
  3993. pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
  3994. var next = this.input.charCodeAt(this.pos + 1);
  3995. var size = 1;
  3996. var tokentype = code === 42 ? types.star : types.modulo;
  3997. // exponentiation operator ** and **=
  3998. if (this.options.ecmaVersion >= 7 && next === 42) {
  3999. ++size;
  4000. tokentype = types.starstar;
  4001. next = this.input.charCodeAt(this.pos + 2);
  4002. }
  4003. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  4004. return this.finishOp(tokentype, size)
  4005. };
  4006. pp$8.readToken_pipe_amp = function(code) { // '|&'
  4007. var next = this.input.charCodeAt(this.pos + 1);
  4008. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  4009. if (next === 61) { return this.finishOp(types.assign, 2) }
  4010. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  4011. };
  4012. pp$8.readToken_caret = function() { // '^'
  4013. var next = this.input.charCodeAt(this.pos + 1);
  4014. if (next === 61) { return this.finishOp(types.assign, 2) }
  4015. return this.finishOp(types.bitwiseXOR, 1)
  4016. };
  4017. pp$8.readToken_plus_min = function(code) { // '+-'
  4018. var next = this.input.charCodeAt(this.pos + 1);
  4019. if (next === code) {
  4020. if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
  4021. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4022. // A `-->` line comment
  4023. this.skipLineComment(3);
  4024. this.skipSpace();
  4025. return this.nextToken()
  4026. }
  4027. return this.finishOp(types.incDec, 2)
  4028. }
  4029. if (next === 61) { return this.finishOp(types.assign, 2) }
  4030. return this.finishOp(types.plusMin, 1)
  4031. };
  4032. pp$8.readToken_lt_gt = function(code) { // '<>'
  4033. var next = this.input.charCodeAt(this.pos + 1);
  4034. var size = 1;
  4035. if (next === code) {
  4036. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4037. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  4038. return this.finishOp(types.bitShift, size)
  4039. }
  4040. if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
  4041. this.input.charCodeAt(this.pos + 3) == 45) {
  4042. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4043. this.skipLineComment(4);
  4044. this.skipSpace();
  4045. return this.nextToken()
  4046. }
  4047. if (next === 61) { size = 2; }
  4048. return this.finishOp(types.relational, size)
  4049. };
  4050. pp$8.readToken_eq_excl = function(code) { // '=!'
  4051. var next = this.input.charCodeAt(this.pos + 1);
  4052. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  4053. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  4054. this.pos += 2;
  4055. return this.finishToken(types.arrow)
  4056. }
  4057. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  4058. };
  4059. pp$8.getTokenFromCode = function(code) {
  4060. switch (code) {
  4061. // The interpretation of a dot depends on whether it is followed
  4062. // by a digit or another two dots.
  4063. case 46: // '.'
  4064. return this.readToken_dot()
  4065. // Punctuation tokens.
  4066. case 40: ++this.pos; return this.finishToken(types.parenL)
  4067. case 41: ++this.pos; return this.finishToken(types.parenR)
  4068. case 59: ++this.pos; return this.finishToken(types.semi)
  4069. case 44: ++this.pos; return this.finishToken(types.comma)
  4070. case 91: ++this.pos; return this.finishToken(types.bracketL)
  4071. case 93: ++this.pos; return this.finishToken(types.bracketR)
  4072. case 123: ++this.pos; return this.finishToken(types.braceL)
  4073. case 125: ++this.pos; return this.finishToken(types.braceR)
  4074. case 58: ++this.pos; return this.finishToken(types.colon)
  4075. case 63: ++this.pos; return this.finishToken(types.question)
  4076. case 96: // '`'
  4077. if (this.options.ecmaVersion < 6) { break }
  4078. ++this.pos;
  4079. return this.finishToken(types.backQuote)
  4080. case 48: // '0'
  4081. var next = this.input.charCodeAt(this.pos + 1);
  4082. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  4083. if (this.options.ecmaVersion >= 6) {
  4084. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  4085. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  4086. }
  4087. // Anything else beginning with a digit is an integer, octal
  4088. // number, or float.
  4089. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  4090. return this.readNumber(false)
  4091. // Quotes produce strings.
  4092. case 34: case 39: // '"', "'"
  4093. return this.readString(code)
  4094. // Operators are parsed inline in tiny state machines. '=' (61) is
  4095. // often referred to. `finishOp` simply skips the amount of
  4096. // characters it is given as second argument, and returns a token
  4097. // of the type given by its first argument.
  4098. case 47: // '/'
  4099. return this.readToken_slash()
  4100. case 37: case 42: // '%*'
  4101. return this.readToken_mult_modulo_exp(code)
  4102. case 124: case 38: // '|&'
  4103. return this.readToken_pipe_amp(code)
  4104. case 94: // '^'
  4105. return this.readToken_caret()
  4106. case 43: case 45: // '+-'
  4107. return this.readToken_plus_min(code)
  4108. case 60: case 62: // '<>'
  4109. return this.readToken_lt_gt(code)
  4110. case 61: case 33: // '=!'
  4111. return this.readToken_eq_excl(code)
  4112. case 126: // '~'
  4113. return this.finishOp(types.prefix, 1)
  4114. }
  4115. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4116. };
  4117. pp$8.finishOp = function(type, size) {
  4118. var str = this.input.slice(this.pos, this.pos + size);
  4119. this.pos += size;
  4120. return this.finishToken(type, str)
  4121. };
  4122. // Parse a regular expression. Some context-awareness is necessary,
  4123. // since a '/' inside a '[]' set does not end the expression.
  4124. function tryCreateRegexp(src, flags, throwErrorAt, parser) {
  4125. try {
  4126. return new RegExp(src, flags)
  4127. } catch (e) {
  4128. if (throwErrorAt !== undefined) {
  4129. if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
  4130. throw e
  4131. }
  4132. }
  4133. }
  4134. var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
  4135. pp$8.readRegexp = function() {
  4136. var this$1 = this;
  4137. var escaped, inClass, start = this.pos;
  4138. for (;;) {
  4139. if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
  4140. var ch = this$1.input.charAt(this$1.pos);
  4141. if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
  4142. if (!escaped) {
  4143. if (ch === "[") { inClass = true; }
  4144. else if (ch === "]" && inClass) { inClass = false; }
  4145. else if (ch === "/" && !inClass) { break }
  4146. escaped = ch === "\\";
  4147. } else { escaped = false; }
  4148. ++this$1.pos;
  4149. }
  4150. var content = this.input.slice(start, this.pos);
  4151. ++this.pos;
  4152. // Need to use `readWord1` because '\uXXXX' sequences are allowed
  4153. // here (don't ask).
  4154. var mods = this.readWord1();
  4155. var tmp = content, tmpFlags = "";
  4156. if (mods) {
  4157. var validFlags = /^[gim]*$/;
  4158. if (this.options.ecmaVersion >= 6) { validFlags = /^[gimuy]*$/; }
  4159. if (!validFlags.test(mods)) { this.raise(start, "Invalid regular expression flag"); }
  4160. if (mods.indexOf("u") >= 0) {
  4161. if (regexpUnicodeSupport) {
  4162. tmpFlags = "u";
  4163. } else {
  4164. // Replace each astral symbol and every Unicode escape sequence that
  4165. // possibly represents an astral symbol or a paired surrogate with a
  4166. // single ASCII symbol to avoid throwing on regular expressions that
  4167. // are only valid in combination with the `/u` flag.
  4168. // Note: replacing with the ASCII symbol `x` might cause false
  4169. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  4170. // perfectly valid pattern that is equivalent to `[a-b]`, but it would
  4171. // be replaced by `[x-b]` which throws an error.
  4172. tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
  4173. code = Number("0x" + code);
  4174. if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
  4175. return "x"
  4176. });
  4177. tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
  4178. tmpFlags = tmpFlags.replace("u", "");
  4179. }
  4180. }
  4181. }
  4182. // Detect invalid regular expressions.
  4183. var value = null;
  4184. // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
  4185. // so don't do detection if we are running under Rhino
  4186. if (!isRhino) {
  4187. tryCreateRegexp(tmp, tmpFlags, start, this);
  4188. // Get a regular expression object for this pattern-flag pair, or `null` in
  4189. // case the current environment doesn't support the flags it uses.
  4190. value = tryCreateRegexp(content, mods);
  4191. }
  4192. return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
  4193. };
  4194. // Read an integer in the given radix. Return null if zero digits
  4195. // were read, the integer value otherwise. When `len` is given, this
  4196. // will return `null` unless the integer has exactly `len` digits.
  4197. pp$8.readInt = function(radix, len) {
  4198. var this$1 = this;
  4199. var start = this.pos, total = 0;
  4200. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  4201. var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
  4202. if (code >= 97) { val = code - 97 + 10; } // a
  4203. else if (code >= 65) { val = code - 65 + 10; } // A
  4204. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4205. else { val = Infinity; }
  4206. if (val >= radix) { break }
  4207. ++this$1.pos;
  4208. total = total * radix + val;
  4209. }
  4210. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4211. return total
  4212. };
  4213. pp$8.readRadixNumber = function(radix) {
  4214. this.pos += 2; // 0x
  4215. var val = this.readInt(radix);
  4216. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4217. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4218. return this.finishToken(types.num, val)
  4219. };
  4220. // Read an integer, octal integer, or floating-point number.
  4221. pp$8.readNumber = function(startsWithDot) {
  4222. var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
  4223. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4224. if (octal && this.pos == start + 1) { octal = false; }
  4225. var next = this.input.charCodeAt(this.pos);
  4226. if (next === 46 && !octal) { // '.'
  4227. ++this.pos;
  4228. this.readInt(10);
  4229. isFloat = true;
  4230. next = this.input.charCodeAt(this.pos);
  4231. }
  4232. if ((next === 69 || next === 101) && !octal) { // 'eE'
  4233. next = this.input.charCodeAt(++this.pos);
  4234. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  4235. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4236. isFloat = true;
  4237. }
  4238. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4239. var str = this.input.slice(start, this.pos), val;
  4240. if (isFloat) { val = parseFloat(str); }
  4241. else if (!octal || str.length === 1) { val = parseInt(str, 10); }
  4242. else if (this.strict) { this.raise(start, "Invalid number"); }
  4243. else if (/[89]/.test(str)) { val = parseInt(str, 10); }
  4244. else { val = parseInt(str, 8); }
  4245. return this.finishToken(types.num, val)
  4246. };
  4247. // Read a string value, interpreting backslash-escapes.
  4248. pp$8.readCodePoint = function() {
  4249. var ch = this.input.charCodeAt(this.pos), code;
  4250. if (ch === 123) { // '{'
  4251. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  4252. var codePos = ++this.pos;
  4253. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  4254. ++this.pos;
  4255. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  4256. } else {
  4257. code = this.readHexChar(4);
  4258. }
  4259. return code
  4260. };
  4261. function codePointToString(code) {
  4262. // UTF-16 Decoding
  4263. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  4264. code -= 0x10000;
  4265. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  4266. }
  4267. pp$8.readString = function(quote) {
  4268. var this$1 = this;
  4269. var out = "", chunkStart = ++this.pos;
  4270. for (;;) {
  4271. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4272. var ch = this$1.input.charCodeAt(this$1.pos);
  4273. if (ch === quote) { break }
  4274. if (ch === 92) { // '\'
  4275. out += this$1.input.slice(chunkStart, this$1.pos);
  4276. out += this$1.readEscapedChar(false);
  4277. chunkStart = this$1.pos;
  4278. } else {
  4279. if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4280. ++this$1.pos;
  4281. }
  4282. }
  4283. out += this.input.slice(chunkStart, this.pos++);
  4284. return this.finishToken(types.string, out)
  4285. };
  4286. // Reads template string tokens.
  4287. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  4288. pp$8.tryReadTemplateToken = function() {
  4289. this.inTemplateElement = true;
  4290. try {
  4291. this.readTmplToken();
  4292. } catch (err) {
  4293. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  4294. this.readInvalidTemplateToken();
  4295. } else {
  4296. throw err
  4297. }
  4298. }
  4299. this.inTemplateElement = false;
  4300. };
  4301. pp$8.invalidStringToken = function(position, message) {
  4302. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  4303. throw INVALID_TEMPLATE_ESCAPE_ERROR
  4304. } else {
  4305. this.raise(position, message);
  4306. }
  4307. };
  4308. pp$8.readTmplToken = function() {
  4309. var this$1 = this;
  4310. var out = "", chunkStart = this.pos;
  4311. for (;;) {
  4312. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
  4313. var ch = this$1.input.charCodeAt(this$1.pos);
  4314. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  4315. if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
  4316. if (ch === 36) {
  4317. this$1.pos += 2;
  4318. return this$1.finishToken(types.dollarBraceL)
  4319. } else {
  4320. ++this$1.pos;
  4321. return this$1.finishToken(types.backQuote)
  4322. }
  4323. }
  4324. out += this$1.input.slice(chunkStart, this$1.pos);
  4325. return this$1.finishToken(types.template, out)
  4326. }
  4327. if (ch === 92) { // '\'
  4328. out += this$1.input.slice(chunkStart, this$1.pos);
  4329. out += this$1.readEscapedChar(true);
  4330. chunkStart = this$1.pos;
  4331. } else if (isNewLine(ch)) {
  4332. out += this$1.input.slice(chunkStart, this$1.pos);
  4333. ++this$1.pos;
  4334. switch (ch) {
  4335. case 13:
  4336. if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
  4337. case 10:
  4338. out += "\n";
  4339. break
  4340. default:
  4341. out += String.fromCharCode(ch);
  4342. break
  4343. }
  4344. if (this$1.options.locations) {
  4345. ++this$1.curLine;
  4346. this$1.lineStart = this$1.pos;
  4347. }
  4348. chunkStart = this$1.pos;
  4349. } else {
  4350. ++this$1.pos;
  4351. }
  4352. }
  4353. };
  4354. // Reads a template token to search for the end, without validating any escape sequences
  4355. pp$8.readInvalidTemplateToken = function() {
  4356. var this$1 = this;
  4357. for (; this.pos < this.input.length; this.pos++) {
  4358. switch (this$1.input[this$1.pos]) {
  4359. case "\\":
  4360. ++this$1.pos;
  4361. break
  4362. case "$":
  4363. if (this$1.input[this$1.pos + 1] !== "{") {
  4364. break
  4365. }
  4366. // falls through
  4367. case "`":
  4368. return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
  4369. // no default
  4370. }
  4371. }
  4372. this.raise(this.start, "Unterminated template");
  4373. };
  4374. // Used to read escaped characters
  4375. pp$8.readEscapedChar = function(inTemplate) {
  4376. var ch = this.input.charCodeAt(++this.pos);
  4377. ++this.pos;
  4378. switch (ch) {
  4379. case 110: return "\n" // 'n' -> '\n'
  4380. case 114: return "\r" // 'r' -> '\r'
  4381. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  4382. case 117: return codePointToString(this.readCodePoint()) // 'u'
  4383. case 116: return "\t" // 't' -> '\t'
  4384. case 98: return "\b" // 'b' -> '\b'
  4385. case 118: return "\u000b" // 'v' -> '\u000b'
  4386. case 102: return "\f" // 'f' -> '\f'
  4387. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  4388. case 10: // ' \n'
  4389. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  4390. return ""
  4391. default:
  4392. if (ch >= 48 && ch <= 55) {
  4393. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4394. var octal = parseInt(octalStr, 8);
  4395. if (octal > 255) {
  4396. octalStr = octalStr.slice(0, -1);
  4397. octal = parseInt(octalStr, 8);
  4398. }
  4399. if (octalStr !== "0" && (this.strict || inTemplate)) {
  4400. this.invalidStringToken(this.pos - 2, "Octal literal in strict mode");
  4401. }
  4402. this.pos += octalStr.length - 1;
  4403. return String.fromCharCode(octal)
  4404. }
  4405. return String.fromCharCode(ch)
  4406. }
  4407. };
  4408. // Used to read character escape sequences ('\x', '\u', '\U').
  4409. pp$8.readHexChar = function(len) {
  4410. var codePos = this.pos;
  4411. var n = this.readInt(16, len);
  4412. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4413. return n
  4414. };
  4415. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4416. // to whether the word contained a '\u' escape.
  4417. //
  4418. // Incrementally adds only escaped chars, adding other chunks as-is
  4419. // as a micro-optimization.
  4420. pp$8.readWord1 = function() {
  4421. var this$1 = this;
  4422. this.containsEsc = false;
  4423. var word = "", first = true, chunkStart = this.pos;
  4424. var astral = this.options.ecmaVersion >= 6;
  4425. while (this.pos < this.input.length) {
  4426. var ch = this$1.fullCharCodeAtPos();
  4427. if (isIdentifierChar(ch, astral)) {
  4428. this$1.pos += ch <= 0xffff ? 1 : 2;
  4429. } else if (ch === 92) { // "\"
  4430. this$1.containsEsc = true;
  4431. word += this$1.input.slice(chunkStart, this$1.pos);
  4432. var escStart = this$1.pos;
  4433. if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
  4434. { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4435. ++this$1.pos;
  4436. var esc = this$1.readCodePoint();
  4437. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4438. { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4439. word += codePointToString(esc);
  4440. chunkStart = this$1.pos;
  4441. } else {
  4442. break
  4443. }
  4444. first = false;
  4445. }
  4446. return word + this.input.slice(chunkStart, this.pos)
  4447. };
  4448. // Read an identifier or keyword token. Will check for reserved
  4449. // words when necessary.
  4450. pp$8.readWord = function() {
  4451. var word = this.readWord1();
  4452. var type = types.name;
  4453. if (this.keywords.test(word)) {
  4454. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  4455. type = keywords$1[word];
  4456. }
  4457. return this.finishToken(type, word)
  4458. };
  4459. // The main exported interface (under `self.acorn` when in the
  4460. // browser) is a `parse` function that takes a code string and
  4461. // returns an abstract syntax tree as specified by [Mozilla parser
  4462. // API][api].
  4463. //
  4464. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4465. function parse(input, options) {
  4466. return new Parser(options, input).parse()
  4467. }
  4468. function getLocator$1(source, options) {
  4469. if (options === void 0) { options = {}; }
  4470. var offsetLine = options.offsetLine || 0;
  4471. var offsetColumn = options.offsetColumn || 0;
  4472. var originalLines = source.split('\n');
  4473. var start = 0;
  4474. var lineRanges = originalLines.map(function (line, i) {
  4475. var end = start + line.length + 1;
  4476. var range = { start: start, end: end, line: i };
  4477. start = end;
  4478. return range;
  4479. });
  4480. var i = 0;
  4481. function rangeContains(range, index) {
  4482. return range.start <= index && index < range.end;
  4483. }
  4484. function getLocation(range, index) {
  4485. return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
  4486. }
  4487. function locate(search, startIndex) {
  4488. if (typeof search === 'string') {
  4489. search = source.indexOf(search, startIndex || 0);
  4490. }
  4491. var range = lineRanges[i];
  4492. var d = search >= range.end ? 1 : -1;
  4493. while (range) {
  4494. if (rangeContains(range, search))
  4495. return getLocation(range, search);
  4496. i += d;
  4497. range = lineRanges[i];
  4498. }
  4499. }
  4500. return locate;
  4501. }
  4502. function locate(source, search, options) {
  4503. if (typeof options === 'number') {
  4504. throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');
  4505. }
  4506. return getLocator$1(source, options)(search, options && options.startIndex);
  4507. }
  4508. const reservedWords$1 = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' );
  4509. const builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split( ' ' );
  4510. const blacklisted = blank();
  4511. reservedWords$1.concat( builtins ).forEach( word => blacklisted[ word ] = true );
  4512. const illegalCharacters = /[^$_a-zA-Z0-9]/g;
  4513. const startsWithDigit = str => /\d/.test( str[0] );
  4514. function isLegal ( str ) {
  4515. if ( startsWithDigit(str) || blacklisted[ str ] ) {
  4516. return false;
  4517. }
  4518. if ( illegalCharacters.test(str) ) {
  4519. return false;
  4520. }
  4521. return true;
  4522. }
  4523. function makeLegal ( str ) {
  4524. str = str
  4525. .replace( /-(\w)/g, ( _, letter ) => letter.toUpperCase() )
  4526. .replace( illegalCharacters, '_' );
  4527. if ( startsWithDigit(str) || blacklisted[ str ] ) { str = `_${str}`; }
  4528. return str;
  4529. }
  4530. function spaces ( i ) {
  4531. let result = '';
  4532. while ( i-- ) { result += ' '; }
  4533. return result;
  4534. }
  4535. function tabsToSpaces ( str ) {
  4536. return str.replace( /^\t+/, match => match.split( '\t' ).join( ' ' ) );
  4537. }
  4538. function getCodeFrame ( source, line, column ) {
  4539. let lines = source.split( '\n' );
  4540. const frameStart = Math.max( 0, line - 3 );
  4541. let frameEnd = Math.min( line + 2, lines.length );
  4542. lines = lines.slice( frameStart, frameEnd );
  4543. while ( !/\S/.test( lines[ lines.length - 1 ] ) ) {
  4544. lines.pop();
  4545. frameEnd -= 1;
  4546. }
  4547. const digits = String( frameEnd ).length;
  4548. return lines
  4549. .map( ( str, i ) => {
  4550. const isErrorLine = frameStart + i + 1 === line;
  4551. let lineNum = String( i + frameStart + 1 );
  4552. while ( lineNum.length < digits ) { lineNum = ` ${lineNum}`; }
  4553. if ( isErrorLine ) {
  4554. const indicator = spaces( digits + 2 + tabsToSpaces( str.slice( 0, column ) ).length ) + '^';
  4555. return `${lineNum}: ${tabsToSpaces( str )}\n${indicator}`;
  4556. }
  4557. return `${lineNum}: ${tabsToSpaces( str )}`;
  4558. })
  4559. .join( '\n' );
  4560. }
  4561. function relativeId ( id ) {
  4562. if ( typeof process === 'undefined' || !isAbsolute( id ) ) { return id; }
  4563. return relative( process.cwd(), id );
  4564. }
  4565. class Variable {
  4566. constructor ( name ) {
  4567. this.name = name;
  4568. }
  4569. addCall () {}
  4570. getName () {
  4571. return this.name;
  4572. }
  4573. hasEffectsWhenCalled () {
  4574. return true;
  4575. }
  4576. hasEffectsWhenMutated () {
  4577. return true;
  4578. }
  4579. includeVariable () {
  4580. if ( this.included ) {
  4581. return false;
  4582. }
  4583. this.included = true;
  4584. return true;
  4585. }
  4586. }
  4587. class NamespaceVariable extends Variable {
  4588. constructor ( module ) {
  4589. super( module.basename() );
  4590. this.isNamespace = true;
  4591. this.module = module;
  4592. this.needsNamespaceBlock = false;
  4593. this.originals = blank();
  4594. module.getExports().concat( module.getReexports() ).forEach( name => {
  4595. this.originals[ name ] = module.traceExport( name );
  4596. } );
  4597. }
  4598. addReference ( node ) {
  4599. this.name = node.name;
  4600. }
  4601. assignExpression () {}
  4602. includeVariable () {
  4603. const hasBeenIncluded = super.includeVariable();
  4604. if ( hasBeenIncluded ) {
  4605. this.needsNamespaceBlock = true;
  4606. forOwn( this.originals, original => original.includeVariable() );
  4607. }
  4608. return hasBeenIncluded;
  4609. }
  4610. renderBlock ( es, legacy, indentString ) {
  4611. const members = keys( this.originals ).map( name => {
  4612. const original = this.originals[ name ];
  4613. if ( original.isReassigned && !legacy ) {
  4614. return `${indentString}get ${name} () { return ${original.getName( es )}; }`;
  4615. }
  4616. if ( legacy && ~reservedWords$1.indexOf( name ) ) { name = `'${name}'`; }
  4617. return `${indentString}${name}: ${original.getName( es )}`;
  4618. } );
  4619. const callee = legacy ? `(Object.freeze || Object)` : `Object.freeze`;
  4620. return `${this.module.bundle.varOrConst} ${this.getName( es )} = ${callee}({\n${members.join( ',\n' )}\n});\n\n`;
  4621. }
  4622. }
  4623. function extractNames ( param ) {
  4624. const names = [];
  4625. extractors[ param.type ]( names, param );
  4626. return names;
  4627. }
  4628. const extractors = {
  4629. Identifier ( names, param ) {
  4630. names.push( param.name );
  4631. },
  4632. ObjectPattern ( names, param ) {
  4633. param.properties.forEach( prop => {
  4634. extractors[ prop.value.type ]( names, prop.value );
  4635. });
  4636. },
  4637. ArrayPattern ( names, param ) {
  4638. param.elements.forEach( element => {
  4639. if ( element ) { extractors[ element.type ]( names, element ); }
  4640. });
  4641. },
  4642. RestElement ( names, param ) {
  4643. extractors[ param.argument.type ]( names, param.argument );
  4644. },
  4645. AssignmentPattern ( names, param ) {
  4646. extractors[ param.left.type ]( names, param.left );
  4647. }
  4648. };
  4649. const UNKNOWN_VALUE = { toString: () => '[[UNKNOWN]]' };
  4650. const UNKNOWN_ASSIGNMENT = {
  4651. type: 'UNKNOWN',
  4652. bindCall: () => {},
  4653. hasEffectsWhenCalled: () => true,
  4654. hasEffectsWhenMutated: () => true,
  4655. };
  4656. const UNDEFINED_ASSIGNMENT = {
  4657. type: 'UNDEFINED',
  4658. bindCall: () => {},
  4659. hasEffectsWhenCalled: () => true,
  4660. hasEffectsWhenMutated: () => true,
  4661. };
  4662. const UNKNOWN_OBJECT_LITERAL = {
  4663. type: 'UNKNOWN_OBJECT_LITERAL',
  4664. bindCall: () => {},
  4665. hasEffectsWhenCalled: () => true,
  4666. hasEffectsWhenMutated: () => false,
  4667. };
  4668. const OPTION_IGNORE_BREAK_STATEMENTS = 'IGNORE_BREAK_STATEMENTS';
  4669. const OPTION_IGNORE_RETURN_AWAIT_YIELD = 'IGNORE_RETURN_AWAIT_YIELD';
  4670. const OPTION_IGNORE_SAFE_THIS_MUTATIONS = 'IGNORE_SAFE_THIS_MUTATIONS';
  4671. const OPTION_CALLED_NODES = 'CALLED_NODES';
  4672. const OPTION_MUTATED_NODES = 'MUTATED_NODES';
  4673. const IGNORED_LABELS = 'IGNORED_LABELS';
  4674. /** Wrapper to ensure immutability */
  4675. class ExecutionPathOptions {
  4676. /**
  4677. * @returns {ExecutionPathOptions}
  4678. */
  4679. static create () {
  4680. return new this( {} );
  4681. }
  4682. constructor ( optionValues ) {
  4683. this._optionValues = optionValues;
  4684. }
  4685. /**
  4686. * Returns a new ExecutionPathOptions instance with the given option set to a new value.
  4687. * Does not mutate the current instance. Also works in sub-classes.
  4688. * @param {string} option - The name of an option
  4689. * @param {*} value - The new value of the option
  4690. * @returns {ExecutionPathOptions} A new options instance
  4691. */
  4692. set ( option, value ) {
  4693. return new this.constructor( Object.assign( {}, this._optionValues, { [option]: value } ) );
  4694. }
  4695. /**
  4696. * @param {string} option - The name of an option
  4697. * @returns {*} Its value
  4698. */
  4699. get ( option ) {
  4700. return this._optionValues[ option ];
  4701. }
  4702. /**
  4703. * @return {boolean}
  4704. */
  4705. ignoreBreakStatements () {
  4706. return this.get( OPTION_IGNORE_BREAK_STATEMENTS );
  4707. }
  4708. /**
  4709. * @param {boolean} [value=true]
  4710. * @return {ExecutionPathOptions}
  4711. */
  4712. setIgnoreBreakStatements ( value ) {
  4713. if ( value === void 0 ) value = true;
  4714. return this.set( OPTION_IGNORE_BREAK_STATEMENTS, value );
  4715. }
  4716. /**
  4717. * @param {string} labelName
  4718. * @return {boolean}
  4719. */
  4720. ignoreLabel ( labelName ) {
  4721. const ignoredLabels = this.get( IGNORED_LABELS );
  4722. return ignoredLabels && ignoredLabels.has( labelName );
  4723. }
  4724. /**
  4725. * @param {string} labelName
  4726. * @return {ExecutionPathOptions}
  4727. */
  4728. setIgnoreLabel ( labelName ) {
  4729. return this.set( IGNORED_LABELS, new Set( this.get( IGNORED_LABELS ) ).add( labelName ) );
  4730. }
  4731. /**
  4732. * @return {ExecutionPathOptions}
  4733. */
  4734. setIgnoreNoLabels () {
  4735. return this.set( IGNORED_LABELS, null );
  4736. }
  4737. /**
  4738. * @return {boolean}
  4739. */
  4740. ignoreReturnAwaitYield () {
  4741. return this.get( OPTION_IGNORE_RETURN_AWAIT_YIELD );
  4742. }
  4743. /**
  4744. * @param {boolean} [value=true]
  4745. * @return {ExecutionPathOptions}
  4746. */
  4747. setIgnoreReturnAwaitYield ( value ) {
  4748. if ( value === void 0 ) value = true;
  4749. return this.set( OPTION_IGNORE_RETURN_AWAIT_YIELD, value );
  4750. }
  4751. /**
  4752. * @return {boolean}
  4753. */
  4754. ignoreSafeThisMutations () {
  4755. return this.get( OPTION_IGNORE_SAFE_THIS_MUTATIONS );
  4756. }
  4757. /**
  4758. * @param {boolean} [value=true]
  4759. * @return {ExecutionPathOptions}
  4760. */
  4761. setIgnoreSafeThisMutations ( value ) {
  4762. if ( value === void 0 ) value = true;
  4763. return this.set( OPTION_IGNORE_SAFE_THIS_MUTATIONS, value );
  4764. }
  4765. /**
  4766. * @param {Node} node
  4767. * @return {ExecutionPathOptions}
  4768. */
  4769. addMutatedNode ( node ) {
  4770. return this.set( OPTION_MUTATED_NODES, new Set( this.get( OPTION_MUTATED_NODES ) ).add( node ) );
  4771. }
  4772. /**
  4773. * @param {Node} node
  4774. * @return {boolean}
  4775. */
  4776. hasNodeBeenMutated ( node ) {
  4777. const mutatedNodes = this.get( OPTION_MUTATED_NODES );
  4778. return mutatedNodes && mutatedNodes.has( node );
  4779. }
  4780. /**
  4781. * @param {Node} node
  4782. * @return {ExecutionPathOptions}
  4783. */
  4784. addCalledNode ( node ) {
  4785. return this.set( OPTION_CALLED_NODES, new Set( this.get( OPTION_CALLED_NODES ) ).add( node ) );
  4786. }
  4787. /**
  4788. * @param {Node} node
  4789. * @return {boolean}
  4790. */
  4791. hasNodeBeenCalled ( node ) {
  4792. const calledNodes = this.get( OPTION_CALLED_NODES );
  4793. return calledNodes && calledNodes.has( node );
  4794. }
  4795. /**
  4796. * @param {Node} calledNode
  4797. * @return {ExecutionPathOptions}
  4798. */
  4799. getHasEffectsWhenCalledOptions ( calledNode ) {
  4800. return this
  4801. .addCalledNode( calledNode )
  4802. .setIgnoreReturnAwaitYield()
  4803. .setIgnoreBreakStatements( false )
  4804. .setIgnoreNoLabels();
  4805. }
  4806. }
  4807. class Node$1 {
  4808. /**
  4809. * Called once all nodes have been initialised and the scopes have been populated.
  4810. * Use this to bind assignments and calls to variables.
  4811. */
  4812. bind () {
  4813. this.eachChild( child => child.bind() );
  4814. }
  4815. /**
  4816. * Bind an expression as an assignment to a node.
  4817. * The default noop implementation is ok as long as hasEffectsWhenAssigned
  4818. * always returns true for this node. Otherwise it should be overridden.
  4819. * @param {Node} expression
  4820. */
  4821. bindAssignment () {}
  4822. /**
  4823. * Binds ways a node is called to a node. Current options are:
  4824. * - withNew: boolean - Did this call use the "new" operator
  4825. * The default noop implementation is ok as long as hasEffectsWhenCalled
  4826. * always returns true for this node. Otherwise it should be overridden.
  4827. * @param callOptions
  4828. */
  4829. bindCall () {}
  4830. eachChild ( callback ) {
  4831. this.keys.forEach( key => {
  4832. const value = this[ key ];
  4833. if ( !value ) { return; }
  4834. if ( Array.isArray( value ) ) {
  4835. value.forEach( child => child && callback( child ) );
  4836. } else {
  4837. callback( value );
  4838. }
  4839. } );
  4840. }
  4841. getValue () {
  4842. return UNKNOWN_VALUE;
  4843. }
  4844. /**
  4845. * Determine if this Node would have an effect on the bundle.
  4846. * This is usually true for already included nodes. Exceptions are e.g. break statements
  4847. * which only have an effect if their surrounding loop or switch statement is included.
  4848. * The options pass on information like this about the current execution path.
  4849. * @param {ExecutionPathOptions} options
  4850. * @return {boolean}
  4851. */
  4852. hasEffects ( options ) {
  4853. return this.included || this.someChild( child => child.hasEffects( options ) );
  4854. }
  4855. /**
  4856. * Special make-shift logic to treat cases where apparently side-effect free statements
  4857. * are executed for side-effects. The most important case are getters with side-effects.
  4858. * Once we can reliably handle this case in member expressions, this function should
  4859. * probably be removed again.
  4860. * @param {ExecutionPathOptions} options
  4861. * @return {boolean}
  4862. */
  4863. hasEffectsAsExpressionStatement () {
  4864. return true;
  4865. }
  4866. /**
  4867. * @param {ExecutionPathOptions} options
  4868. * @return {boolean}
  4869. */
  4870. hasEffectsWhenAssigned () {
  4871. return true;
  4872. }
  4873. /**
  4874. * @param {ExecutionPathOptions} options
  4875. * @return {boolean}
  4876. */
  4877. hasEffectsWhenCalled () {
  4878. return true;
  4879. }
  4880. /**
  4881. * @param {ExecutionPathOptions} options
  4882. * @return {boolean}
  4883. */
  4884. hasEffectsWhenMutated () {
  4885. return true;
  4886. }
  4887. /**
  4888. * Includes the node in the bundle. Children are usually included if they are
  4889. * necessary for this node (e.g. a function body) or if they have effects.
  4890. * Necessary variables should be included as well. Should return true if any
  4891. * nodes or variables have been added that were missing before.
  4892. * @return {boolean}
  4893. */
  4894. includeInBundle () {
  4895. if ( this.isFullyIncluded() ) { return false; }
  4896. let addedNewNodes = false;
  4897. this.eachChild( childNode => {
  4898. if ( childNode.includeInBundle() ) {
  4899. addedNewNodes = true;
  4900. }
  4901. } );
  4902. if ( this.included && !addedNewNodes ) {
  4903. return false;
  4904. }
  4905. this.included = true;
  4906. return true;
  4907. }
  4908. /**
  4909. * Alternative version of includeInBundle to override the default behaviour of
  4910. * declarations to only include nodes for declarators that have an effect. Necessary
  4911. * for for-loops that do not use a declared loop variable.
  4912. * @return {boolean}
  4913. */
  4914. includeWithAllDeclarations () {
  4915. return this.includeInBundle();
  4916. }
  4917. /**
  4918. * Assign a scope to this node and make sure all children have the right scopes.
  4919. * Perform any additional initialisation that does not depend on the scope being
  4920. * populated with variables.
  4921. * Usually one should not override this function but override initialiseScope,
  4922. * initialiseNode and/or initialiseChildren instead. BlockScopes have a special
  4923. * alternative initialisation initialiseAndReplaceScope.
  4924. * @param {Scope} parentScope
  4925. */
  4926. initialise ( parentScope ) {
  4927. this.initialiseScope( parentScope );
  4928. this.initialiseNode( parentScope );
  4929. this.initialiseChildren( parentScope );
  4930. }
  4931. /**
  4932. * Override to change how and with what scopes children are initialised
  4933. * @param {Scope} parentScope
  4934. */
  4935. initialiseChildren () {
  4936. this.eachChild( child => child.initialise( this.scope ) );
  4937. }
  4938. /**
  4939. * Override to perform special initialisation steps after the scope is initialised
  4940. * @param {Scope} parentScope
  4941. */
  4942. initialiseNode () {}
  4943. /**
  4944. * Override if this scope should receive a different scope than the parent scope.
  4945. * @param {Scope} parentScope
  4946. */
  4947. initialiseScope ( parentScope ) {
  4948. this.scope = parentScope;
  4949. }
  4950. insertSemicolon ( code ) {
  4951. if ( code.original[ this.end - 1 ] !== ';' ) {
  4952. code.appendLeft( this.end, ';' );
  4953. }
  4954. }
  4955. /**
  4956. * Shortcut to skip checking this node for effects when all children have already
  4957. * been included.
  4958. * @param {Scope} parentScope
  4959. */
  4960. isFullyIncluded () {
  4961. if ( this._fullyIncluded ) {
  4962. return true;
  4963. }
  4964. this._fullyIncluded = this.included && !this.someChild( child => !child.isFullyIncluded() );
  4965. }
  4966. locate () {
  4967. // useful for debugging
  4968. const location = locate( this.module.code, this.start, { offsetLine: 1 } );
  4969. location.file = this.module.id;
  4970. location.toString = () => JSON.stringify( location );
  4971. return location;
  4972. }
  4973. render ( code, es ) {
  4974. this.eachChild( child => child.render( code, es ) );
  4975. }
  4976. /**
  4977. * Start a new execution path to determine if this node has an effect on the bundle and
  4978. * should therefore be included. Unless they are fully included, included nodes should
  4979. * always be included again in subsequent visits as the inclusion of additional variables
  4980. * may require the inclusion of more child nodes in e.g. block statements.
  4981. * @return {boolean}
  4982. */
  4983. shouldBeIncluded () {
  4984. return this.hasEffects( ExecutionPathOptions.create() );
  4985. }
  4986. someChild ( callback ) {
  4987. return this.keys.some( key => {
  4988. const value = this[ key ];
  4989. if ( !value ) { return false; }
  4990. if ( Array.isArray( value ) ) {
  4991. return value.some( child => child && callback( child ) );
  4992. }
  4993. return callback( value );
  4994. } );
  4995. }
  4996. toString () {
  4997. return this.module.code.slice( this.start, this.end );
  4998. }
  4999. }
  5000. class ArrayPattern extends Node$1 {
  5001. bindAssignment () {
  5002. this.eachChild( child => child.bindAssignment( UNKNOWN_ASSIGNMENT ) );
  5003. }
  5004. hasEffectsWhenAssigned ( options ) {
  5005. return this.someChild( child => child.hasEffectsWhenAssigned( options ) );
  5006. }
  5007. initialiseAndDeclare ( parentScope, kind ) {
  5008. this.initialiseScope( parentScope );
  5009. this.eachChild( child => child.initialiseAndDeclare( parentScope, kind, UNKNOWN_ASSIGNMENT ) );
  5010. }
  5011. }
  5012. class LocalVariable extends Variable {
  5013. constructor ( name, declarator, init ) {
  5014. super( name );
  5015. this.isReassigned = false;
  5016. this.exportName = null;
  5017. this.declarations = new Set( declarator ? [ declarator ] : null );
  5018. this.assignedExpressions = new Set( init ? [ init ] : null );
  5019. this.calls = new Set();
  5020. }
  5021. addDeclaration ( identifier ) {
  5022. this.declarations.add( identifier );
  5023. }
  5024. addCall ( callOptions ) {
  5025. // To prevent infinite loops
  5026. if ( this.calls.has( callOptions ) ) { return; }
  5027. this.calls.add( callOptions );
  5028. Array.from( this.assignedExpressions ).forEach( expression => expression.bindCall( callOptions ) );
  5029. }
  5030. addReference () {}
  5031. assignExpression ( expression ) {
  5032. this.assignedExpressions.add( expression );
  5033. this.isReassigned = true;
  5034. Array.from( this.calls ).forEach( callOptions => expression.bindCall( callOptions ) );
  5035. }
  5036. getName ( es ) {
  5037. if ( es ) { return this.name; }
  5038. if ( !this.isReassigned || !this.exportName ) { return this.name; }
  5039. return `exports.${this.exportName}`;
  5040. }
  5041. hasEffectsWhenCalled ( options ) {
  5042. return Array.from( this.assignedExpressions ).some( node =>
  5043. !options.hasNodeBeenCalled( node )
  5044. && node.hasEffectsWhenCalled( options.getHasEffectsWhenCalledOptions( node ) )
  5045. );
  5046. }
  5047. hasEffectsWhenMutated ( options ) {
  5048. return this.included
  5049. || Array.from( this.assignedExpressions ).some( node =>
  5050. !options.hasNodeBeenMutated( node ) &&
  5051. node.hasEffectsWhenMutated( options.addMutatedNode( node ) )
  5052. );
  5053. }
  5054. includeVariable () {
  5055. const hasBeenIncluded = super.includeVariable();
  5056. if ( hasBeenIncluded ) {
  5057. this.declarations.forEach( identifier => identifier.includeInBundle() );
  5058. }
  5059. return hasBeenIncluded;
  5060. }
  5061. toString () {
  5062. return this.name;
  5063. }
  5064. }
  5065. class ParameterVariable extends LocalVariable {
  5066. constructor ( name, declarator ) {
  5067. super( name, declarator, UNKNOWN_ASSIGNMENT );
  5068. }
  5069. getName () {
  5070. return this.name;
  5071. }
  5072. }
  5073. class Scope {
  5074. constructor ( options ) {
  5075. if ( options === void 0 ) options = {};
  5076. this.parent = options.parent;
  5077. this.isModuleScope = !!options.isModuleScope;
  5078. this.children = [];
  5079. if ( this.parent ) { this.parent.children.push( this ); }
  5080. this.variables = blank();
  5081. }
  5082. addDeclaration ( identifier, isHoisted, init ) {
  5083. const name = identifier.name;
  5084. if ( this.variables[ name ] ) {
  5085. const variable = this.variables[ name ];
  5086. variable.addDeclaration( identifier );
  5087. init && variable.assignExpression( init );
  5088. } else {
  5089. this.variables[ name ] = new LocalVariable( identifier.name, identifier, init );
  5090. }
  5091. }
  5092. addParameterDeclaration ( identifier ) {
  5093. const name = identifier.name;
  5094. this.variables[ name ] = new ParameterVariable( name, identifier );
  5095. }
  5096. contains ( name ) {
  5097. return !!this.variables[ name ] ||
  5098. ( this.parent ? this.parent.contains( name ) : false );
  5099. }
  5100. deshadow ( names ) {
  5101. keys( this.variables ).forEach( key => {
  5102. const declaration = this.variables[ key ];
  5103. // we can disregard exports.foo etc
  5104. if ( declaration.exportName && declaration.isReassigned ) { return; }
  5105. const name = declaration.getName( true );
  5106. let deshadowed = name;
  5107. let i = 1;
  5108. while ( names.has( deshadowed ) ) {
  5109. deshadowed = `${name}$$${i++}`;
  5110. }
  5111. declaration.name = deshadowed;
  5112. } );
  5113. this.children.forEach( scope => scope.deshadow( names ) );
  5114. }
  5115. findLexicalBoundary () {
  5116. return this.parent.findLexicalBoundary();
  5117. }
  5118. findVariable ( name ) {
  5119. return this.variables[ name ] ||
  5120. ( this.parent && this.parent.findVariable( name ) );
  5121. }
  5122. }
  5123. class ArrowFunctionExpression extends Node$1 {
  5124. // Should receive an implementation once we start tracking parameter values
  5125. bindCall () {}
  5126. hasEffects () {
  5127. return this.included;
  5128. }
  5129. hasEffectsWhenCalled ( options ) {
  5130. return this.params.some( param => param.hasEffects( options ) )
  5131. || this.body.hasEffects( options );
  5132. }
  5133. hasEffectsWhenMutated () {
  5134. return this.included;
  5135. }
  5136. initialiseChildren () {
  5137. this.params.forEach( param => param.initialiseAndDeclare( this.scope, 'parameter' ) );
  5138. if ( this.body.initialiseAndReplaceScope ) {
  5139. this.body.initialiseAndReplaceScope( new Scope( { parent: this.scope } ) );
  5140. } else {
  5141. this.body.initialise( this.scope );
  5142. }
  5143. }
  5144. initialiseScope ( parentScope ) {
  5145. this.scope = new Scope( { parent: parentScope } );
  5146. }
  5147. }
  5148. // TODO tidy this up a bit (e.g. they can both use node.module.imports)
  5149. function disallowIllegalReassignment ( scope, node ) {
  5150. if ( node.type === 'MemberExpression' && node.object.type === 'Identifier' ) {
  5151. const variable = scope.findVariable( node.object.name );
  5152. if ( variable.isNamespace ) {
  5153. node.module.error({
  5154. code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
  5155. message: `Illegal reassignment to import '${node.object.name}'`
  5156. }, node.start );
  5157. }
  5158. }
  5159. else if ( node.type === 'Identifier' ) {
  5160. if ( node.module.imports[ node.name ] && !scope.contains( node.name ) ) {
  5161. node.module.error({
  5162. code: 'ILLEGAL_REASSIGNMENT',
  5163. message: `Illegal reassignment to import '${node.name}'`
  5164. }, node.start );
  5165. }
  5166. }
  5167. }
  5168. class AssignmentExpression extends Node$1 {
  5169. bind () {
  5170. super.bind();
  5171. disallowIllegalReassignment( this.scope, this.left );
  5172. this.left.bindAssignment( this.right );
  5173. }
  5174. hasEffects ( options ) {
  5175. return super.hasEffects( options ) || this.left.hasEffectsWhenAssigned( options );
  5176. }
  5177. hasEffectsAsExpressionStatement ( options ) {
  5178. return this.hasEffects( options );
  5179. }
  5180. }
  5181. class AssignmentPattern extends Node$1 {
  5182. bind () {
  5183. super.bind();
  5184. this.left.bindAssignment( this.right );
  5185. }
  5186. bindAssignment ( expression ) {
  5187. this.left.bindAssignment( expression );
  5188. }
  5189. hasEffectsWhenAssigned ( options ) {
  5190. return this.left.hasEffectsWhenAssigned( options );
  5191. }
  5192. initialiseAndDeclare ( parentScope, kind, init ) {
  5193. this.initialiseScope( parentScope );
  5194. this.right.initialise( parentScope );
  5195. this.left.initialiseAndDeclare( parentScope, kind, init );
  5196. }
  5197. }
  5198. class AwaitExpression extends Node$1 {
  5199. hasEffects ( options ) {
  5200. return super.hasEffects( options )
  5201. || !options.ignoreReturnAwaitYield();
  5202. }
  5203. hasEffectsAsExpressionStatement ( options ) {
  5204. return this.hasEffects( options );
  5205. }
  5206. }
  5207. const operators = {
  5208. '==': ( left, right ) => left == right,
  5209. '!=': ( left, right ) => left != right,
  5210. '===': ( left, right ) => left === right,
  5211. '!==': ( left, right ) => left !== right,
  5212. '<': ( left, right ) => left < right,
  5213. '<=': ( left, right ) => left <= right,
  5214. '>': ( left, right ) => left > right,
  5215. '>=': ( left, right ) => left >= right,
  5216. '<<': ( left, right ) => left << right,
  5217. '>>': ( left, right ) => left >> right,
  5218. '>>>': ( left, right ) => left >>> right,
  5219. '+': ( left, right ) => left + right,
  5220. '-': ( left, right ) => left - right,
  5221. '*': ( left, right ) => left * right,
  5222. '/': ( left, right ) => left / right,
  5223. '%': ( left, right ) => left % right,
  5224. '|': ( left, right ) => left | right,
  5225. '^': ( left, right ) => left ^ right,
  5226. '&': ( left, right ) => left & right,
  5227. '**': ( left, right ) => Math.pow( left, right ),
  5228. in: ( left, right ) => left in right,
  5229. instanceof: ( left, right ) => left instanceof right
  5230. };
  5231. class BinaryExpression extends Node$1 {
  5232. getValue () {
  5233. const leftValue = this.left.getValue();
  5234. if ( leftValue === UNKNOWN_VALUE ) { return UNKNOWN_VALUE; }
  5235. const rightValue = this.right.getValue();
  5236. if ( rightValue === UNKNOWN_VALUE ) { return UNKNOWN_VALUE; }
  5237. if ( !operators[ this.operator ] ) { return UNKNOWN_VALUE; }
  5238. return operators[ this.operator ]( leftValue, rightValue );
  5239. }
  5240. }
  5241. class Statement extends Node$1 {
  5242. render ( code, es ) {
  5243. if ( !this.module.bundle.treeshake || this.included ) {
  5244. super.render( code, es );
  5245. } else {
  5246. code.remove( this.leadingCommentStart || this.start, this.next || this.end );
  5247. }
  5248. }
  5249. }
  5250. class BlockScope extends Scope {
  5251. addDeclaration ( identifier, isHoisted, init ) {
  5252. if ( isHoisted ) {
  5253. this.parent.addDeclaration( identifier, isHoisted, init );
  5254. } else {
  5255. super.addDeclaration( identifier, false, init );
  5256. }
  5257. }
  5258. }
  5259. class BlockStatement extends Statement {
  5260. bind () {
  5261. this.body.forEach( node => node.bind() );
  5262. }
  5263. hasEffects ( options ) {
  5264. // Empty block statements do not have effects even though they may be included as e.g. function body
  5265. return this.body.some( child => child.hasEffects( options ) );
  5266. }
  5267. includeInBundle () {
  5268. if ( this.isFullyIncluded() ) { return false; }
  5269. let addedNewNodes = false;
  5270. this.body.forEach( node => {
  5271. if ( node.shouldBeIncluded() ) {
  5272. if ( node.includeInBundle() ) {
  5273. addedNewNodes = true;
  5274. }
  5275. }
  5276. } );
  5277. if ( !this.included || addedNewNodes ) {
  5278. this.included = true;
  5279. return true;
  5280. }
  5281. return false;
  5282. }
  5283. initialiseAndReplaceScope ( scope ) {
  5284. this.scope = scope;
  5285. this.initialiseNode();
  5286. this.initialiseChildren( scope );
  5287. }
  5288. initialiseChildren () {
  5289. let lastNode;
  5290. for ( const node of this.body ) {
  5291. node.initialise( this.scope );
  5292. if ( lastNode ) { lastNode.next = node.start; }
  5293. lastNode = node;
  5294. }
  5295. }
  5296. initialiseScope ( parentScope ) {
  5297. this.scope = new BlockScope( { parent: parentScope } );
  5298. }
  5299. render ( code, es ) {
  5300. if ( this.body.length ) {
  5301. for ( const node of this.body ) {
  5302. node.render( code, es );
  5303. }
  5304. } else {
  5305. Statement.prototype.render.call( this, code, es );
  5306. }
  5307. }
  5308. }
  5309. class BreakStatement extends Node$1 {
  5310. hasEffects ( options ) {
  5311. return super.hasEffects( options )
  5312. || !options.ignoreBreakStatements()
  5313. || (this.label && !options.ignoreLabel( this.label.name ));
  5314. }
  5315. }
  5316. class CallExpression extends Node$1 {
  5317. bind () {
  5318. if ( this.callee.type === 'Identifier' ) {
  5319. const variable = this.scope.findVariable( this.callee.name );
  5320. if ( variable.isNamespace ) {
  5321. this.module.error( {
  5322. code: 'CANNOT_CALL_NAMESPACE',
  5323. message: `Cannot call a namespace ('${this.callee.name}')`
  5324. }, this.start );
  5325. }
  5326. if ( this.callee.name === 'eval' && variable.isGlobal ) {
  5327. this.module.warn( {
  5328. code: 'EVAL',
  5329. message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
  5330. url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval'
  5331. }, this.start );
  5332. }
  5333. }
  5334. super.bind();
  5335. this.callee.bindCall( { withNew: false } );
  5336. }
  5337. hasEffects ( options ) {
  5338. return this.included
  5339. || this.arguments.some( child => child.hasEffects( options ) )
  5340. || this.callee.hasEffectsWhenCalled( options.getHasEffectsWhenCalledOptions( this.callee ) );
  5341. }
  5342. hasEffectsAsExpressionStatement ( options ) {
  5343. return this.hasEffects( options );
  5344. }
  5345. }
  5346. class CatchClause extends Node$1 {
  5347. initialiseChildren () {
  5348. this.param && this.param.initialiseAndDeclare( this.scope, 'parameter' );
  5349. this.body.initialiseAndReplaceScope( this.scope );
  5350. }
  5351. initialiseScope ( parentScope ) {
  5352. this.scope = new BlockScope( { parent: parentScope } );
  5353. }
  5354. }
  5355. class ClassBody extends Node$1 {
  5356. bindCall ( callOptions ) {
  5357. if ( this.classConstructor ) {
  5358. this.classConstructor.bindCall( callOptions );
  5359. }
  5360. }
  5361. hasEffectsWhenCalled ( options ) {
  5362. if ( this.classConstructor ) {
  5363. return this.classConstructor.hasEffectsWhenCalled( options );
  5364. }
  5365. return false;
  5366. }
  5367. initialiseNode () {
  5368. this.classConstructor = this.body.find( method => method.kind === 'constructor' );
  5369. }
  5370. }
  5371. class ClassNode extends Node$1 {
  5372. bindCall ( callOptions ) {
  5373. if ( this.superClass ) {
  5374. this.superClass.bindCall( callOptions );
  5375. }
  5376. this.body.bindCall( callOptions );
  5377. }
  5378. hasEffectsAsExpressionStatement ( options ) {
  5379. return this.hasEffects( options );
  5380. }
  5381. hasEffectsWhenCalled ( options ) {
  5382. return this.body.hasEffectsWhenCalled( options )
  5383. || ( this.superClass && this.superClass.hasEffectsWhenCalled( options ) );
  5384. }
  5385. initialiseChildren () {
  5386. if ( this.superClass ) {
  5387. this.superClass.initialise( this.scope );
  5388. }
  5389. this.body.initialise( this.scope );
  5390. }
  5391. initialiseScope ( parentScope ) {
  5392. this.scope = new Scope( { parent: parentScope } );
  5393. }
  5394. }
  5395. class ClassDeclaration extends ClassNode {
  5396. initialiseChildren ( parentScope ) {
  5397. // Class declarations are like let declarations: Not hoisted, can be reassigned, cannot be redeclared
  5398. this.id && this.id.initialiseAndDeclare( parentScope, 'class', this );
  5399. super.initialiseChildren( parentScope );
  5400. }
  5401. render ( code, es ) {
  5402. if ( !this.module.bundle.treeshake || this.included ) {
  5403. super.render( code, es );
  5404. } else {
  5405. code.remove( this.leadingCommentStart || this.start, this.next || this.end );
  5406. }
  5407. }
  5408. }
  5409. class ClassExpression extends ClassNode {
  5410. initialiseChildren ( parentScope ) {
  5411. this.id && this.id.initialiseAndDeclare( this.scope, 'class', this );
  5412. super.initialiseChildren( parentScope );
  5413. }
  5414. }
  5415. class ConditionalExpression extends Node$1 {
  5416. initialiseChildren ( parentScope ) {
  5417. if ( this.module.bundle.treeshake ) {
  5418. this.testValue = this.test.getValue();
  5419. if ( this.testValue === UNKNOWN_VALUE ) {
  5420. super.initialiseChildren( parentScope );
  5421. } else if ( this.testValue ) {
  5422. this.consequent.initialise( this.scope );
  5423. this.alternate = null;
  5424. } else if ( this.alternate ) {
  5425. this.alternate.initialise( this.scope );
  5426. this.consequent = null;
  5427. }
  5428. } else {
  5429. super.initialiseChildren( parentScope );
  5430. }
  5431. }
  5432. getValue () {
  5433. const testValue = this.test.getValue();
  5434. if ( testValue === UNKNOWN_VALUE ) { return UNKNOWN_VALUE; }
  5435. return testValue ? this.consequent.getValue() : this.alternate.getValue();
  5436. }
  5437. render ( code, es ) {
  5438. if ( !this.module.bundle.treeshake ) {
  5439. super.render( code, es );
  5440. }
  5441. else {
  5442. if ( this.testValue === UNKNOWN_VALUE ) {
  5443. super.render( code, es );
  5444. }
  5445. else if ( this.testValue ) {
  5446. code.remove( this.start, this.consequent.start );
  5447. code.remove( this.consequent.end, this.end );
  5448. if ( this.consequent.type === 'SequenceExpression' ) {
  5449. code.prependRight( this.consequent.start, '(' );
  5450. code.appendLeft( this.consequent.end, ')' );
  5451. }
  5452. this.consequent.render( code, es );
  5453. } else {
  5454. code.remove( this.start, this.alternate.start );
  5455. code.remove( this.alternate.end, this.end );
  5456. if ( this.alternate.type === 'SequenceExpression' ) {
  5457. code.prependRight( this.alternate.start, '(' );
  5458. code.appendLeft( this.alternate.end, ')' );
  5459. }
  5460. this.alternate.render( code, es );
  5461. }
  5462. }
  5463. }
  5464. }
  5465. class DoWhileStatement extends Statement {
  5466. hasEffects ( options ) {
  5467. return (
  5468. this.included
  5469. || this.test.hasEffects( options )
  5470. || this.body.hasEffects( options.setIgnoreBreakStatements() )
  5471. );
  5472. }
  5473. }
  5474. class EmptyStatement extends Statement {
  5475. render ( code ) {
  5476. if ( this.parent.type === 'BlockStatement' || this.parent.type === 'Program' ) {
  5477. code.remove( this.start, this.end );
  5478. }
  5479. }
  5480. }
  5481. class ExportAllDeclaration extends Node$1 {
  5482. initialiseNode () {
  5483. this.isExportDeclaration = true;
  5484. }
  5485. render ( code ) {
  5486. code.remove( this.leadingCommentStart || this.start, this.next || this.end );
  5487. }
  5488. }
  5489. const functionOrClassDeclaration = /^(?:Function|Class)Declaration/;
  5490. class ExportDefaultDeclaration extends Node$1 {
  5491. addCall ( options ) {
  5492. this.declaration.bindCall( options );
  5493. }
  5494. addReference ( reference ) {
  5495. this.name = reference.name;
  5496. if ( this.original ) { this.original.addReference( reference ); }
  5497. }
  5498. bind () {
  5499. const name = ( this.declaration.id && this.declaration.id.name ) || this.declaration.name;
  5500. if ( name ) { this.original = this.scope.findVariable( name ); }
  5501. this.declaration.bind();
  5502. }
  5503. getName ( es ) {
  5504. if ( this.original && !this.original.isReassigned ) {
  5505. return this.original.getName( es );
  5506. }
  5507. return this.name;
  5508. }
  5509. hasEffectsWhenCalled ( options ) {
  5510. return this.declaration.hasEffectsWhenCalled( options );
  5511. }
  5512. includeVariable () {
  5513. if ( this.included ) {
  5514. return false;
  5515. }
  5516. this.included = true;
  5517. this.declaration.includeInBundle();
  5518. return true;
  5519. }
  5520. includeInBundle () {
  5521. if ( this.declaration.shouldBeIncluded() ) {
  5522. return this.declaration.includeInBundle();
  5523. }
  5524. return false;
  5525. }
  5526. initialiseNode () {
  5527. this.isExportDeclaration = true;
  5528. this.isDefault = true;
  5529. this.name = ( this.declaration.id && this.declaration.id.name ) || this.declaration.name || this.module.basename();
  5530. this.scope.variables.default = this;
  5531. }
  5532. // TODO this is total chaos, tidy it up
  5533. render ( code, es ) {
  5534. const treeshake = this.module.bundle.treeshake;
  5535. const name = this.getName( es );
  5536. // paren workaround: find first non-whitespace character position after `export default`
  5537. let declaration_start;
  5538. if ( this.declaration ) {
  5539. const statementStr = code.original.slice( this.start, this.end );
  5540. declaration_start = this.start + statementStr.match( /^\s*export\s+default\s*/ )[ 0 ].length;
  5541. }
  5542. if ( this.included || this.declaration.included ) {
  5543. if ( this.included ) {
  5544. if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
  5545. if ( this.declaration.id ) {
  5546. code.remove( this.start, declaration_start );
  5547. } else {
  5548. code.overwrite( this.start, declaration_start, `var ${this.name} = ` );
  5549. if ( code.original[ this.end - 1 ] !== ';' ) { code.appendLeft( this.end, ';' ); }
  5550. }
  5551. }
  5552. else {
  5553. if ( this.original && this.original.getName( es ) === name ) {
  5554. // prevent `var foo = foo`
  5555. code.remove( this.leadingCommentStart || this.start, this.next || this.end );
  5556. return; // don't render children. TODO this seems like a bit of a hack
  5557. } else {
  5558. code.overwrite( this.start, declaration_start, `${this.module.bundle.varOrConst} ${name} = ` );
  5559. }
  5560. this.insertSemicolon( code );
  5561. }
  5562. } else {
  5563. // remove `var foo` from `var foo = bar()`, if `foo` is unused
  5564. code.remove( this.start, declaration_start );
  5565. }
  5566. super.render( code, es );
  5567. } else {
  5568. if ( treeshake ) {
  5569. if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
  5570. code.remove( this.leadingCommentStart || this.start, this.next || this.end );
  5571. } else {
  5572. const hasEffects = this.declaration.hasEffects( ExecutionPathOptions.create() );
  5573. code.remove( this.start, hasEffects ? declaration_start : this.next || this.end );
  5574. }
  5575. } else if ( name === this.declaration.name ) {
  5576. code.remove( this.start, this.next || this.end );
  5577. } else {
  5578. code.overwrite( this.start, declaration_start, `${this.module.bundle.varOrConst} ${name} = ` );
  5579. }
  5580. // code.remove( this.start, this.next || this.end );
  5581. }
  5582. }
  5583. }
  5584. class ExportNamedDeclaration extends Node$1 {
  5585. bind () {
  5586. // Do not bind specifiers
  5587. if ( this.declaration ) { this.declaration.bind(); }
  5588. }
  5589. hasEffects ( options ) {
  5590. return this.included || (this.declaration && this.declaration.hasEffects( options ));
  5591. }
  5592. initialiseNode () {
  5593. this.isExportDeclaration = true;
  5594. }
  5595. render ( code, es ) {
  5596. if ( this.declaration ) {
  5597. code.remove( this.start, this.declaration.start );
  5598. this.declaration.render( code, es );
  5599. } else {
  5600. const start = this.leadingCommentStart || this.start;
  5601. const end = this.next || this.end;
  5602. if ( this.defaultExport ) {
  5603. const name = this.defaultExport.getName( es );
  5604. const originalName = this.defaultExport.original.getName( es );
  5605. if ( name !== originalName ) {
  5606. code.overwrite( start, end, `var ${name} = ${originalName};` );
  5607. return;
  5608. }
  5609. }
  5610. code.remove( start, end );
  5611. }
  5612. }
  5613. }
  5614. class ExpressionStatement extends Statement {
  5615. hasEffects ( options ) {
  5616. return super.hasEffects( options ) || this.expression.hasEffectsAsExpressionStatement(options);
  5617. }
  5618. render ( code, es ) {
  5619. super.render( code, es );
  5620. if ( this.included ) { this.insertSemicolon( code ); }
  5621. }
  5622. }
  5623. class ForStatement extends Statement {
  5624. hasEffects ( options ) {
  5625. return (
  5626. this.included
  5627. || this.init && this.init.hasEffects( options )
  5628. || this.test && this.test.hasEffects( options )
  5629. || this.update && this.update.hasEffects( options )
  5630. || this.body.hasEffects( options.setIgnoreBreakStatements() )
  5631. );
  5632. }
  5633. initialiseChildren () {
  5634. if ( this.init ) { this.init.initialise( this.scope ); }
  5635. if ( this.test ) { this.test.initialise( this.scope ); }
  5636. if ( this.update ) { this.update.initialise( this.scope ); }
  5637. if ( this.body.type === 'BlockStatement' ) {
  5638. this.body.initialiseScope( this.scope );
  5639. this.body.initialiseChildren();
  5640. } else {
  5641. this.body.initialise( this.scope );
  5642. }
  5643. }
  5644. initialiseScope ( parentScope ) {
  5645. this.scope = new BlockScope( { parent: parentScope } );
  5646. }
  5647. }
  5648. class ForInStatement extends Statement {
  5649. hasEffects ( options ) {
  5650. return (
  5651. this.included
  5652. || this.left && (this.left.hasEffects( options ) || this.left.hasEffectsWhenAssigned( options ))
  5653. || this.right && this.right.hasEffects( options )
  5654. || this.body.hasEffects( options.setIgnoreBreakStatements() )
  5655. );
  5656. }
  5657. initialiseChildren () {
  5658. this.left.initialise( this.scope );
  5659. this.right.initialise( this.scope.parent );
  5660. this.body.initialiseAndReplaceScope ?
  5661. this.body.initialiseAndReplaceScope( this.scope ) :
  5662. this.body.initialise( this.scope );
  5663. }
  5664. includeInBundle () {
  5665. let addedNewNodes = super.includeInBundle();
  5666. if ( this.left.includeWithAllDeclarations() ) {
  5667. addedNewNodes = true;
  5668. }
  5669. return addedNewNodes;
  5670. }
  5671. initialiseScope ( parentScope ) {
  5672. this.scope = new BlockScope( { parent: parentScope } );
  5673. }
  5674. }
  5675. class ForOfStatement extends Statement {
  5676. bind () {
  5677. super.bind();
  5678. this.left.bindAssignment( UNKNOWN_ASSIGNMENT );
  5679. }
  5680. hasEffects ( options ) {
  5681. return (
  5682. this.included
  5683. || this.left && (this.left.hasEffects( options ) || this.left.hasEffectsWhenAssigned( options ))
  5684. || this.right && this.right.hasEffects( options )
  5685. || this.body.hasEffects( options.setIgnoreBreakStatements() )
  5686. );
  5687. }
  5688. includeInBundle () {
  5689. let addedNewNodes = super.includeInBundle();
  5690. if ( this.left.includeWithAllDeclarations() ) {
  5691. addedNewNodes = true;
  5692. }
  5693. return addedNewNodes;
  5694. }
  5695. initialiseChildren () {
  5696. this.left.initialise( this.scope );
  5697. this.right.initialise( this.scope.parent );
  5698. this.body.initialiseAndReplaceScope ?
  5699. this.body.initialiseAndReplaceScope( this.scope ) :
  5700. this.body.initialise( this.scope );
  5701. }
  5702. initialiseScope ( parentScope ) {
  5703. this.scope = new BlockScope( { parent: parentScope } );
  5704. }
  5705. }
  5706. class FunctionScope extends Scope {
  5707. constructor ( options ) {
  5708. if ( options === void 0 ) options = {};
  5709. super( options );
  5710. this.variables.arguments = new ParameterVariable( 'arguments' );
  5711. this.variables.this = new LocalVariable( 'this', null, null );
  5712. }
  5713. findLexicalBoundary () {
  5714. return this;
  5715. }
  5716. }
  5717. class FunctionNode extends Node$1 {
  5718. bindCall ( ref ) {
  5719. var withNew = ref.withNew;
  5720. const thisVariable = this.scope.findVariable( 'this' );
  5721. if ( withNew ) {
  5722. thisVariable.assignExpression( UNKNOWN_OBJECT_LITERAL );
  5723. } else {
  5724. thisVariable.assignExpression( UNKNOWN_ASSIGNMENT );
  5725. }
  5726. }
  5727. hasEffects ( options ) {
  5728. return this.included || (this.id && this.id.hasEffects( options ));
  5729. }
  5730. hasEffectsAsExpressionStatement ( options ) {
  5731. return this.hasEffects( options );
  5732. }
  5733. hasEffectsWhenCalled ( options ) {
  5734. const innerOptions = options.setIgnoreSafeThisMutations();
  5735. return this.params.some( param => param.hasEffects( innerOptions ) )
  5736. || this.body.hasEffects( innerOptions );
  5737. }
  5738. hasEffectsWhenMutated () {
  5739. return this.included;
  5740. }
  5741. initialiseScope ( parentScope ) {
  5742. this.scope = new FunctionScope( { parent: parentScope } );
  5743. }
  5744. }
  5745. class FunctionDeclaration extends FunctionNode {
  5746. initialiseChildren ( parentScope ) {
  5747. this.id && this.id.initialiseAndDeclare( parentScope, 'function', this );
  5748. this.params.forEach( param => param.initialiseAndDeclare( this.scope, 'parameter' ) );
  5749. this.body.initialiseAndReplaceScope( new Scope( { parent: this.scope } ) );
  5750. }
  5751. render ( code, es ) {
  5752. if ( !this.module.bundle.treeshake || this.included ) {
  5753. super.render( code, es );
  5754. } else {
  5755. code.remove( this.leadingCommentStart || this.start, this.next || this.end );
  5756. }
  5757. }
  5758. }
  5759. class FunctionExpression extends FunctionNode {
  5760. initialiseChildren () {
  5761. this.id && this.id.initialiseAndDeclare( this.scope, 'function', this );
  5762. this.params.forEach( param => param.initialiseAndDeclare( this.scope, 'parameter' ) );
  5763. this.body.initialiseAndReplaceScope( new Scope( { parent: this.scope } ) );
  5764. }
  5765. }
  5766. function isReference (node, parent) {
  5767. if (node.type === 'MemberExpression') {
  5768. return !node.computed && isReference(node.object, node);
  5769. }
  5770. if (node.type === 'Identifier') {
  5771. // the only time we could have an identifier node without a parent is
  5772. // if it's the entire body of a function without a block statement –
  5773. // i.e. an arrow function expression like `a => a`
  5774. if (!parent) return true;
  5775. // TODO is this right?
  5776. if (parent.type === 'MemberExpression' || parent.type === 'MethodDefinition') {
  5777. return parent.computed || node === parent.object;
  5778. }
  5779. // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
  5780. if (parent.type === 'Property') return parent.computed || node === parent.value;
  5781. // disregard the `bar` in `class Foo { bar () {...} }`
  5782. if (parent.type === 'MethodDefinition') return false;
  5783. // disregard the `bar` in `export { foo as bar }`
  5784. if (parent.type === 'ExportSpecifier' && node !== parent.local) return false;
  5785. return true;
  5786. }
  5787. return false;
  5788. }
  5789. function isAssignmentPatternLhs ( node, parent ) {
  5790. // special case: `({ foo = 42 }) => {...}`
  5791. // `foo` actually has two different parents, the Property of the
  5792. // ObjectPattern, and the AssignmentPattern. In one case it's a
  5793. // reference, in one case it's not, because it's shorthand for
  5794. // `({ foo: foo = 42 }) => {...}`. But unlike a regular shorthand
  5795. // property, the `foo` node appears at different levels of the tree
  5796. return (
  5797. parent.type === 'Property' &&
  5798. parent.shorthand &&
  5799. parent.value.type === 'AssignmentPattern' &&
  5800. parent.value.left === node
  5801. );
  5802. }
  5803. class Identifier extends Node$1 {
  5804. bind () {
  5805. if ( isReference( this, this.parent ) || isAssignmentPatternLhs( this, this.parent ) ) {
  5806. this.variable = this.scope.findVariable( this.name );
  5807. this.variable.addReference( this );
  5808. }
  5809. }
  5810. bindAssignment ( expression ) {
  5811. if ( this.variable ) {
  5812. this.variable.assignExpression( expression );
  5813. }
  5814. }
  5815. bindCall ( callOptions ) {
  5816. if ( this.variable ) {
  5817. this.variable.addCall( callOptions );
  5818. }
  5819. }
  5820. hasEffectsAsExpressionStatement ( options ) {
  5821. return this.hasEffects( options ) || this.variable.isGlobal;
  5822. }
  5823. hasEffectsWhenAssigned () {
  5824. return this.variable && this.variable.included;
  5825. }
  5826. hasEffectsWhenCalled ( options ) {
  5827. if ( !this.variable ) {
  5828. return true;
  5829. }
  5830. return this.variable.hasEffectsWhenCalled( options );
  5831. }
  5832. hasEffectsWhenMutated ( options ) {
  5833. return this.variable && this.variable.hasEffectsWhenMutated( options );
  5834. }
  5835. includeInBundle () {
  5836. if ( this.included ) { return false; }
  5837. this.included = true;
  5838. this.variable && this.variable.includeVariable();
  5839. return true;
  5840. }
  5841. initialiseAndDeclare ( parentScope, kind, init ) {
  5842. this.initialiseScope( parentScope );
  5843. switch ( kind ) {
  5844. case 'var':
  5845. case 'function':
  5846. this.scope.addDeclaration( this, true, init );
  5847. break;
  5848. case 'let':
  5849. case 'const':
  5850. case 'class':
  5851. this.scope.addDeclaration( this, false, init );
  5852. break;
  5853. case 'parameter':
  5854. this.scope.addParameterDeclaration( this );
  5855. break;
  5856. default:
  5857. throw new Error( 'Unexpected identifier kind', kind );
  5858. }
  5859. }
  5860. render ( code, es ) {
  5861. if ( this.variable ) {
  5862. const name = this.variable.getName( es );
  5863. if ( name !== this.name ) {
  5864. code.overwrite( this.start, this.end, name, { storeName: true, contentOnly: false } );
  5865. // special case
  5866. if ( this.parent.type === 'Property' && this.parent.shorthand ) {
  5867. code.appendLeft( this.start, `${this.name}: ` );
  5868. }
  5869. }
  5870. }
  5871. }
  5872. }
  5873. // Statement types which may contain if-statements as direct children.
  5874. const statementsWithIfStatements = new Set( [
  5875. 'DoWhileStatement',
  5876. 'ForInStatement',
  5877. 'ForOfStatement',
  5878. 'ForStatement',
  5879. 'IfStatement',
  5880. 'WhileStatement'
  5881. ] );
  5882. function getHoistedVars ( node, scope ) {
  5883. const hoistedVars = [];
  5884. function visit ( node ) {
  5885. if ( node.type === 'VariableDeclaration' && node.kind === 'var' ) {
  5886. node.declarations.forEach( declarator => {
  5887. declarator.init = null;
  5888. declarator.initialise( scope );
  5889. extractNames( declarator.id ).forEach( name => {
  5890. if ( hoistedVars.indexOf( name ) < 0 ) { hoistedVars.push( name ); }
  5891. } );
  5892. } );
  5893. }
  5894. else if ( !/Function/.test( node.type ) ) {
  5895. node.eachChild( visit );
  5896. }
  5897. }
  5898. visit( node );
  5899. return hoistedVars;
  5900. }
  5901. class IfStatement extends Statement {
  5902. initialiseChildren ( parentScope ) {
  5903. super.initialiseChildren( parentScope );
  5904. if ( this.module.bundle.treeshake ) {
  5905. this.testValue = this.test.getValue();
  5906. if ( this.testValue === UNKNOWN_VALUE ) {
  5907. return;
  5908. }
  5909. if ( this.testValue ) {
  5910. if ( this.alternate ) {
  5911. this.hoistedVars = getHoistedVars( this.alternate, this.scope );
  5912. this.alternate = null;
  5913. }
  5914. } else {
  5915. this.hoistedVars = getHoistedVars( this.consequent, this.scope );
  5916. this.consequent = null;
  5917. }
  5918. }
  5919. }
  5920. render ( code, es ) {
  5921. if ( this.module.bundle.treeshake ) {
  5922. if ( this.testValue === UNKNOWN_VALUE ) {
  5923. super.render( code, es );
  5924. }
  5925. else {
  5926. code.overwrite( this.test.start, this.test.end, JSON.stringify( this.testValue ) );
  5927. // TODO if no block-scoped declarations, remove enclosing
  5928. // curlies and dedent block (if there is a block)
  5929. if ( this.hoistedVars ) {
  5930. const names = this.hoistedVars
  5931. .map( name => {
  5932. const variable = this.scope.findVariable( name );
  5933. return variable.included ? variable.getName() : null;
  5934. } )
  5935. .filter( Boolean );
  5936. if ( names.length > 0 ) {
  5937. code.appendLeft( this.start, `var ${names.join( ', ' )};\n\n` );
  5938. }
  5939. }
  5940. if ( this.testValue ) {
  5941. code.remove( this.start, this.consequent.start );
  5942. code.remove( this.consequent.end, this.end );
  5943. this.consequent.render( code, es );
  5944. }
  5945. else {
  5946. code.remove( this.start, this.alternate ? this.alternate.start : this.next || this.end );
  5947. if ( this.alternate ) {
  5948. this.alternate.render( code, es );
  5949. }
  5950. else if ( statementsWithIfStatements.has( this.parent.type ) ) {
  5951. code.prependRight( this.start, '{}' );
  5952. }
  5953. }
  5954. }
  5955. }
  5956. else {
  5957. super.render( code, es );
  5958. }
  5959. }
  5960. }
  5961. class ImportDeclaration extends Node$1 {
  5962. bind () {
  5963. // noop
  5964. // TODO do the inter-module binding setup here?
  5965. }
  5966. initialiseNode () {
  5967. this.isImportDeclaration = true;
  5968. }
  5969. render ( code ) {
  5970. code.remove( this.start, this.next || this.end );
  5971. }
  5972. }
  5973. class LabeledStatement extends Statement {
  5974. hasEffects ( options ) {
  5975. return this.body.hasEffects(
  5976. options
  5977. .setIgnoreLabel( this.label.name )
  5978. .setIgnoreBreakStatements()
  5979. );
  5980. }
  5981. }
  5982. class Literal extends Node$1 {
  5983. getValue () {
  5984. return this.value;
  5985. }
  5986. hasEffectsWhenMutated () {
  5987. return false;
  5988. }
  5989. render ( code ) {
  5990. if ( typeof this.value === 'string' ) {
  5991. code.indentExclusionRanges.push( [ this.start + 1, this.end - 1 ] );
  5992. }
  5993. }
  5994. }
  5995. const operators$1 = {
  5996. '&&': ( left, right ) => left && right,
  5997. '||': ( left, right ) => left || right
  5998. };
  5999. class LogicalExpression extends Node$1 {
  6000. getValue () {
  6001. const leftValue = this.left.getValue();
  6002. if ( leftValue === UNKNOWN_VALUE ) { return UNKNOWN_VALUE; }
  6003. const rightValue = this.right.getValue();
  6004. if ( rightValue === UNKNOWN_VALUE ) { return UNKNOWN_VALUE; }
  6005. return operators$1[ this.operator ]( leftValue, rightValue );
  6006. }
  6007. hasEffectsWhenMutated ( options ) {
  6008. const leftValue = this.left.getValue();
  6009. if ( leftValue === UNKNOWN_VALUE ) {
  6010. return this.left.hasEffectsWhenMutated( options ) || this.right.hasEffectsWhenMutated( options );
  6011. }
  6012. if ((leftValue && this.operator === '||') || (!leftValue && this.operator === '&&')) {
  6013. return this.left.hasEffectsWhenMutated( options );
  6014. }
  6015. return this.right.hasEffectsWhenMutated( options );
  6016. }
  6017. }
  6018. function flatten ( node ) {
  6019. const parts = [];
  6020. while ( node.type === 'MemberExpression' ) {
  6021. if ( node.computed ) { return null; }
  6022. parts.unshift( node.property.name );
  6023. node = node.object;
  6024. }
  6025. if ( node.type !== 'Identifier' ) { return null; }
  6026. const name = node.name;
  6027. parts.unshift( name );
  6028. return { name, keypath: parts.join( '.' ) };
  6029. }
  6030. const pureFunctions = {};
  6031. const arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split( ' ' );
  6032. const simdTypes = 'Int8x16 Int16x8 Int32x4 Float32x4 Float64x2'.split( ' ' );
  6033. const simdMethods = 'abs add and bool check div equal extractLane fromFloat32x4 fromFloat32x4Bits fromFloat64x2 fromFloat64x2Bits fromInt16x8Bits fromInt32x4 fromInt32x4Bits fromInt8x16Bits greaterThan greaterThanOrEqual lessThan lessThanOrEqual load max maxNum min minNum mul neg not notEqual or reciprocalApproximation reciprocalSqrtApproximation replaceLane select selectBits shiftLeftByScalar shiftRightArithmeticByScalar shiftRightLogicalByScalar shuffle splat sqrt store sub swizzle xor'.split( ' ' );
  6034. const allSimdMethods = [];
  6035. simdTypes.forEach( t => {
  6036. simdMethods.forEach( m => {
  6037. allSimdMethods.push( `SIMD.${t}.${m}` );
  6038. });
  6039. });
  6040. [
  6041. 'Array.isArray',
  6042. 'Error', 'EvalError', 'InternalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
  6043. 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape', 'unescape',
  6044. 'Object', 'Object.create', 'Object.getNotifier', 'Object.getOwn', 'Object.getOwnPropertyDescriptor', 'Object.getOwnPropertyNames', 'Object.getOwnPropertySymbols', 'Object.getPrototypeOf', 'Object.is', 'Object.isExtensible', 'Object.isFrozen', 'Object.isSealed', 'Object.keys',
  6045. 'Function', 'Boolean',
  6046. 'Number', 'Number.isFinite', 'Number.isInteger', 'Number.isNaN', 'Number.isSafeInteger', 'Number.parseFloat', 'Number.parseInt',
  6047. 'Symbol', 'Symbol.for', 'Symbol.keyFor',
  6048. 'Math.abs', 'Math.acos', 'Math.acosh', 'Math.asin', 'Math.asinh', 'Math.atan', 'Math.atan2', 'Math.atanh', 'Math.cbrt', 'Math.ceil', 'Math.clz32', 'Math.cos', 'Math.cosh', 'Math.exp', 'Math.expm1', 'Math.floor', 'Math.fround', 'Math.hypot', 'Math.imul', 'Math.log', 'Math.log10', 'Math.log1p', 'Math.log2', 'Math.max', 'Math.min', 'Math.pow', 'Math.random', 'Math.round', 'Math.sign', 'Math.sin', 'Math.sinh', 'Math.sqrt', 'Math.tan', 'Math.tanh', 'Math.trunc',
  6049. 'Date', 'Date.UTC', 'Date.now', 'Date.parse',
  6050. 'String', 'String.fromCharCode', 'String.fromCodePoint', 'String.raw',
  6051. 'RegExp',
  6052. 'Map', 'Set', 'WeakMap', 'WeakSet',
  6053. 'ArrayBuffer', 'ArrayBuffer.isView',
  6054. 'DataView',
  6055. 'JSON.parse', 'JSON.stringify',
  6056. 'Promise.all', 'Promise.race', 'Promise.resolve',
  6057. 'Intl.Collator', 'Intl.Collator.supportedLocalesOf', 'Intl.DateTimeFormat', 'Intl.DateTimeFormat.supportedLocalesOf', 'Intl.NumberFormat', 'Intl.NumberFormat.supportedLocalesOf'
  6058. // TODO properties of e.g. window...
  6059. ].concat(
  6060. arrayTypes,
  6061. arrayTypes.map( t => `${t}.from` ),
  6062. arrayTypes.map( t => `${t}.of` ),
  6063. simdTypes.map( t => `SIMD.${t}` ),
  6064. allSimdMethods
  6065. ).forEach( name => pureFunctions[ name ] = true );
  6066. const validProp = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
  6067. class Keypath {
  6068. constructor ( node ) {
  6069. this.parts = [];
  6070. while ( node.type === 'MemberExpression' ) {
  6071. const prop = node.property;
  6072. if ( node.computed ) {
  6073. if ( prop.type !== 'Literal' || typeof prop.value !== 'string' || !validProp.test( prop.value ) ) {
  6074. this.computed = true;
  6075. return;
  6076. }
  6077. }
  6078. this.parts.unshift( prop );
  6079. node = node.object;
  6080. }
  6081. this.root = node;
  6082. }
  6083. }
  6084. class MemberExpression extends Node$1 {
  6085. bind () {
  6086. // if this resolves to a namespaced declaration, prepare
  6087. // to replace it
  6088. // TODO this code is a bit inefficient
  6089. const keypath = new Keypath( this );
  6090. if ( !keypath.computed && keypath.root.type === 'Identifier' ) {
  6091. let variable = this.scope.findVariable( keypath.root.name );
  6092. while ( variable.isNamespace && keypath.parts.length ) {
  6093. const exporterId = variable.module.id;
  6094. const part = keypath.parts[ 0 ];
  6095. variable = variable.module.traceExport( part.name || part.value );
  6096. if ( !variable ) {
  6097. this.module.warn( {
  6098. code: 'MISSING_EXPORT',
  6099. missing: part.name || part.value,
  6100. importer: relativeId( this.module.id ),
  6101. exporter: relativeId( exporterId ),
  6102. message: `'${part.name || part.value}' is not exported by '${relativeId( exporterId )}'`,
  6103. url: `https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module`
  6104. }, part.start );
  6105. this.replacement = 'undefined';
  6106. return;
  6107. }
  6108. keypath.parts.shift();
  6109. }
  6110. if ( keypath.parts.length ) {
  6111. super.bind();
  6112. return; // not a namespaced declaration
  6113. }
  6114. this.variable = variable;
  6115. if ( variable.isExternal ) {
  6116. variable.module.suggestName( keypath.root.name );
  6117. }
  6118. }
  6119. else {
  6120. super.bind();
  6121. }
  6122. }
  6123. bindCall ( callOptions ) {
  6124. if ( this.variable ) {
  6125. this.variable.addCall( callOptions );
  6126. }
  6127. }
  6128. hasEffectsWhenAssigned ( options ) {
  6129. return this.object.hasEffectsWhenMutated( options );
  6130. }
  6131. includeInBundle () {
  6132. let addedNewNodes = super.includeInBundle();
  6133. if ( this.variable && !this.variable.included ) {
  6134. this.variable.includeVariable();
  6135. addedNewNodes = true;
  6136. }
  6137. return addedNewNodes;
  6138. }
  6139. hasEffectsWhenCalled ( options ) {
  6140. if ( this.variable ) {
  6141. return this.variable.hasEffectsWhenCalled( options );
  6142. }
  6143. if ( !isReference( this ) ) {
  6144. return true;
  6145. }
  6146. const flattenedNode = flatten( this );
  6147. return !(this.scope.findVariable( flattenedNode.name ).isGlobal && pureFunctions[ flattenedNode.keypath ]);
  6148. }
  6149. render ( code, es ) {
  6150. if ( this.variable ) {
  6151. const name = this.variable.getName( es );
  6152. if ( name !== this.name ) { code.overwrite( this.start, this.end, name, { storeName: true, contentOnly: false } ); }
  6153. }
  6154. else if ( this.replacement ) {
  6155. code.overwrite( this.start, this.end, this.replacement, { storeName: true, contentOnly: false } );
  6156. }
  6157. super.render( code, es );
  6158. }
  6159. }
  6160. class MethodDefinition extends Node$1 {
  6161. bindCall ( callOptions ) {
  6162. this.value.bindCall( callOptions );
  6163. }
  6164. hasEffects ( options ) {
  6165. return this.key.hasEffects( options );
  6166. }
  6167. hasEffectsWhenCalled ( options ) {
  6168. return this.value.hasEffectsWhenCalled( options );
  6169. }
  6170. }
  6171. class NewExpression extends Node$1 {
  6172. bind () {
  6173. super.bind();
  6174. this.callee.bindCall( { withNew: true } );
  6175. }
  6176. hasEffects ( options ) {
  6177. return this.included
  6178. || this.arguments.some( child => child.hasEffects( options ) )
  6179. || this.callee.hasEffectsWhenCalled( options.getHasEffectsWhenCalledOptions( this.callee ) );
  6180. }
  6181. }
  6182. class ObjectExpression extends Node$1 {
  6183. hasEffectsWhenMutated () {
  6184. return false;
  6185. }
  6186. }
  6187. class ObjectPattern extends Node$1 {
  6188. bindAssignment ( expression ) {
  6189. this.properties.forEach( child => child.bindAssignment( expression ) );
  6190. }
  6191. hasEffectsWhenAssigned ( options ) {
  6192. return this.someChild( child => child.hasEffectsWhenAssigned( options ) );
  6193. }
  6194. initialiseAndDeclare ( parentScope, kind, init ) {
  6195. this.initialiseScope( parentScope );
  6196. this.properties.forEach( child => child.initialiseAndDeclare( parentScope, kind, init ) );
  6197. }
  6198. }
  6199. class Property extends Node$1 {
  6200. bindAssignment () {
  6201. this.value.bindAssignment( UNKNOWN_ASSIGNMENT );
  6202. }
  6203. hasEffectsWhenAssigned ( options ) {
  6204. return this.value.hasEffectsWhenAssigned( options );
  6205. }
  6206. initialiseAndDeclare ( parentScope, kind, init ) {
  6207. this.initialiseScope( parentScope );
  6208. this.key.initialise( parentScope );
  6209. this.value.initialiseAndDeclare( parentScope, kind, init && UNKNOWN_ASSIGNMENT );
  6210. }
  6211. render ( code, es ) {
  6212. if ( !this.shorthand ) {
  6213. this.key.render( code, es );
  6214. }
  6215. this.value.render( code, es );
  6216. }
  6217. }
  6218. class RestElement extends Node$1 {
  6219. bindAssignment () {
  6220. this.argument.bindAssignment( UNKNOWN_ASSIGNMENT );
  6221. }
  6222. hasEffectsWhenAssigned ( options ) {
  6223. return this.argument.hasEffectsWhenAssigned( options );
  6224. }
  6225. initialiseAndDeclare ( parentScope, kind ) {
  6226. this.initialiseScope( parentScope );
  6227. this.argument.initialiseAndDeclare( parentScope, kind, UNKNOWN_ASSIGNMENT );
  6228. }
  6229. }
  6230. class ReturnStatement extends Statement {
  6231. hasEffects ( options ) {
  6232. return super.hasEffects( options )
  6233. || !options.ignoreReturnAwaitYield();
  6234. }
  6235. }
  6236. class SwitchCase extends Node$1 {
  6237. includeInBundle () {
  6238. if ( this.isFullyIncluded() ) { return false; }
  6239. let addedNewNodes = false;
  6240. if (this.test && this.test.includeInBundle()) {
  6241. addedNewNodes = true;
  6242. }
  6243. this.consequent.forEach( node => {
  6244. if ( node.shouldBeIncluded() ) {
  6245. if ( node.includeInBundle() ) {
  6246. addedNewNodes = true;
  6247. }
  6248. }
  6249. } );
  6250. if ( !this.included || addedNewNodes ) {
  6251. this.included = true;
  6252. return true;
  6253. }
  6254. return false;
  6255. }
  6256. }
  6257. class SwitchStatement extends Statement {
  6258. hasEffects ( options ) {
  6259. return super.hasEffects( options.setIgnoreBreakStatements() );
  6260. }
  6261. initialiseScope ( parentScope ) {
  6262. this.scope = new BlockScope( { parent: parentScope } );
  6263. }
  6264. }
  6265. class TaggedTemplateExpression extends Node$1 {
  6266. bind () {
  6267. if ( this.tag.type === 'Identifier' ) {
  6268. const variable = this.scope.findVariable( this.tag.name );
  6269. if ( variable.isNamespace ) {
  6270. this.module.error( {
  6271. code: 'CANNOT_CALL_NAMESPACE',
  6272. message: `Cannot call a namespace ('${this.tag.name}')`
  6273. }, this.start );
  6274. }
  6275. if ( this.tag.name === 'eval' && variable.isGlobal ) {
  6276. this.module.warn( {
  6277. code: 'EVAL',
  6278. message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
  6279. url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval'
  6280. }, this.start );
  6281. }
  6282. }
  6283. super.bind();
  6284. this.tag.bindCall( { withNew: false } );
  6285. }
  6286. hasEffects ( options ) {
  6287. return super.hasEffects( options )
  6288. || this.tag.hasEffectsWhenCalled( options.getHasEffectsWhenCalledOptions( this.tag ) );
  6289. }
  6290. }
  6291. class TemplateElement extends Node$1 {
  6292. hasEffects() {
  6293. return false;
  6294. }
  6295. }
  6296. class TemplateLiteral extends Node$1 {
  6297. render ( code, es ) {
  6298. code.indentExclusionRanges.push( [ this.start, this.end ] );
  6299. super.render( code, es );
  6300. }
  6301. }
  6302. class ThisExpression extends Node$1 {
  6303. initialiseNode () {
  6304. const lexicalBoundary = this.scope.findLexicalBoundary();
  6305. if ( lexicalBoundary.isModuleScope ) {
  6306. this.alias = this.module.context;
  6307. if ( this.alias === 'undefined' ) {
  6308. this.module.warn( {
  6309. code: 'THIS_IS_UNDEFINED',
  6310. message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`,
  6311. url: `https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined`
  6312. }, this.start );
  6313. }
  6314. }
  6315. }
  6316. bind () {
  6317. this.variable = this.scope.findVariable( 'this' );
  6318. }
  6319. hasEffectsWhenMutated ( options ) {
  6320. return !options.ignoreSafeThisMutations() || this.variable.hasEffectsWhenMutated( options );
  6321. }
  6322. render ( code ) {
  6323. if ( this.alias ) {
  6324. code.overwrite( this.start, this.end, this.alias, { storeName: true, contentOnly: false } );
  6325. }
  6326. }
  6327. }
  6328. class ThrowStatement extends Node$1 {
  6329. hasEffects () {
  6330. return true;
  6331. }
  6332. }
  6333. const operators$2 = {
  6334. '-': value => -value,
  6335. '+': value => +value,
  6336. '!': value => !value,
  6337. '~': value => ~value,
  6338. typeof: value => typeof value,
  6339. void: () => undefined,
  6340. delete: () => UNKNOWN_VALUE
  6341. };
  6342. class UnaryExpression extends Node$1 {
  6343. bind () {
  6344. if ( this.value === UNKNOWN_VALUE ) { super.bind(); }
  6345. }
  6346. getValue () {
  6347. const argumentValue = this.argument.getValue();
  6348. if ( argumentValue === UNKNOWN_VALUE ) { return UNKNOWN_VALUE; }
  6349. return operators$2[ this.operator ]( argumentValue );
  6350. }
  6351. hasEffects ( options ) {
  6352. return this.included
  6353. || this.argument.hasEffects( options )
  6354. || (this.operator === 'delete' && (
  6355. this.argument.type !== 'MemberExpression'
  6356. || this.argument.object.hasEffectsWhenMutated( options )
  6357. ));
  6358. }
  6359. hasEffectsAsExpressionStatement ( options ) {
  6360. return this.hasEffects( options );
  6361. }
  6362. initialiseNode () {
  6363. this.value = this.getValue();
  6364. }
  6365. }
  6366. class UpdateExpression extends Node$1 {
  6367. bind () {
  6368. disallowIllegalReassignment( this.scope, this.argument );
  6369. if ( this.argument.type === 'Identifier' ) {
  6370. const variable = this.scope.findVariable( this.argument.name );
  6371. variable.isReassigned = true;
  6372. }
  6373. super.bind();
  6374. }
  6375. hasEffects ( options ) {
  6376. return this.included || this.argument.hasEffectsWhenAssigned( options );
  6377. }
  6378. hasEffectsAsExpressionStatement ( options ) {
  6379. return this.hasEffects( options );
  6380. }
  6381. }
  6382. class VariableDeclarator extends Node$1 {
  6383. bindAssignment ( expression ) {
  6384. this.id.bindAssignment( expression );
  6385. }
  6386. initialiseDeclarator ( parentScope, kind ) {
  6387. this.initialiseScope( parentScope );
  6388. this.init && this.init.initialise( this.scope );
  6389. this.id.initialiseAndDeclare( this.scope, kind, this.init );
  6390. }
  6391. // TODO Deleting this does not break any tests. Find meaningful test or delete.
  6392. render ( code, es ) {
  6393. extractNames( this.id ).forEach( name => {
  6394. const variable = this.scope.findVariable( name );
  6395. if ( !es && variable.exportName && variable.isReassigned ) {
  6396. if ( this.init ) {
  6397. code.overwrite( this.start, this.id.end, variable.getName( es ) );
  6398. } else if ( this.module.bundle.treeshake ) {
  6399. code.remove( this.start, this.end );
  6400. }
  6401. }
  6402. } );
  6403. super.render( code, es );
  6404. }
  6405. }
  6406. function getSeparator ( code, start ) {
  6407. let c = start;
  6408. while ( c > 0 && code[ c - 1 ] !== '\n' ) {
  6409. c -= 1;
  6410. if ( code[ c ] === ';' || code[ c ] === '{' ) { return '; '; }
  6411. }
  6412. const lineStart = code.slice( c, start ).match( /^\s*/ )[ 0 ];
  6413. return `;\n${lineStart}`;
  6414. }
  6415. const forStatement = /^For(?:Of|In)?Statement/;
  6416. class VariableDeclaration extends Node$1 {
  6417. bindAssignment () {
  6418. this.eachChild( child => child.bindAssignment( UNKNOWN_ASSIGNMENT ) );
  6419. }
  6420. hasEffectsWhenAssigned () {
  6421. return false;
  6422. }
  6423. includeWithAllDeclarations () {
  6424. if ( this.isFullyIncluded() ) { return false; }
  6425. let addedNewNodes = false;
  6426. this.declarations.forEach( declarator => {
  6427. if ( declarator.includeInBundle() ) {
  6428. addedNewNodes = true;
  6429. }
  6430. } );
  6431. if ( !this.included || addedNewNodes ) {
  6432. this.included = true;
  6433. return true;
  6434. }
  6435. return false;
  6436. }
  6437. includeInBundle () {
  6438. if ( this.isFullyIncluded() ) { return false; }
  6439. let addedNewNodes = false;
  6440. this.declarations.forEach( declarator => {
  6441. if ( declarator.shouldBeIncluded() ) {
  6442. if ( declarator.includeInBundle() ) {
  6443. addedNewNodes = true;
  6444. }
  6445. }
  6446. } );
  6447. if ( !this.included || addedNewNodes ) {
  6448. this.included = true;
  6449. return true;
  6450. }
  6451. return false;
  6452. }
  6453. initialiseChildren () {
  6454. this.declarations.forEach( child => child.initialiseDeclarator( this.scope, this.kind ) );
  6455. }
  6456. render ( code, es ) {
  6457. const treeshake = this.module.bundle.treeshake;
  6458. let shouldSeparate = false;
  6459. let separator;
  6460. if ( this.scope.isModuleScope && !forStatement.test( this.parent.type ) ) {
  6461. shouldSeparate = true;
  6462. separator = getSeparator( this.module.code, this.start );
  6463. }
  6464. let c = this.start;
  6465. let empty = true;
  6466. for ( let i = 0; i < this.declarations.length; i += 1 ) {
  6467. const declarator = this.declarations[ i ];
  6468. const prefix = empty ? '' : separator; // TODO indentation
  6469. if ( declarator.id.type === 'Identifier' ) {
  6470. const variable = this.scope.findVariable( declarator.id.name );
  6471. const isExportedAndReassigned = !es && variable.exportName && variable.isReassigned;
  6472. if ( isExportedAndReassigned ) {
  6473. if ( declarator.init ) {
  6474. if ( shouldSeparate ) { code.overwrite( c, declarator.start, prefix ); }
  6475. c = declarator.end;
  6476. empty = false;
  6477. }
  6478. } else if ( !treeshake || variable.included ) {
  6479. if ( shouldSeparate ) { code.overwrite( c, declarator.start, `${prefix}${this.kind} ` ); } // TODO indentation
  6480. c = declarator.end;
  6481. empty = false;
  6482. }
  6483. } else {
  6484. const exportAssignments = [];
  6485. let isIncluded = false;
  6486. extractNames( declarator.id ).forEach( name => {
  6487. const variable = this.scope.findVariable( name );
  6488. const isExportedAndReassigned = !es && variable.exportName && variable.isReassigned;
  6489. if ( isExportedAndReassigned ) {
  6490. // code.overwrite( c, declarator.start, prefix );
  6491. // c = declarator.end;
  6492. // empty = false;
  6493. exportAssignments.push( 'TODO' );
  6494. } else if ( declarator.included ) {
  6495. isIncluded = true;
  6496. }
  6497. } );
  6498. if ( !treeshake || isIncluded ) {
  6499. if ( shouldSeparate ) { code.overwrite( c, declarator.start, `${prefix}${this.kind} ` ); } // TODO indentation
  6500. c = declarator.end;
  6501. empty = false;
  6502. }
  6503. if ( exportAssignments.length ) {
  6504. throw new Error( 'TODO' );
  6505. }
  6506. }
  6507. declarator.render( code, es );
  6508. }
  6509. if ( treeshake && empty ) {
  6510. code.remove( this.leadingCommentStart || this.start, this.next || this.end );
  6511. } else {
  6512. // always include a semi-colon (https://github.com/rollup/rollup/pull/1013),
  6513. // unless it's a var declaration in a loop head
  6514. const needsSemicolon = !forStatement.test( this.parent.type ) || this === this.parent.body;
  6515. if ( this.end > c ) {
  6516. code.overwrite( c, this.end, needsSemicolon ? ';' : '' );
  6517. } else if ( needsSemicolon ) {
  6518. this.insertSemicolon( code );
  6519. }
  6520. }
  6521. }
  6522. }
  6523. class WhileStatement extends Statement {
  6524. hasEffects ( options ) {
  6525. return (
  6526. this.included
  6527. || this.test.hasEffects( options )
  6528. || this.body.hasEffects( options.setIgnoreBreakStatements() )
  6529. );
  6530. }
  6531. }
  6532. class YieldExpression extends Node$1 {
  6533. hasEffects ( options ) {
  6534. return super.hasEffects( options )
  6535. || !options.ignoreReturnAwaitYield();
  6536. }
  6537. hasEffectsAsExpressionStatement ( options ) {
  6538. return this.hasEffects( options );
  6539. }
  6540. }
  6541. var nodes = {
  6542. ArrayExpression: Node$1,
  6543. ArrayPattern,
  6544. ArrowFunctionExpression,
  6545. AssignmentExpression,
  6546. AssignmentPattern,
  6547. AwaitExpression,
  6548. BinaryExpression,
  6549. BlockStatement,
  6550. BreakStatement,
  6551. CallExpression,
  6552. CatchClause,
  6553. ClassBody,
  6554. ClassDeclaration,
  6555. ClassExpression,
  6556. ConditionalExpression,
  6557. DoWhileStatement,
  6558. EmptyStatement,
  6559. ExportAllDeclaration,
  6560. ExportDefaultDeclaration,
  6561. ExportNamedDeclaration,
  6562. ExpressionStatement,
  6563. ForStatement,
  6564. ForInStatement,
  6565. ForOfStatement,
  6566. FunctionDeclaration,
  6567. FunctionExpression,
  6568. Identifier,
  6569. IfStatement,
  6570. ImportDeclaration,
  6571. LabeledStatement,
  6572. Literal,
  6573. LogicalExpression,
  6574. MemberExpression,
  6575. MethodDefinition,
  6576. NewExpression,
  6577. ObjectExpression,
  6578. ObjectPattern,
  6579. Property,
  6580. RestElement,
  6581. ReturnStatement,
  6582. SwitchCase,
  6583. SwitchStatement,
  6584. TaggedTemplateExpression,
  6585. TemplateElement,
  6586. TemplateLiteral,
  6587. ThisExpression,
  6588. ThrowStatement,
  6589. TryStatement: Statement,
  6590. UnaryExpression,
  6591. UpdateExpression,
  6592. VariableDeclarator,
  6593. VariableDeclaration,
  6594. WhileStatement,
  6595. YieldExpression
  6596. };
  6597. class UnknownNode extends Node$1 {
  6598. hasEffects () {
  6599. return true;
  6600. }
  6601. }
  6602. var keys$1 = {
  6603. Program: [ 'body' ],
  6604. Literal: []
  6605. };
  6606. const newline = /\n/;
  6607. function enhance ( ast, module, comments ) {
  6608. enhanceNode( ast, module, module, module.magicString );
  6609. let comment = comments.shift();
  6610. for ( const node of ast.body ) {
  6611. if ( comment && ( comment.start < node.start ) ) {
  6612. node.leadingCommentStart = comment.start;
  6613. }
  6614. while ( comment && comment.end < node.end ) { comment = comments.shift(); }
  6615. // if the next comment is on the same line as the end of the node,
  6616. // treat is as a trailing comment
  6617. if ( comment && !newline.test( module.code.slice( node.end, comment.start ) ) ) {
  6618. node.trailingCommentEnd = comment.end; // TODO is node.trailingCommentEnd used anywhere?
  6619. comment = comments.shift();
  6620. }
  6621. node.initialise( module.scope );
  6622. }
  6623. }
  6624. function enhanceNode ( raw, parent, module, code ) {
  6625. if ( !raw ) { return; }
  6626. if ( 'length' in raw ) {
  6627. for ( let i = 0; i < raw.length; i += 1 ) {
  6628. enhanceNode( raw[i], parent, module, code );
  6629. }
  6630. return;
  6631. }
  6632. // with e.g. shorthand properties, key and value are
  6633. // the same node. We don't want to enhance an object twice
  6634. if ( raw.__enhanced ) { return; }
  6635. raw.__enhanced = true;
  6636. if ( !keys$1[ raw.type ] ) {
  6637. keys$1[ raw.type ] = Object.keys( raw ).filter( key => typeof raw[ key ] === 'object' );
  6638. }
  6639. raw.parent = parent;
  6640. raw.module = module;
  6641. raw.keys = keys$1[ raw.type ];
  6642. code.addSourcemapLocation( raw.start );
  6643. code.addSourcemapLocation( raw.end );
  6644. for ( const key of keys$1[ raw.type ] ) {
  6645. enhanceNode( raw[ key ], raw, module, code );
  6646. }
  6647. const type = nodes[ raw.type ] || UnknownNode;
  6648. raw.__proto__ = type.prototype;
  6649. }
  6650. function clone ( node ) {
  6651. if ( !node ) { return node; }
  6652. if ( typeof node !== 'object' ) { return node; }
  6653. if ( Array.isArray( node ) ) {
  6654. const cloned = new Array( node.length );
  6655. for ( let i = 0; i < node.length; i += 1 ) { cloned[i] = clone( node[i] ); }
  6656. return cloned;
  6657. }
  6658. const cloned = {};
  6659. for ( const key in node ) {
  6660. cloned[ key ] = clone( node[ key ] );
  6661. }
  6662. return cloned;
  6663. }
  6664. class ModuleScope extends Scope {
  6665. constructor ( module ) {
  6666. super( {
  6667. isModuleScope: true,
  6668. parent: module.bundle.scope
  6669. } );
  6670. this.module = module;
  6671. this.variables.this = new LocalVariable( 'this', null, UNDEFINED_ASSIGNMENT );
  6672. }
  6673. deshadow ( names ) {
  6674. names = new Set( names );
  6675. forOwn( this.module.imports, specifier => {
  6676. if ( specifier.module.isExternal ) { return; }
  6677. const addDeclaration = declaration => {
  6678. if ( declaration.isNamespace && !declaration.isExternal ) {
  6679. declaration.module.getExports().forEach( name => {
  6680. addDeclaration( declaration.module.traceExport( name ) );
  6681. } );
  6682. }
  6683. names.add( declaration.name );
  6684. };
  6685. specifier.module.getExports().forEach( name => {
  6686. addDeclaration( specifier.module.traceExport( name ) );
  6687. } );
  6688. if ( specifier.name !== '*' ) {
  6689. const declaration = specifier.module.traceExport( specifier.name );
  6690. if ( !declaration ) {
  6691. this.module.warn( {
  6692. code: 'NON_EXISTENT_EXPORT',
  6693. name: specifier.name,
  6694. source: specifier.module.id,
  6695. message: `Non-existent export '${specifier.name}' is imported from ${relativeId( specifier.module.id )}`
  6696. }, specifier.specifier.start );
  6697. return;
  6698. }
  6699. const name = declaration.getName( true );
  6700. if ( name !== specifier.name ) {
  6701. names.add( declaration.getName( true ) );
  6702. }
  6703. if ( specifier.name !== 'default' && specifier.specifier.imported.name !== specifier.specifier.local.name ) {
  6704. names.add( specifier.specifier.imported.name );
  6705. }
  6706. }
  6707. } );
  6708. super.deshadow( names );
  6709. }
  6710. findLexicalBoundary () {
  6711. return this;
  6712. }
  6713. findVariable ( name ) {
  6714. if ( this.variables[ name ] ) {
  6715. return this.variables[ name ];
  6716. }
  6717. return this.module.trace( name ) || this.parent.findVariable( name );
  6718. }
  6719. }
  6720. function tryParse ( module, acornOptions ) {
  6721. try {
  6722. return parse( module.code, assign( {
  6723. ecmaVersion: 8,
  6724. sourceType: 'module',
  6725. onComment: ( block, text, start, end ) => module.comments.push( { block, text, start, end } ),
  6726. preserveParens: false
  6727. }, acornOptions ) );
  6728. } catch ( err ) {
  6729. module.error( {
  6730. code: 'PARSE_ERROR',
  6731. message: err.message.replace( / \(\d+:\d+\)$/, '' )
  6732. }, err.pos );
  6733. }
  6734. }
  6735. function includeFully ( node ) {
  6736. node.includeInBundle();
  6737. node.eachChild( includeFully );
  6738. }
  6739. class Module {
  6740. constructor ( ref ) {
  6741. var id = ref.id;
  6742. var code = ref.code;
  6743. var originalCode = ref.originalCode;
  6744. var originalSourcemap = ref.originalSourcemap;
  6745. var ast = ref.ast;
  6746. var sourcemapChain = ref.sourcemapChain;
  6747. var resolvedIds = ref.resolvedIds;
  6748. var resolvedExternalIds = ref.resolvedExternalIds;
  6749. var bundle = ref.bundle;
  6750. this.code = code;
  6751. this.id = id;
  6752. this.bundle = bundle;
  6753. this.originalCode = originalCode;
  6754. this.originalSourcemap = originalSourcemap;
  6755. this.sourcemapChain = sourcemapChain;
  6756. this.comments = [];
  6757. timeStart( 'ast' );
  6758. if ( ast ) {
  6759. // prevent mutating the provided AST, as it may be reused on
  6760. // subsequent incremental rebuilds
  6761. this.ast = clone( ast );
  6762. this.astClone = ast;
  6763. } else {
  6764. this.ast = tryParse( this, bundle.acornOptions ); // TODO what happens to comments if AST is provided?
  6765. this.astClone = clone( this.ast );
  6766. }
  6767. timeEnd( 'ast' );
  6768. this.excludeFromSourcemap = /\0/.test( id );
  6769. this.context = bundle.getModuleContext( id );
  6770. // all dependencies
  6771. this.sources = [];
  6772. this.dependencies = [];
  6773. this.resolvedIds = resolvedIds || blank();
  6774. this.resolvedExternalIds = resolvedExternalIds || blank();
  6775. // imports and exports, indexed by local name
  6776. this.imports = blank();
  6777. this.exports = blank();
  6778. this.exportsAll = blank();
  6779. this.reexports = blank();
  6780. this.exportAllSources = [];
  6781. this.exportAllModules = null;
  6782. // By default, `id` is the filename. Custom resolvers and loaders
  6783. // can change that, but it makes sense to use it for the source filename
  6784. this.magicString = new MagicString$1( code, {
  6785. filename: this.excludeFromSourcemap ? null : id, // don't include plugin helpers in sourcemap
  6786. indentExclusionRanges: []
  6787. } );
  6788. // remove existing sourceMappingURL comments
  6789. this.comments = this.comments.filter( comment => {
  6790. //only one line comment can contain source maps
  6791. const isSourceMapComment = !comment.block && SOURCEMAPPING_URL_RE.test( comment.text );
  6792. if ( isSourceMapComment ) {
  6793. this.magicString.remove( comment.start, comment.end );
  6794. }
  6795. return !isSourceMapComment;
  6796. } );
  6797. this.declarations = blank();
  6798. this.type = 'Module'; // TODO only necessary so that Scope knows this should be treated as a function scope... messy
  6799. this.scope = new ModuleScope( this );
  6800. timeStart( 'analyse' );
  6801. this.analyse();
  6802. timeEnd( 'analyse' );
  6803. this.strongDependencies = [];
  6804. }
  6805. addExport ( node ) {
  6806. const source = node.source && node.source.value;
  6807. // export { name } from './other.js'
  6808. if ( source ) {
  6809. if ( !~this.sources.indexOf( source ) ) { this.sources.push( source ); }
  6810. if ( node.type === 'ExportAllDeclaration' ) {
  6811. // Store `export * from '...'` statements in an array of delegates.
  6812. // When an unknown import is encountered, we see if one of them can satisfy it.
  6813. this.exportAllSources.push( source );
  6814. }
  6815. else {
  6816. node.specifiers.forEach( specifier => {
  6817. const name = specifier.exported.name;
  6818. if ( this.exports[ name ] || this.reexports[ name ] ) {
  6819. this.error( {
  6820. code: 'DUPLICATE_EXPORT',
  6821. message: `A module cannot have multiple exports with the same name ('${name}')`
  6822. }, specifier.start );
  6823. }
  6824. this.reexports[ name ] = {
  6825. start: specifier.start,
  6826. source,
  6827. localName: specifier.local.name,
  6828. module: null // filled in later
  6829. };
  6830. } );
  6831. }
  6832. }
  6833. // export default function foo () {}
  6834. // export default foo;
  6835. // export default 42;
  6836. else if ( node.type === 'ExportDefaultDeclaration' ) {
  6837. const identifier = ( node.declaration.id && node.declaration.id.name ) || node.declaration.name;
  6838. if ( this.exports.default ) {
  6839. this.error( {
  6840. code: 'DUPLICATE_EXPORT',
  6841. message: `A module can only have one default export`
  6842. }, node.start );
  6843. }
  6844. this.exports.default = {
  6845. localName: 'default',
  6846. identifier
  6847. };
  6848. }
  6849. // export var { foo, bar } = ...
  6850. // export var foo = 42;
  6851. // export var a = 1, b = 2, c = 3;
  6852. // export function foo () {}
  6853. else if ( node.declaration ) {
  6854. const declaration = node.declaration;
  6855. if ( declaration.type === 'VariableDeclaration' ) {
  6856. declaration.declarations.forEach( decl => {
  6857. extractNames( decl.id ).forEach( localName => {
  6858. this.exports[ localName ] = { localName };
  6859. } );
  6860. } );
  6861. } else {
  6862. // export function foo () {}
  6863. const localName = declaration.id.name;
  6864. this.exports[ localName ] = { localName };
  6865. }
  6866. }
  6867. // export { foo, bar, baz }
  6868. else {
  6869. node.specifiers.forEach( specifier => {
  6870. const localName = specifier.local.name;
  6871. const exportedName = specifier.exported.name;
  6872. if ( this.exports[ exportedName ] || this.reexports[ exportedName ] ) {
  6873. this.error( {
  6874. code: 'DUPLICATE_EXPORT',
  6875. message: `A module cannot have multiple exports with the same name ('${exportedName}')`
  6876. }, specifier.start );
  6877. }
  6878. this.exports[ exportedName ] = { localName };
  6879. } );
  6880. }
  6881. }
  6882. addImport ( node ) {
  6883. const source = node.source.value;
  6884. if ( !~this.sources.indexOf( source ) ) { this.sources.push( source ); }
  6885. node.specifiers.forEach( specifier => {
  6886. const localName = specifier.local.name;
  6887. if ( this.imports[ localName ] ) {
  6888. this.error( {
  6889. code: 'DUPLICATE_IMPORT',
  6890. message: `Duplicated import '${localName}'`
  6891. }, specifier.start );
  6892. }
  6893. const isDefault = specifier.type === 'ImportDefaultSpecifier';
  6894. const isNamespace = specifier.type === 'ImportNamespaceSpecifier';
  6895. const name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name;
  6896. this.imports[ localName ] = { source, specifier, name, module: null };
  6897. } );
  6898. }
  6899. analyse () {
  6900. enhance( this.ast, this, this.comments );
  6901. // discover this module's imports and exports
  6902. let lastNode;
  6903. for ( const node of this.ast.body ) {
  6904. if ( node.isImportDeclaration ) {
  6905. this.addImport( node );
  6906. } else if ( node.isExportDeclaration ) {
  6907. this.addExport( node );
  6908. }
  6909. if ( lastNode ) { lastNode.next = node.leadingCommentStart || node.start; }
  6910. lastNode = node;
  6911. }
  6912. }
  6913. basename () {
  6914. const base = basename( this.id );
  6915. const ext = extname( this.id );
  6916. return makeLegal( ext ? base.slice( 0, -ext.length ) : base );
  6917. }
  6918. bindImportSpecifiers () {
  6919. [ this.imports, this.reexports ].forEach( specifiers => {
  6920. keys( specifiers ).forEach( name => {
  6921. const specifier = specifiers[ name ];
  6922. const id = this.resolvedIds[ specifier.source ] || this.resolvedExternalIds[ specifier.source ];
  6923. specifier.module = this.bundle.moduleById.get( id );
  6924. } );
  6925. } );
  6926. this.exportAllModules = this.exportAllSources.map( source => {
  6927. const id = this.resolvedIds[ source ] || this.resolvedExternalIds[ source ];
  6928. return this.bundle.moduleById.get( id );
  6929. } );
  6930. this.sources.forEach( source => {
  6931. const id = this.resolvedIds[ source ];
  6932. if ( id ) {
  6933. const module = this.bundle.moduleById.get( id );
  6934. this.dependencies.push( module );
  6935. }
  6936. } );
  6937. }
  6938. bindReferences () {
  6939. for ( const node of this.ast.body ) {
  6940. node.bind();
  6941. }
  6942. // if ( this.declarations.default ) {
  6943. // if ( this.exports.default.identifier ) {
  6944. // const declaration = this.trace( this.exports.default.identifier );
  6945. // if ( declaration ) this.declarations.default.bind( declaration );
  6946. // }
  6947. // }
  6948. }
  6949. error ( props, pos ) {
  6950. if ( pos !== undefined ) {
  6951. props.pos = pos;
  6952. var ref = locate( this.code, pos, { offsetLine: 1 } );
  6953. var line = ref.line;
  6954. var column = ref.column; // TODO trace sourcemaps
  6955. props.loc = { file: this.id, line, column };
  6956. props.frame = getCodeFrame( this.code, line, column );
  6957. }
  6958. error( props );
  6959. }
  6960. getExports () {
  6961. return keys( this.exports );
  6962. }
  6963. getReexports () {
  6964. const reexports = blank();
  6965. keys( this.reexports ).forEach( name => {
  6966. reexports[ name ] = true;
  6967. } );
  6968. this.exportAllModules.forEach( module => {
  6969. if ( module.isExternal ) {
  6970. reexports[ `*${module.id}` ] = true;
  6971. return;
  6972. }
  6973. module.getExports().concat( module.getReexports() ).forEach( name => {
  6974. if ( name !== 'default' ) { reexports[ name ] = true; }
  6975. } );
  6976. } );
  6977. return keys( reexports );
  6978. }
  6979. includeAllInBundle () {
  6980. this.ast.body.forEach( includeFully );
  6981. }
  6982. includeInBundle () {
  6983. let addedNewNodes = false;
  6984. this.ast.body.forEach( node => {
  6985. if ( node.shouldBeIncluded() ) {
  6986. if ( node.includeInBundle() ) {
  6987. addedNewNodes = true;
  6988. }
  6989. }
  6990. } );
  6991. return addedNewNodes;
  6992. }
  6993. namespace () {
  6994. if ( !this.declarations[ '*' ] ) {
  6995. this.declarations[ '*' ] = new NamespaceVariable( this );
  6996. }
  6997. return this.declarations[ '*' ];
  6998. }
  6999. render ( es, legacy ) {
  7000. const magicString = this.magicString.clone();
  7001. for ( const node of this.ast.body ) {
  7002. node.render( magicString, es );
  7003. }
  7004. if ( this.namespace().needsNamespaceBlock ) {
  7005. magicString.append( '\n\n' + this.namespace().renderBlock( es, legacy, '\t' ) ); // TODO use correct indentation
  7006. }
  7007. return magicString.trim();
  7008. }
  7009. toJSON () {
  7010. return {
  7011. id: this.id,
  7012. dependencies: this.dependencies.map( module => module.id ),
  7013. code: this.code,
  7014. originalCode: this.originalCode,
  7015. originalSourcemap: this.originalSourcemap,
  7016. ast: this.astClone,
  7017. sourcemapChain: this.sourcemapChain,
  7018. resolvedIds: this.resolvedIds,
  7019. resolvedExternalIds: this.resolvedExternalIds
  7020. };
  7021. }
  7022. trace ( name ) {
  7023. // TODO this is slightly circular
  7024. if ( name in this.scope.variables ) {
  7025. return this.scope.variables[ name ];
  7026. }
  7027. if ( name in this.imports ) {
  7028. const importDeclaration = this.imports[ name ];
  7029. const otherModule = importDeclaration.module;
  7030. if ( importDeclaration.name === '*' && !otherModule.isExternal ) {
  7031. return otherModule.namespace();
  7032. }
  7033. const declaration = otherModule.traceExport( importDeclaration.name );
  7034. if ( !declaration ) {
  7035. this.error( {
  7036. code: 'MISSING_EXPORT',
  7037. message: `'${importDeclaration.name}' is not exported by ${relativeId( otherModule.id )}`,
  7038. url: `https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module`
  7039. }, importDeclaration.specifier.start );
  7040. }
  7041. return declaration;
  7042. }
  7043. return null;
  7044. }
  7045. traceExport ( name ) {
  7046. // export * from 'external'
  7047. if ( name[ 0 ] === '*' ) {
  7048. const module = this.bundle.moduleById.get( name.slice( 1 ) );
  7049. return module.traceExport( '*' );
  7050. }
  7051. // export { foo } from './other.js'
  7052. const reexportDeclaration = this.reexports[ name ];
  7053. if ( reexportDeclaration ) {
  7054. const declaration = reexportDeclaration.module.traceExport( reexportDeclaration.localName );
  7055. if ( !declaration ) {
  7056. this.error( {
  7057. code: 'MISSING_EXPORT',
  7058. message: `'${reexportDeclaration.localName}' is not exported by ${relativeId( reexportDeclaration.module.id )}`,
  7059. url: `https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module`
  7060. }, reexportDeclaration.start );
  7061. }
  7062. return declaration;
  7063. }
  7064. const exportDeclaration = this.exports[ name ];
  7065. if ( exportDeclaration ) {
  7066. const name = exportDeclaration.localName;
  7067. const declaration = this.trace( name );
  7068. return declaration || this.bundle.scope.findVariable( name );
  7069. }
  7070. if ( name === 'default' ) { return; }
  7071. for ( let i = 0; i < this.exportAllModules.length; i += 1 ) {
  7072. const module = this.exportAllModules[ i ];
  7073. const declaration = module.traceExport( name );
  7074. if ( declaration ) { return declaration; }
  7075. }
  7076. }
  7077. warn ( warning, pos ) {
  7078. if ( pos !== undefined ) {
  7079. warning.pos = pos;
  7080. var ref = locate( this.code, pos, { offsetLine: 1 } );
  7081. var line = ref.line;
  7082. var column = ref.column; // TODO trace sourcemaps
  7083. warning.loc = { file: this.id, line, column };
  7084. warning.frame = getCodeFrame( this.code, line, column );
  7085. }
  7086. warning.id = this.id;
  7087. this.bundle.warn( warning );
  7088. }
  7089. }
  7090. class ExternalVariable extends Variable {
  7091. constructor ( module, name ) {
  7092. super( name );
  7093. this.module = module;
  7094. this.safeName = null;
  7095. this.isExternal = true;
  7096. this.isNamespace = name === '*';
  7097. }
  7098. addReference ( reference ) {
  7099. if ( this.name === 'default' || this.name === '*' ) {
  7100. this.module.suggestName( reference.name );
  7101. }
  7102. }
  7103. getName ( es ) {
  7104. if ( this.name === '*' ) {
  7105. return this.module.name;
  7106. }
  7107. if ( this.name === 'default' ) {
  7108. return this.module.exportsNamespace || ( !es && this.module.exportsNames ) ?
  7109. `${this.module.name}__default` :
  7110. this.module.name;
  7111. }
  7112. return es ? this.safeName : `${this.module.name}.${this.name}`;
  7113. }
  7114. includeDeclaration () {
  7115. if ( this.included ) {
  7116. return false;
  7117. }
  7118. this.included = true;
  7119. this.module.used = true;
  7120. return true;
  7121. }
  7122. setSafeName ( name ) {
  7123. this.safeName = name;
  7124. }
  7125. }
  7126. class ExternalModule {
  7127. constructor ( id ) {
  7128. this.id = id;
  7129. const parts = id.split( /[\\/]/ );
  7130. this.name = makeLegal( parts.pop() );
  7131. this.nameSuggestions = blank();
  7132. this.mostCommonSuggestion = 0;
  7133. this.isExternal = true;
  7134. this.used = false;
  7135. this.declarations = blank();
  7136. this.exportsNames = false;
  7137. }
  7138. suggestName ( name ) {
  7139. if ( !this.nameSuggestions[ name ] ) { this.nameSuggestions[ name ] = 0; }
  7140. this.nameSuggestions[ name ] += 1;
  7141. if ( this.nameSuggestions[ name ] > this.mostCommonSuggestion ) {
  7142. this.mostCommonSuggestion = this.nameSuggestions[ name ];
  7143. this.name = name;
  7144. }
  7145. }
  7146. traceExport ( name ) {
  7147. if ( name !== 'default' && name !== '*' ) { this.exportsNames = true; }
  7148. if ( name === '*' ) { this.exportsNamespace = true; }
  7149. return this.declarations[ name ]
  7150. || (this.declarations[ name ] = new ExternalVariable( this, name ));
  7151. }
  7152. }
  7153. function getInteropBlock ( bundle, options ) {
  7154. return bundle.externalModules
  7155. .map( module => {
  7156. if ( !module.declarations.default || options.interop === false ) { return null; }
  7157. if ( module.exportsNamespace ) {
  7158. return `${bundle.varOrConst} ${module.name}__default = ${module.name}['default'];`;
  7159. }
  7160. if ( module.exportsNames ) {
  7161. return `${bundle.varOrConst} ${module.name}__default = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};`;
  7162. }
  7163. return `${module.name} = ${module.name} && ${module.name}.hasOwnProperty('default') ? ${module.name}['default'] : ${module.name};`;
  7164. })
  7165. .filter( Boolean )
  7166. .join( '\n' );
  7167. }
  7168. function getExportBlock ( bundle, exportMode, mechanism ) {
  7169. if ( mechanism === void 0 ) mechanism = 'return';
  7170. const entryModule = bundle.entryModule;
  7171. if ( exportMode === 'default' ) {
  7172. return `${mechanism} ${entryModule.traceExport( 'default' ).getName( false )};`;
  7173. }
  7174. const exports = entryModule.getExports().concat( entryModule.getReexports() )
  7175. .map( name => {
  7176. if ( name[0] === '*' ) {
  7177. // export all from external
  7178. const id = name.slice( 1 );
  7179. const module = bundle.moduleById.get( id );
  7180. return `Object.keys(${module.name}).forEach(function (key) { exports[key] = ${module.name}[key]; });`;
  7181. }
  7182. const prop = name === 'default' ? `['default']` : `.${name}`;
  7183. const declaration = entryModule.traceExport( name );
  7184. const lhs = `exports${prop}`;
  7185. const rhs = declaration ?
  7186. declaration.getName( false ) :
  7187. name; // exporting a global
  7188. // prevent `exports.count = exports.count`
  7189. if ( lhs === rhs ) { return null; }
  7190. return `${lhs} = ${rhs};`;
  7191. });
  7192. return exports
  7193. .filter( Boolean )
  7194. .join( '\n' );
  7195. }
  7196. var esModuleExport = `Object.defineProperty(exports, '__esModule', { value: true });`;
  7197. const builtins$1 = {
  7198. process: true,
  7199. events: true,
  7200. stream: true,
  7201. util: true,
  7202. path: true,
  7203. buffer: true,
  7204. querystring: true,
  7205. url: true,
  7206. string_decoder: true,
  7207. punycode: true,
  7208. http: true,
  7209. https: true,
  7210. os: true,
  7211. assert: true,
  7212. constants: true,
  7213. timers: true,
  7214. console: true,
  7215. vm: true,
  7216. zlib: true,
  7217. tty: true,
  7218. domain: true
  7219. };
  7220. // Creating a browser bundle that depends on Node.js built-in modules ('util'). You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins
  7221. function warnOnBuiltins ( bundle ) {
  7222. const externalBuiltins = bundle.externalModules
  7223. .filter( mod => mod.id in builtins$1 )
  7224. .map( mod => mod.id );
  7225. if ( !externalBuiltins.length ) { return; }
  7226. const detail = externalBuiltins.length === 1 ?
  7227. `module ('${externalBuiltins[0]}')` :
  7228. `modules (${externalBuiltins.slice( 0, -1 ).map( name => `'${name}'` ).join( ', ' )} and '${externalBuiltins.slice( -1 )}')`;
  7229. bundle.warn({
  7230. code: 'MISSING_NODE_BUILTINS',
  7231. modules: externalBuiltins,
  7232. message: `Creating a browser bundle that depends on Node.js built-in ${detail}. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins`
  7233. });
  7234. }
  7235. function amd ( bundle, magicString, ref, options ) {
  7236. var exportMode = ref.exportMode;
  7237. var getPath = ref.getPath;
  7238. var indentString = ref.indentString;
  7239. var intro = ref.intro;
  7240. var outro = ref.outro;
  7241. warnOnBuiltins( bundle );
  7242. const deps = bundle.externalModules.map( m => `'${getPath(m.id)}'` );
  7243. const args = bundle.externalModules.map( m => m.name );
  7244. if ( exportMode === 'named' ) {
  7245. args.unshift( `exports` );
  7246. deps.unshift( `'exports'` );
  7247. }
  7248. const amdOptions = options.amd || {};
  7249. const params =
  7250. ( amdOptions.id ? `'${amdOptions.id}', ` : `` ) +
  7251. ( deps.length ? `[${deps.join( ', ' )}], ` : `` );
  7252. const useStrict = options.strict !== false ? ` 'use strict';` : ``;
  7253. const define = amdOptions.define || 'define';
  7254. const wrapperStart = `${define}(${params}function (${args.join( ', ' )}) {${useStrict}\n\n`;
  7255. // var foo__default = 'default' in foo ? foo['default'] : foo;
  7256. const interopBlock = getInteropBlock( bundle, options );
  7257. if ( interopBlock ) { magicString.prepend( interopBlock + '\n\n' ); }
  7258. if ( intro ) { magicString.prepend( intro ); }
  7259. const exportBlock = getExportBlock( bundle, exportMode );
  7260. if ( exportBlock ) { magicString.append( '\n\n' + exportBlock ); }
  7261. if ( exportMode === 'named' && options.legacy !== true ) { magicString.append( `\n\n${esModuleExport}` ); }
  7262. if ( outro ) { magicString.append( outro ); }
  7263. return magicString
  7264. .indent( indentString )
  7265. .append( '\n\n});' )
  7266. .prepend( wrapperStart );
  7267. }
  7268. function cjs ( bundle, magicString, ref, options ) {
  7269. var exportMode = ref.exportMode;
  7270. var getPath = ref.getPath;
  7271. var intro = ref.intro;
  7272. var outro = ref.outro;
  7273. intro = ( options.strict === false ? intro : `'use strict';\n\n${intro}` ) +
  7274. ( exportMode === 'named' && options.legacy !== true ? `${esModuleExport}\n\n` : '' );
  7275. let needsInterop = false;
  7276. const varOrConst = bundle.varOrConst;
  7277. const interop = options.interop !== false;
  7278. // TODO handle empty imports, once they're supported
  7279. const importBlock = bundle.externalModules
  7280. .map( module => {
  7281. if ( interop && module.declarations.default ) {
  7282. if ( module.exportsNamespace ) {
  7283. return `${varOrConst} ${module.name} = require('${getPath(module.id)}');` +
  7284. `\n${varOrConst} ${module.name}__default = ${module.name}['default'];`;
  7285. }
  7286. needsInterop = true;
  7287. if ( module.exportsNames ) {
  7288. return `${varOrConst} ${module.name} = require('${getPath(module.id)}');` +
  7289. `\n${varOrConst} ${module.name}__default = _interopDefault(${module.name});`;
  7290. }
  7291. return `${varOrConst} ${module.name} = _interopDefault(require('${getPath(module.id)}'));`;
  7292. } else {
  7293. const includedDeclarations = Object.keys( module.declarations )
  7294. .filter( name => module.declarations[ name ].included );
  7295. const needsVar = includedDeclarations.length || module.reexported;
  7296. return needsVar ?
  7297. `${varOrConst} ${module.name} = require('${getPath(module.id)}');` :
  7298. `require('${getPath(module.id)}');`;
  7299. }
  7300. })
  7301. .join( '\n' );
  7302. if ( needsInterop ) {
  7303. intro += `function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n`;
  7304. }
  7305. if ( importBlock ) {
  7306. intro += importBlock + '\n\n';
  7307. }
  7308. magicString.prepend( intro );
  7309. const exportBlock = getExportBlock( bundle, exportMode, 'module.exports =' );
  7310. if ( exportBlock ) { magicString.append( '\n\n' + exportBlock ); }
  7311. if ( outro ) { magicString.append( outro ); }
  7312. return magicString;
  7313. }
  7314. function notDefault ( name ) {
  7315. return name !== 'default';
  7316. }
  7317. function es ( bundle, magicString, ref ) {
  7318. var getPath = ref.getPath;
  7319. var intro = ref.intro;
  7320. var outro = ref.outro;
  7321. const importBlock = bundle.externalModules
  7322. .map( module => {
  7323. const specifiers = [];
  7324. const specifiersList = [specifiers];
  7325. const importedNames = keys( module.declarations )
  7326. .filter( name => name !== '*' && name !== 'default' )
  7327. .filter( name => module.declarations[ name ].included )
  7328. .map( name => {
  7329. if ( name[0] === '*' ) {
  7330. return `* as ${module.name}`;
  7331. }
  7332. const declaration = module.declarations[ name ];
  7333. if ( declaration.name === declaration.safeName ) { return declaration.name; }
  7334. return `${declaration.name} as ${declaration.safeName}`;
  7335. })
  7336. .filter( Boolean );
  7337. if ( module.declarations.default ) {
  7338. if ( module.exportsNamespace ) {
  7339. specifiersList.push([ `${module.name}__default` ]);
  7340. } else {
  7341. specifiers.push( module.name );
  7342. }
  7343. }
  7344. const namespaceSpecifier = module.declarations['*'] && module.declarations['*'].included ? `* as ${module.name}` : null; // TODO prevent unnecessary namespace import, e.g form/external-imports
  7345. const namedSpecifier = importedNames.length ? `{ ${importedNames.sort().join( ', ' )} }` : null;
  7346. if ( namespaceSpecifier && namedSpecifier ) {
  7347. // Namespace and named specifiers cannot be combined.
  7348. specifiersList.push( [namespaceSpecifier] );
  7349. specifiers.push( namedSpecifier );
  7350. } else if ( namedSpecifier ) {
  7351. specifiers.push( namedSpecifier );
  7352. } else if ( namespaceSpecifier ) {
  7353. specifiers.push( namespaceSpecifier );
  7354. }
  7355. return specifiersList
  7356. .map( specifiers => {
  7357. if ( specifiers.length ) {
  7358. return `import ${specifiers.join( ', ' )} from '${getPath(module.id)}';`;
  7359. }
  7360. return module.reexported ?
  7361. null :
  7362. `import '${getPath(module.id)}';`;
  7363. })
  7364. .filter( Boolean )
  7365. .join( '\n' );
  7366. })
  7367. .join( '\n' );
  7368. if ( importBlock ) { intro += importBlock + '\n\n'; }
  7369. if ( intro ) { magicString.prepend( intro ); }
  7370. const module = bundle.entryModule;
  7371. const exportInternalSpecifiers = [];
  7372. const exportExternalSpecifiers = new Map();
  7373. const exportAllDeclarations = [];
  7374. module.getExports()
  7375. .filter( notDefault )
  7376. .forEach( name => {
  7377. const declaration = module.traceExport( name );
  7378. const rendered = declaration.getName( true );
  7379. exportInternalSpecifiers.push( rendered === name ? name : `${rendered} as ${name}` );
  7380. });
  7381. module.getReexports()
  7382. .filter( notDefault )
  7383. .forEach( name => {
  7384. const declaration = module.traceExport( name );
  7385. if ( declaration.isExternal ) {
  7386. if ( name[0] === '*' ) {
  7387. // export * from 'external'
  7388. exportAllDeclarations.push( `export * from '${name.slice( 1 )}';` );
  7389. } else {
  7390. if ( !exportExternalSpecifiers.has( declaration.module.id ) ) { exportExternalSpecifiers.set( declaration.module.id, [] ); }
  7391. exportExternalSpecifiers.get( declaration.module.id ).push( name );
  7392. }
  7393. return;
  7394. }
  7395. const rendered = declaration.getName( true );
  7396. exportInternalSpecifiers.push( rendered === name ? name : `${rendered} as ${name}` );
  7397. });
  7398. const exportBlock = [];
  7399. if ( exportInternalSpecifiers.length ) { exportBlock.push( `export { ${exportInternalSpecifiers.join(', ')} };` ); }
  7400. if ( module.exports.default || module.reexports.default ) { exportBlock.push( `export default ${module.traceExport( 'default' ).getName( true )};` ); }
  7401. if ( exportAllDeclarations.length ) { exportBlock.push( exportAllDeclarations.join( '\n' ) ); }
  7402. if ( exportExternalSpecifiers.size ) {
  7403. exportExternalSpecifiers.forEach( ( specifiers, id ) => {
  7404. exportBlock.push( `export { ${specifiers.join( ', ' )} } from '${id}';` );
  7405. });
  7406. }
  7407. if ( exportBlock.length ) { magicString.append( '\n\n' + exportBlock.join( '\n' ).trim() ); }
  7408. if ( outro ) { magicString.append( outro ); }
  7409. return magicString.trim();
  7410. }
  7411. function getGlobalNameMaker ( globals, bundle, fallback ) {
  7412. if ( fallback === void 0 ) fallback = null;
  7413. const fn = typeof globals === 'function' ? globals : id => globals[ id ];
  7414. return function ( module ) {
  7415. const name = fn( module.id );
  7416. if ( name ) { return name; }
  7417. if ( Object.keys( module.declarations ).length > 0 ) {
  7418. bundle.warn({
  7419. code: 'MISSING_GLOBAL_NAME',
  7420. source: module.id,
  7421. guess: module.name,
  7422. message: `No name was provided for external module '${module.id}' in options.globals – guessing '${module.name}'`
  7423. });
  7424. return module.name;
  7425. }
  7426. return fallback;
  7427. };
  7428. }
  7429. // Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
  7430. // if the property name isn't trivial
  7431. const shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/;
  7432. function property ( prop ) {
  7433. return shouldUseDot.test( prop ) ? `.${prop}` : `['${prop}']`;
  7434. }
  7435. function keypath ( keypath ) {
  7436. return keypath.split( '.' ).map( property ).join( '' );
  7437. }
  7438. function trimEmptyImports ( modules ) {
  7439. let i = modules.length;
  7440. while ( i-- ) {
  7441. const module = modules[i];
  7442. if ( Object.keys( module.declarations ).length > 0 ) {
  7443. return modules.slice( 0, i + 1 );
  7444. }
  7445. }
  7446. return [];
  7447. }
  7448. function setupNamespace ( keypath$$1 ) {
  7449. const parts = keypath$$1.split( '.' );
  7450. parts.pop();
  7451. let acc = 'this';
  7452. return parts
  7453. .map( part => ( acc += property( part ), `${acc} = ${acc} || {};` ) )
  7454. .join( '\n' ) + '\n';
  7455. }
  7456. const thisProp = name => `this${keypath( name )}`;
  7457. function iife ( bundle, magicString, ref, options ) {
  7458. var exportMode = ref.exportMode;
  7459. var indentString = ref.indentString;
  7460. var intro = ref.intro;
  7461. var outro = ref.outro;
  7462. const globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle, 'null' );
  7463. var extend = options.extend;
  7464. var name = options.name;
  7465. const isNamespaced = name && name.indexOf( '.' ) !== -1;
  7466. const possibleVariableAssignment = !extend && !isNamespaced;
  7467. if ( name && possibleVariableAssignment && !isLegal(name) ) {
  7468. error({
  7469. code: 'ILLEGAL_IDENTIFIER_AS_NAME',
  7470. message: `Given name (${name}) is not legal JS identifier. If you need this you can try --extend option`
  7471. });
  7472. }
  7473. warnOnBuiltins( bundle );
  7474. const external = trimEmptyImports( bundle.externalModules );
  7475. const dependencies = external.map( globalNameMaker );
  7476. const args = external.map( m => m.name );
  7477. if ( exportMode !== 'none' && !name ) {
  7478. error({
  7479. code: 'INVALID_OPTION',
  7480. message: `You must supply options.name for IIFE bundles`
  7481. });
  7482. }
  7483. if ( extend ) {
  7484. dependencies.unshift( `(${thisProp(name)} = ${thisProp(name)} || {})` );
  7485. args.unshift( 'exports' );
  7486. } else if ( exportMode === 'named' ) {
  7487. dependencies.unshift( '{}' );
  7488. args.unshift( 'exports' );
  7489. }
  7490. const useStrict = options.strict !== false ? `${indentString}'use strict';\n\n` : ``;
  7491. let wrapperIntro = `(function (${args}) {\n${useStrict}`;
  7492. if ( exportMode !== 'none' && !extend) {
  7493. wrapperIntro = ( isNamespaced ? thisProp(name) : `${bundle.varOrConst} ${name}` ) + ` = ${wrapperIntro}`;
  7494. }
  7495. if ( isNamespaced ) {
  7496. wrapperIntro = setupNamespace( name ) + wrapperIntro;
  7497. }
  7498. let wrapperOutro = `\n\n}(${dependencies}));`;
  7499. if (!extend && exportMode === 'named') {
  7500. wrapperOutro = `\n\n${indentString}return exports;${wrapperOutro}`;
  7501. }
  7502. // var foo__default = 'default' in foo ? foo['default'] : foo;
  7503. const interopBlock = getInteropBlock( bundle, options );
  7504. if ( interopBlock ) { magicString.prepend( interopBlock + '\n\n' ); }
  7505. if ( intro ) { magicString.prepend( intro ); }
  7506. const exportBlock = getExportBlock( bundle, exportMode );
  7507. if ( exportBlock ) { magicString.append( '\n\n' + exportBlock ); }
  7508. if ( outro ) { magicString.append( outro ); }
  7509. return magicString
  7510. .indent( indentString )
  7511. .prepend( wrapperIntro )
  7512. .append( wrapperOutro );
  7513. }
  7514. function globalProp ( name ) {
  7515. if ( !name ) { return 'null'; }
  7516. return `global${ keypath( name ) }`;
  7517. }
  7518. function setupNamespace$1 ( name ) {
  7519. const parts = name.split( '.' );
  7520. const last = property( parts.pop() );
  7521. let acc = 'global';
  7522. return parts
  7523. .map( part => ( acc += property( part ), `${acc} = ${acc} || {}` ) )
  7524. .concat( `${acc}${last}` )
  7525. .join( ', ' );
  7526. }
  7527. function safeAccess ( name ) {
  7528. const parts = name.split( '.' );
  7529. let acc = 'global';
  7530. return parts
  7531. .map( part => ( acc += property( part ), acc ) )
  7532. .join( ` && ` );
  7533. }
  7534. const wrapperOutro = '\n\n})));';
  7535. function umd ( bundle, magicString, ref, options ) {
  7536. var exportMode = ref.exportMode;
  7537. var getPath = ref.getPath;
  7538. var indentString = ref.indentString;
  7539. var intro = ref.intro;
  7540. var outro = ref.outro;
  7541. if ( exportMode !== 'none' && !options.name ) {
  7542. error({
  7543. code: 'INVALID_OPTION',
  7544. message: 'You must supply options.name for UMD bundles'
  7545. });
  7546. }
  7547. warnOnBuiltins( bundle );
  7548. const globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle );
  7549. const amdDeps = bundle.externalModules.map( m => `'${getPath(m.id)}'` );
  7550. const cjsDeps = bundle.externalModules.map( m => `require('${getPath(m.id)}')` );
  7551. const trimmed = trimEmptyImports( bundle.externalModules );
  7552. const globalDeps = trimmed.map( module => globalProp( globalNameMaker( module ) ) );
  7553. const args = trimmed.map( m => m.name );
  7554. if ( exportMode === 'named' ) {
  7555. amdDeps.unshift( `'exports'` );
  7556. cjsDeps.unshift( `exports` );
  7557. globalDeps.unshift( `(${setupNamespace$1(options.name)} = ${options.extend ? `${globalProp(options.name)} || ` : '' }{})` );
  7558. args.unshift( 'exports' );
  7559. }
  7560. const amdOptions = options.amd || {};
  7561. const amdParams =
  7562. ( amdOptions.id ? `'${amdOptions.id}', ` : `` ) +
  7563. ( amdDeps.length ? `[${amdDeps.join( ', ' )}], ` : `` );
  7564. const define = amdOptions.define || 'define';
  7565. const cjsExport = exportMode === 'default' ? `module.exports = ` : ``;
  7566. const defaultExport = exportMode === 'default' ? `${setupNamespace$1(options.name)} = ` : '';
  7567. const useStrict = options.strict !== false ? ` 'use strict';` : ``;
  7568. let globalExport;
  7569. if (options.noConflict === true) {
  7570. let factory;
  7571. if ( exportMode === 'default' ) {
  7572. factory = `var exports = factory(${globalDeps});`;
  7573. } else if ( exportMode === 'named' ) {
  7574. const module = globalDeps.shift();
  7575. factory = `var exports = ${module};
  7576. factory(${['exports'].concat(globalDeps)});`;
  7577. }
  7578. globalExport = `(function() {
  7579. var current = ${safeAccess(options.name)};
  7580. ${factory}
  7581. ${globalProp(options.name)} = exports;
  7582. exports.noConflict = function() { ${globalProp(options.name)} = current; return exports; };
  7583. })()`;
  7584. } else {
  7585. globalExport = `(${defaultExport}factory(${globalDeps}))`;
  7586. }
  7587. const wrapperIntro =
  7588. `(function (global, factory) {
  7589. typeof exports === 'object' && typeof module !== 'undefined' ? ${cjsExport}factory(${cjsDeps.join( ', ' )}) :
  7590. typeof ${define} === 'function' && ${define}.amd ? ${define}(${amdParams}factory) :
  7591. ${globalExport};
  7592. }(this, (function (${args}) {${useStrict}
  7593. `.replace( /^\t\t/gm, '' ).replace( /^\t/gm, indentString || '\t' );
  7594. // var foo__default = 'default' in foo ? foo['default'] : foo;
  7595. const interopBlock = getInteropBlock( bundle, options );
  7596. if ( interopBlock ) { magicString.prepend( interopBlock + '\n\n' ); }
  7597. if ( intro ) { magicString.prepend( intro ); }
  7598. const exportBlock = getExportBlock( bundle, exportMode );
  7599. if ( exportBlock ) { magicString.append( '\n\n' + exportBlock ); }
  7600. if ( exportMode === 'named' && options.legacy !== true ) { magicString.append( `\n\n${esModuleExport}` ); }
  7601. if ( outro ) { magicString.append( outro ); }
  7602. return magicString
  7603. .trim()
  7604. .indent( indentString )
  7605. .append( wrapperOutro )
  7606. .prepend( wrapperIntro );
  7607. }
  7608. var finalisers = { amd, cjs, es, iife, umd };
  7609. function ensureArray ( thing ) {
  7610. if ( Array.isArray( thing ) ) { return thing; }
  7611. if ( thing == undefined ) { return []; }
  7612. return [ thing ];
  7613. }
  7614. function load ( id ) {
  7615. return readFileSync( id, 'utf-8' );
  7616. }
  7617. function findFile ( file ) {
  7618. try {
  7619. const stats = lstatSync( file );
  7620. if ( stats.isSymbolicLink() ) { return findFile( realpathSync( file ) ); }
  7621. if ( stats.isFile() ) {
  7622. // check case
  7623. const name = basename( file );
  7624. const files = readdirSync( dirname( file ) );
  7625. if ( ~files.indexOf( name ) ) { return file; }
  7626. }
  7627. } catch ( err ) {
  7628. // suppress
  7629. }
  7630. }
  7631. function addJsExtensionIfNecessary ( file ) {
  7632. return findFile( file ) || findFile( file + '.js' );
  7633. }
  7634. function resolveId ( importee, importer ) {
  7635. if ( typeof process === 'undefined' ) {
  7636. error({
  7637. code: 'MISSING_PROCESS',
  7638. message: `It looks like you're using Rollup in a non-Node.js environment. This means you must supply a plugin with custom resolveId and load functions`,
  7639. url: 'https://github.com/rollup/rollup/wiki/Plugins'
  7640. });
  7641. }
  7642. // external modules (non-entry modules that start with neither '.' or '/')
  7643. // are skipped at this stage.
  7644. if ( importer !== undefined && !isAbsolute( importee ) && importee[0] !== '.' ) { return null; }
  7645. // `resolve` processes paths from right to left, prepending them until an
  7646. // absolute path is created. Absolute importees therefore shortcircuit the
  7647. // resolve call and require no special handing on our part.
  7648. // See https://nodejs.org/api/path.html#path_path_resolve_paths
  7649. return addJsExtensionIfNecessary(
  7650. resolve( importer ? dirname( importer ) : resolve(), importee ) );
  7651. }
  7652. function makeOnwarn () {
  7653. const warned = blank();
  7654. return warning => {
  7655. const str = warning.toString();
  7656. if ( str in warned ) { return; }
  7657. console.error( str ); //eslint-disable-line no-console
  7658. warned[ str ] = true;
  7659. };
  7660. }
  7661. function badExports ( option, keys$$1 ) {
  7662. error({
  7663. code: 'INVALID_EXPORT_OPTION',
  7664. message: `'${option}' was specified for options.exports, but entry module has following exports: ${keys$$1.join(', ')}`
  7665. });
  7666. }
  7667. function getExportMode ( bundle, ref ) {
  7668. var exportMode = ref.exports;
  7669. var name = ref.name;
  7670. var format = ref.format;
  7671. const exportKeys = keys( bundle.entryModule.exports )
  7672. .concat( keys( bundle.entryModule.reexports ) )
  7673. .concat( bundle.entryModule.exportAllSources ); // not keys, but makes our job easier this way
  7674. if ( exportMode === 'default' ) {
  7675. if ( exportKeys.length !== 1 || exportKeys[0] !== 'default' ) {
  7676. badExports( 'default', exportKeys );
  7677. }
  7678. } else if ( exportMode === 'none' && exportKeys.length ) {
  7679. badExports( 'none', exportKeys );
  7680. }
  7681. if ( !exportMode || exportMode === 'auto' ) {
  7682. if ( exportKeys.length === 0 ) {
  7683. exportMode = 'none';
  7684. } else if ( exportKeys.length === 1 && exportKeys[0] === 'default' ) {
  7685. exportMode = 'default';
  7686. } else {
  7687. if ( bundle.entryModule.exports.default && format !== 'es') {
  7688. bundle.warn({
  7689. code: 'MIXED_EXPORTS',
  7690. message: `Using named and default exports together. Consumers of your bundle will have to use ${name || 'bundle'}['default'] to access the default export, which may not be what you want. Use \`exports: 'named'\` to disable this warning`,
  7691. url: `https://github.com/rollup/rollup/wiki/JavaScript-API#exports`
  7692. });
  7693. }
  7694. exportMode = 'named';
  7695. }
  7696. }
  7697. if ( !/(?:default|named|none)/.test( exportMode ) ) {
  7698. error({
  7699. code: 'INVALID_EXPORT_OPTION',
  7700. message: `options.exports must be 'default', 'named', 'none', 'auto', or left unspecified (defaults to 'auto')`
  7701. });
  7702. }
  7703. return exportMode;
  7704. }
  7705. function getIndentString ( magicString, options ) {
  7706. if ( options.indent === true ) {
  7707. return magicString.getIndentString();
  7708. }
  7709. return options.indent || '';
  7710. }
  7711. function transform ( bundle, source, id, plugins ) {
  7712. const sourcemapChain = [];
  7713. const originalSourcemap = typeof source.map === 'string' ? JSON.parse( source.map ) : source.map;
  7714. if ( originalSourcemap && typeof originalSourcemap.mappings === 'string' ) {
  7715. originalSourcemap.mappings = decode$$1( originalSourcemap.mappings );
  7716. }
  7717. const originalCode = source.code;
  7718. let ast = source.ast;
  7719. let promise = Promise.resolve( source.code );
  7720. plugins.forEach( plugin => {
  7721. if ( !plugin.transform ) { return; }
  7722. promise = promise.then( previous => {
  7723. function augment ( object, pos, code ) {
  7724. if ( typeof object === 'string' ) {
  7725. object = { message: object };
  7726. }
  7727. if ( object.code ) { object.pluginCode = object.code; }
  7728. object.code = code;
  7729. if ( pos !== undefined ) {
  7730. if ( pos.line !== undefined && pos.column !== undefined ) {
  7731. var line = pos.line;
  7732. var column = pos.column;
  7733. object.loc = { file: id, line, column };
  7734. object.frame = getCodeFrame( previous, line, column );
  7735. }
  7736. else {
  7737. object.pos = pos;
  7738. var ref = locate( previous, pos, { offsetLine: 1 });
  7739. var line = ref.line;
  7740. var column = ref.column;
  7741. object.loc = { file: id, line, column };
  7742. object.frame = getCodeFrame( previous, line, column );
  7743. }
  7744. }
  7745. object.plugin = plugin.name;
  7746. object.id = id;
  7747. return object;
  7748. }
  7749. let throwing;
  7750. const context = {
  7751. warn: ( warning, pos ) => {
  7752. warning = augment( warning, pos, 'PLUGIN_WARNING' );
  7753. bundle.warn( warning );
  7754. },
  7755. error ( err, pos ) {
  7756. err = augment( err, pos, 'PLUGIN_ERROR' );
  7757. throwing = true;
  7758. error( err );
  7759. }
  7760. };
  7761. let transformed;
  7762. try {
  7763. transformed = plugin.transform.call( context, previous, id );
  7764. } catch ( err ) {
  7765. if ( !throwing ) { context.error( err ); }
  7766. error( err );
  7767. }
  7768. return Promise.resolve( transformed )
  7769. .then( result => {
  7770. if ( result == null ) { return previous; }
  7771. if ( typeof result === 'string' ) {
  7772. result = {
  7773. code: result,
  7774. ast: null,
  7775. map: null
  7776. };
  7777. }
  7778. // `result.map` can only be a string if `result` isn't
  7779. else if ( typeof result.map === 'string' ) {
  7780. result.map = JSON.parse( result.map );
  7781. }
  7782. if ( result.map && typeof result.map.mappings === 'string' ) {
  7783. result.map.mappings = decode$$1( result.map.mappings );
  7784. }
  7785. sourcemapChain.push( result.map || { missing: true, plugin: plugin.name }); // lil' bit hacky but it works
  7786. ast = result.ast;
  7787. return result.code;
  7788. })
  7789. .catch( err => {
  7790. err = augment( err, undefined, 'PLUGIN_ERROR' );
  7791. error( err );
  7792. });
  7793. });
  7794. });
  7795. return promise.then( code => ({ code, originalCode, originalSourcemap, ast, sourcemapChain }) );
  7796. }
  7797. function transformBundle ( code, plugins, sourcemapChain, options ) {
  7798. return plugins.reduce( ( promise, plugin ) => {
  7799. if ( !plugin.transformBundle ) { return promise; }
  7800. return promise.then( code => {
  7801. return Promise.resolve().then( () => {
  7802. return plugin.transformBundle( code, { format : options.format } );
  7803. }).then( result => {
  7804. if ( result == null ) { return code; }
  7805. if ( typeof result === 'string' ) {
  7806. result = {
  7807. code: result,
  7808. map: null
  7809. };
  7810. }
  7811. const map = typeof result.map === 'string' ? JSON.parse( result.map ) : result.map;
  7812. if ( map && typeof map.mappings === 'string' ) {
  7813. map.mappings = decode$$1( map.mappings );
  7814. }
  7815. sourcemapChain.push( map );
  7816. return result.code;
  7817. }).catch( err => {
  7818. error({
  7819. code: 'BAD_BUNDLE_TRANSFORMER',
  7820. message: `Error transforming bundle${plugin.name ? ` with '${plugin.name}' plugin` : ''}: ${err.message}`,
  7821. plugin: plugin.name
  7822. });
  7823. });
  7824. });
  7825. }, Promise.resolve( code ) );
  7826. }
  7827. class Source {
  7828. constructor ( filename, content ) {
  7829. this.isOriginal = true;
  7830. this.filename = filename;
  7831. this.content = content;
  7832. }
  7833. traceSegment ( line, column, name ) {
  7834. return { line, column, name, source: this };
  7835. }
  7836. }
  7837. class Link {
  7838. constructor ( map, sources ) {
  7839. this.sources = sources;
  7840. this.names = map.names;
  7841. this.mappings = map.mappings;
  7842. }
  7843. traceMappings () {
  7844. const sources = [];
  7845. const sourcesContent = [];
  7846. const names = [];
  7847. const mappings = this.mappings.map( line => {
  7848. const tracedLine = [];
  7849. line.forEach( segment => {
  7850. const source = this.sources[ segment[1] ];
  7851. if ( !source ) { return; }
  7852. const traced = source.traceSegment( segment[2], segment[3], this.names[ segment[4] ] );
  7853. if ( traced ) {
  7854. let sourceIndex = null;
  7855. let nameIndex = null;
  7856. segment = [
  7857. segment[0],
  7858. null,
  7859. traced.line,
  7860. traced.column
  7861. ];
  7862. // newer sources are more likely to be used, so search backwards.
  7863. sourceIndex = sources.lastIndexOf( traced.source.filename );
  7864. if ( sourceIndex === -1 ) {
  7865. sourceIndex = sources.length;
  7866. sources.push( traced.source.filename );
  7867. sourcesContent[ sourceIndex ] = traced.source.content;
  7868. } else if ( sourcesContent[ sourceIndex ] == null ) {
  7869. sourcesContent[ sourceIndex ] = traced.source.content;
  7870. } else if ( traced.source.content != null && sourcesContent[ sourceIndex ] !== traced.source.content ) {
  7871. error({
  7872. message: `Multiple conflicting contents for sourcemap source ${source.filename}`
  7873. });
  7874. }
  7875. segment[1] = sourceIndex;
  7876. if ( traced.name ) {
  7877. nameIndex = names.indexOf( traced.name );
  7878. if ( nameIndex === -1 ) {
  7879. nameIndex = names.length;
  7880. names.push( traced.name );
  7881. }
  7882. segment[4] = nameIndex;
  7883. }
  7884. tracedLine.push( segment );
  7885. }
  7886. });
  7887. return tracedLine;
  7888. });
  7889. return { sources, sourcesContent, names, mappings };
  7890. }
  7891. traceSegment ( line, column, name ) {
  7892. const segments = this.mappings[ line ];
  7893. if ( !segments ) { return null; }
  7894. for ( let i = 0; i < segments.length; i += 1 ) {
  7895. const segment = segments[i];
  7896. if ( segment[0] > column ) { return null; }
  7897. if ( segment[0] === column ) {
  7898. const source = this.sources[ segment[1] ];
  7899. if ( !source ) { return null; }
  7900. return source.traceSegment( segment[2], segment[3], this.names[ segment[4] ] || name );
  7901. }
  7902. }
  7903. return null;
  7904. }
  7905. }
  7906. function collapseSourcemaps ( bundle, file, map, modules, bundleSourcemapChain ) {
  7907. const moduleSources = modules.filter( module => !module.excludeFromSourcemap ).map( module => {
  7908. let sourcemapChain = module.sourcemapChain;
  7909. let source;
  7910. if ( module.originalSourcemap == null ) {
  7911. source = new Source( module.id, module.originalCode );
  7912. } else {
  7913. const sources = module.originalSourcemap.sources;
  7914. const sourcesContent = module.originalSourcemap.sourcesContent || [];
  7915. if ( sources == null || ( sources.length <= 1 && sources[0] == null ) ) {
  7916. source = new Source( module.id, sourcesContent[0] );
  7917. sourcemapChain = [ module.originalSourcemap ].concat( sourcemapChain );
  7918. } else {
  7919. // TODO indiscriminately treating IDs and sources as normal paths is probably bad.
  7920. const directory = dirname( module.id ) || '.';
  7921. const sourceRoot = module.originalSourcemap.sourceRoot || '.';
  7922. const baseSources = sources.map( (source, i) => {
  7923. return new Source( resolve( directory, sourceRoot, source ), sourcesContent[i] );
  7924. });
  7925. source = new Link( module.originalSourcemap, baseSources );
  7926. }
  7927. }
  7928. sourcemapChain.forEach( map => {
  7929. if ( map.missing ) {
  7930. bundle.warn({
  7931. code: 'SOURCEMAP_BROKEN',
  7932. plugin: map.plugin,
  7933. message: `Sourcemap is likely to be incorrect: a plugin${map.plugin ? ` ('${map.plugin}')` : ``} was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
  7934. url: `https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect`
  7935. });
  7936. map = {
  7937. names: [],
  7938. mappings: ''
  7939. };
  7940. }
  7941. source = new Link( map, [ source ]);
  7942. });
  7943. return source;
  7944. });
  7945. let source = new Link( map, moduleSources );
  7946. bundleSourcemapChain.forEach( map => {
  7947. source = new Link( map, [ source ] );
  7948. });
  7949. var ref = source.traceMappings();
  7950. var sources = ref.sources;
  7951. var sourcesContent = ref.sourcesContent;
  7952. var names = ref.names;
  7953. var mappings = ref.mappings;
  7954. if ( file ) {
  7955. const directory = dirname( file );
  7956. sources = sources.map( source => relative( directory, source ) );
  7957. map.file = basename( file );
  7958. }
  7959. // we re-use the `map` object because it has convenient toString/toURL methods
  7960. map.sources = sources;
  7961. map.sourcesContent = sourcesContent;
  7962. map.names = names;
  7963. map.mappings = encode$$1( mappings );
  7964. return map;
  7965. }
  7966. function callIfFunction ( thing ) {
  7967. return typeof thing === 'function' ? thing() : thing;
  7968. }
  7969. class GlobalVariable extends Variable {
  7970. constructor ( name ) {
  7971. super( name );
  7972. this.isExternal = true;
  7973. this.isGlobal = true;
  7974. this.isReassigned = false;
  7975. this.included = true;
  7976. }
  7977. addReference ( reference ) {
  7978. if ( reference.isReassignment ) { this.isReassigned = true; }
  7979. }
  7980. assignExpression () {}
  7981. hasEffectsWhenCalled () {
  7982. return !pureFunctions[ this.name ];
  7983. }
  7984. }
  7985. class BundleScope extends Scope {
  7986. findVariable ( name ) {
  7987. if ( !this.variables[ name ] ) {
  7988. this.variables[ name ] = new GlobalVariable( name );
  7989. }
  7990. return this.variables[ name ];
  7991. }
  7992. }
  7993. class Bundle$$1 {
  7994. constructor ( options ) {
  7995. this.cachedModules = new Map();
  7996. if ( options.cache ) {
  7997. options.cache.modules.forEach( module => {
  7998. this.cachedModules.set( module.id, module );
  7999. } );
  8000. }
  8001. this.plugins = ensureArray( options.plugins );
  8002. options = this.plugins.reduce( ( acc, plugin ) => {
  8003. if ( plugin.options ) { return plugin.options( acc ) || acc; }
  8004. return acc;
  8005. }, options );
  8006. if ( !options.input ) {
  8007. throw new Error( 'You must supply options.input to rollup' );
  8008. }
  8009. this.entry = options.input;
  8010. this.entryId = null;
  8011. this.entryModule = null;
  8012. this.treeshake = options.treeshake !== false;
  8013. if ( options.pureExternalModules === true ) {
  8014. this.isPureExternalModule = () => true;
  8015. } else if ( typeof options.pureExternalModules === 'function' ) {
  8016. this.isPureExternalModule = options.pureExternalModules;
  8017. } else if ( Array.isArray( options.pureExternalModules ) ) {
  8018. const pureExternalModules = new Set( options.pureExternalModules );
  8019. this.isPureExternalModule = id => pureExternalModules.has( id );
  8020. } else {
  8021. this.isPureExternalModule = () => false;
  8022. }
  8023. this.resolveId = first(
  8024. [ id => this.isExternal( id ) ? false : null ]
  8025. .concat( this.plugins.map( plugin => plugin.resolveId ).filter( Boolean ) )
  8026. .concat( resolveId )
  8027. );
  8028. const loaders = this.plugins
  8029. .map( plugin => plugin.load )
  8030. .filter( Boolean );
  8031. this.hasLoaders = loaders.length !== 0;
  8032. this.load = first( loaders.concat( load ) );
  8033. this.scope = new BundleScope();
  8034. // TODO strictly speaking, this only applies with non-ES6, non-default-only bundles
  8035. [ 'module', 'exports', '_interopDefault' ].forEach( name => {
  8036. this.scope.findVariable( name ); // creates global variable as side-effect
  8037. } );
  8038. this.moduleById = new Map();
  8039. this.modules = [];
  8040. this.externalModules = [];
  8041. this.context = String( options.context );
  8042. const optionsModuleContext = options.moduleContext;
  8043. if ( typeof optionsModuleContext === 'function' ) {
  8044. this.getModuleContext = id => optionsModuleContext( id ) || this.context;
  8045. } else if ( typeof optionsModuleContext === 'object' ) {
  8046. const moduleContext = new Map();
  8047. Object.keys( optionsModuleContext ).forEach( key => {
  8048. moduleContext.set( resolve( key ), optionsModuleContext[ key ] );
  8049. } );
  8050. this.getModuleContext = id => moduleContext.get( id ) || this.context;
  8051. } else {
  8052. this.getModuleContext = () => this.context;
  8053. }
  8054. if ( typeof options.external === 'function' ) {
  8055. this.isExternal = options.external;
  8056. } else {
  8057. const ids = ensureArray( options.external );
  8058. this.isExternal = id => ids.indexOf( id ) !== -1;
  8059. }
  8060. this.onwarn = options.onwarn || makeOnwarn();
  8061. this.varOrConst = options.preferConst ? 'const' : 'var';
  8062. this.legacy = options.legacy;
  8063. this.acornOptions = options.acorn || {};
  8064. }
  8065. build () {
  8066. // Phase 1 – discovery. We load the entry module and find which
  8067. // modules it imports, and import those, until we have all
  8068. // of the entry module's dependencies
  8069. return this.resolveId( this.entry, undefined )
  8070. .then( id => {
  8071. if ( id === false ) {
  8072. error( {
  8073. code: 'UNRESOLVED_ENTRY',
  8074. message: `Entry module cannot be external`
  8075. } );
  8076. }
  8077. if ( id == null ) {
  8078. error( {
  8079. code: 'UNRESOLVED_ENTRY',
  8080. message: `Could not resolve entry (${this.entry})`
  8081. } );
  8082. }
  8083. this.entryId = id;
  8084. return this.fetchModule( id, undefined );
  8085. } )
  8086. .then( entryModule => {
  8087. this.entryModule = entryModule;
  8088. // Phase 2 – binding. We link references to their variables
  8089. // to generate a complete picture of the bundle
  8090. timeStart( 'phase 2' );
  8091. this.modules.forEach( module => module.bindImportSpecifiers() );
  8092. this.modules.forEach( module => module.bindReferences() );
  8093. timeEnd( 'phase 2' );
  8094. // Phase 3 – marking. We include all statements that should be included
  8095. timeStart( 'phase 3' );
  8096. // mark all export statements
  8097. entryModule.getExports().forEach( name => {
  8098. const variable = entryModule.traceExport( name );
  8099. variable.exportName = name;
  8100. variable.includeVariable();
  8101. if ( variable.isNamespace ) {
  8102. variable.needsNamespaceBlock = true;
  8103. }
  8104. } );
  8105. entryModule.getReexports().forEach( name => {
  8106. const variable = entryModule.traceExport( name );
  8107. if ( variable.isExternal ) {
  8108. variable.reexported = variable.module.reexported = true;
  8109. } else {
  8110. variable.exportName = name;
  8111. variable.includeVariable();
  8112. }
  8113. } );
  8114. // mark statements that should appear in the bundle
  8115. if ( this.treeshake ) {
  8116. let addedNewNodes;
  8117. do {
  8118. addedNewNodes = false;
  8119. this.modules.forEach( module => {
  8120. if ( module.includeInBundle() ) {
  8121. addedNewNodes = true;
  8122. }
  8123. } );
  8124. } while ( addedNewNodes );
  8125. } else {
  8126. // Necessary to properly replace namespace imports
  8127. this.modules.forEach( module => module.includeAllInBundle() );
  8128. }
  8129. timeEnd( 'phase 3' );
  8130. // Phase 4 – final preparation. We order the modules with an
  8131. // enhanced topological sort that accounts for cycles, then
  8132. // ensure that names are deconflicted throughout the bundle
  8133. timeStart( 'phase 4' );
  8134. // while we're here, check for unused external imports
  8135. this.externalModules.forEach( module => {
  8136. const unused = Object.keys( module.declarations )
  8137. .filter( name => name !== '*' )
  8138. .filter( name => !module.declarations[ name ].included && !module.declarations[ name ].reexported );
  8139. if ( unused.length === 0 ) { return; }
  8140. const names = unused.length === 1 ?
  8141. `'${unused[ 0 ]}' is` :
  8142. `${unused.slice( 0, -1 ).map( name => `'${name}'` ).join( ', ' )} and '${unused.slice( -1 )}' are`;
  8143. this.warn( {
  8144. code: 'UNUSED_EXTERNAL_IMPORT',
  8145. source: module.id,
  8146. names: unused,
  8147. message: `${names} imported from external module '${module.id}' but never used`
  8148. } );
  8149. } );
  8150. // prune unused external imports
  8151. this.externalModules = this.externalModules.filter( module => {
  8152. return module.used || !this.isPureExternalModule( module.id );
  8153. } );
  8154. this.orderedModules = this.sort();
  8155. this.deconflict();
  8156. timeEnd( 'phase 4' );
  8157. } );
  8158. }
  8159. deconflict () {
  8160. const used = blank();
  8161. // ensure no conflicts with globals
  8162. keys( this.scope.variables ).forEach( name => used[ name ] = 1 );
  8163. function getSafeName ( name ) {
  8164. while ( used[ name ] ) {
  8165. name += `$${used[ name ]++}`;
  8166. }
  8167. used[ name ] = 1;
  8168. return name;
  8169. }
  8170. const toDeshadow = new Set();
  8171. this.externalModules.forEach( module => {
  8172. const safeName = getSafeName( module.name );
  8173. toDeshadow.add( safeName );
  8174. module.name = safeName;
  8175. // ensure we don't shadow named external imports, if
  8176. // we're creating an ES6 bundle
  8177. forOwn( module.declarations, ( declaration, name ) => {
  8178. const safeName = getSafeName( name );
  8179. toDeshadow.add( safeName );
  8180. declaration.setSafeName( safeName );
  8181. } );
  8182. } );
  8183. this.modules.forEach( module => {
  8184. forOwn( module.scope.variables, variable => {
  8185. if ( variable.isDefault && variable.declaration.id ) {
  8186. return;
  8187. }
  8188. variable.name = getSafeName( variable.name );
  8189. } );
  8190. // deconflict reified namespaces
  8191. const namespace = module.namespace();
  8192. if ( namespace.needsNamespaceBlock ) {
  8193. namespace.name = getSafeName( namespace.name );
  8194. }
  8195. } );
  8196. this.scope.deshadow( toDeshadow );
  8197. }
  8198. fetchModule ( id, importer ) {
  8199. // short-circuit cycles
  8200. if ( this.moduleById.has( id ) ) { return null; }
  8201. this.moduleById.set( id, null );
  8202. return this.load( id )
  8203. .catch( err => {
  8204. let msg = `Could not load ${id}`;
  8205. if ( importer ) { msg += ` (imported by ${importer})`; }
  8206. msg += `: ${err.message}`;
  8207. throw new Error( msg );
  8208. } )
  8209. .then( source => {
  8210. if ( typeof source === 'string' ) { return source; }
  8211. if ( source && typeof source === 'object' && source.code ) { return source; }
  8212. // TODO report which plugin failed
  8213. error( {
  8214. code: 'BAD_LOADER',
  8215. message: `Error loading ${relativeId( id )}: plugin load hook should return a string, a { code, map } object, or nothing/null`
  8216. } );
  8217. } )
  8218. .then( source => {
  8219. if ( typeof source === 'string' ) {
  8220. source = {
  8221. code: source,
  8222. ast: null
  8223. };
  8224. }
  8225. if ( this.cachedModules.has( id ) && this.cachedModules.get( id ).originalCode === source.code ) {
  8226. return this.cachedModules.get( id );
  8227. }
  8228. return transform( this, source, id, this.plugins );
  8229. } )
  8230. .then( source => {
  8231. var code = source.code;
  8232. var originalCode = source.originalCode;
  8233. var originalSourcemap = source.originalSourcemap;
  8234. var ast = source.ast;
  8235. var sourcemapChain = source.sourcemapChain;
  8236. var resolvedIds = source.resolvedIds;
  8237. const module = new Module( {
  8238. id,
  8239. code,
  8240. originalCode,
  8241. originalSourcemap,
  8242. ast,
  8243. sourcemapChain,
  8244. resolvedIds,
  8245. bundle: this
  8246. } );
  8247. this.modules.push( module );
  8248. this.moduleById.set( id, module );
  8249. return this.fetchAllDependencies( module ).then( () => {
  8250. keys( module.exports ).forEach( name => {
  8251. if ( name !== 'default' ) {
  8252. module.exportsAll[ name ] = module.id;
  8253. }
  8254. } );
  8255. module.exportAllSources.forEach( source => {
  8256. const id = module.resolvedIds[ source ] || module.resolvedExternalIds[ source ];
  8257. const exportAllModule = this.moduleById.get( id );
  8258. if ( exportAllModule.isExternal ) { return; }
  8259. keys( exportAllModule.exportsAll ).forEach( name => {
  8260. if ( name in module.exportsAll ) {
  8261. this.warn( {
  8262. code: 'NAMESPACE_CONFLICT',
  8263. reexporter: module.id,
  8264. name,
  8265. sources: [ module.exportsAll[ name ], exportAllModule.exportsAll[ name ] ],
  8266. message: `Conflicting namespaces: ${relativeId( module.id )} re-exports '${name}' from both ${relativeId(
  8267. module.exportsAll[ name ] )} and ${relativeId( exportAllModule.exportsAll[ name ] )} (will be ignored)`
  8268. } );
  8269. } else {
  8270. module.exportsAll[ name ] = exportAllModule.exportsAll[ name ];
  8271. }
  8272. } );
  8273. } );
  8274. return module;
  8275. } );
  8276. } );
  8277. }
  8278. fetchAllDependencies ( module ) {
  8279. return mapSequence( module.sources, source => {
  8280. const resolvedId = module.resolvedIds[ source ];
  8281. return ( resolvedId ? Promise.resolve( resolvedId ) : this.resolveId( source, module.id ) )
  8282. .then( resolvedId => {
  8283. const externalId = resolvedId || (isRelative( source ) ? resolve( module.id, '..', source ) : source);
  8284. let isExternal = this.isExternal( externalId );
  8285. if ( !resolvedId && !isExternal ) {
  8286. if ( isRelative( source ) ) {
  8287. error( {
  8288. code: 'UNRESOLVED_IMPORT',
  8289. message: `Could not resolve '${source}' from ${relativeId( module.id )}`
  8290. } );
  8291. }
  8292. this.warn( {
  8293. code: 'UNRESOLVED_IMPORT',
  8294. source,
  8295. importer: relativeId( module.id ),
  8296. message: `'${source}' is imported by ${relativeId(
  8297. module.id )}, but could not be resolved – treating it as an external dependency`,
  8298. url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency'
  8299. } );
  8300. isExternal = true;
  8301. }
  8302. if ( isExternal ) {
  8303. module.resolvedExternalIds[ source ] = externalId;
  8304. if ( !this.moduleById.has( externalId ) ) {
  8305. const module = new ExternalModule( externalId );
  8306. this.externalModules.push( module );
  8307. this.moduleById.set( externalId, module );
  8308. }
  8309. const externalModule = this.moduleById.get( externalId );
  8310. // add external declarations so we can detect which are never used
  8311. Object.keys( module.imports ).forEach( name => {
  8312. const importDeclaration = module.imports[ name ];
  8313. if ( importDeclaration.source !== source ) { return; }
  8314. externalModule.traceExport( importDeclaration.name );
  8315. } );
  8316. } else {
  8317. if ( resolvedId === module.id ) {
  8318. // need to find the actual import declaration, so we can provide
  8319. // a useful error message. Bit hoop-jumpy but what can you do
  8320. const declaration = module.ast.body.find( node => {
  8321. return ( node.isImportDeclaration || node.isExportDeclaration ) && node.source.value === source;
  8322. } );
  8323. const declarationType = /Export/.test( declaration.type ) ? 'export' : 'import';
  8324. module.error( {
  8325. code: 'CANNOT_IMPORT_SELF',
  8326. message: `A module cannot ${declarationType} itself`
  8327. }, declaration.start );
  8328. }
  8329. module.resolvedIds[ source ] = resolvedId;
  8330. return this.fetchModule( resolvedId, module.id );
  8331. }
  8332. } );
  8333. } );
  8334. }
  8335. getPathRelativeToEntryDirname ( resolvedId ) {
  8336. if ( isRelative( resolvedId ) || isAbsolute( resolvedId ) ) {
  8337. const entryDirname = dirname( this.entryId );
  8338. const relativeToEntry = normalize( relative( entryDirname, resolvedId ) );
  8339. return isRelative( relativeToEntry ) ? relativeToEntry : `./${relativeToEntry}`;
  8340. }
  8341. return resolvedId;
  8342. }
  8343. render ( options ) {
  8344. if ( options === void 0 ) options = {};
  8345. return Promise.resolve().then( () => {
  8346. // Determine export mode - 'default', 'named', 'none'
  8347. const exportMode = getExportMode( this, options );
  8348. let magicString = new Bundle$1( { separator: '\n\n' } );
  8349. const usedModules = [];
  8350. timeStart( 'render modules' );
  8351. this.orderedModules.forEach( module => {
  8352. const source = module.render( options.format === 'es', this.legacy );
  8353. if ( source.toString().length ) {
  8354. magicString.addSource( source );
  8355. usedModules.push( module );
  8356. }
  8357. } );
  8358. if ( !magicString.toString().trim() && this.entryModule.getExports().length === 0 && this.entryModule.getReexports().length === 0 ) {
  8359. this.warn( {
  8360. code: 'EMPTY_BUNDLE',
  8361. message: 'Generated an empty bundle'
  8362. } );
  8363. }
  8364. timeEnd( 'render modules' );
  8365. let intro = [ options.intro ]
  8366. .concat(
  8367. this.plugins.map( plugin => plugin.intro && plugin.intro() )
  8368. )
  8369. .filter( Boolean )
  8370. .join( '\n\n' );
  8371. if ( intro ) { intro += '\n\n'; }
  8372. let outro = [ options.outro ]
  8373. .concat(
  8374. this.plugins.map( plugin => plugin.outro && plugin.outro() )
  8375. )
  8376. .filter( Boolean )
  8377. .join( '\n\n' );
  8378. if ( outro ) { outro = `\n\n${outro}`; }
  8379. const indentString = getIndentString( magicString, options );
  8380. const finalise = finalisers[ options.format ];
  8381. if ( !finalise ) {
  8382. error( {
  8383. code: 'INVALID_OPTION',
  8384. message: `Invalid format: ${options.format} - valid options are ${keys( finalisers ).join( ', ' )}`
  8385. } );
  8386. }
  8387. timeStart( 'render format' );
  8388. const optionsPaths = options.paths;
  8389. const getPath = (
  8390. typeof optionsPaths === 'function' ?
  8391. ( id => optionsPaths( id ) || this.getPathRelativeToEntryDirname( id ) ) :
  8392. optionsPaths ?
  8393. ( id => optionsPaths.hasOwnProperty( id ) ? optionsPaths[ id ] : this.getPathRelativeToEntryDirname( id ) ) :
  8394. id => this.getPathRelativeToEntryDirname( id )
  8395. );
  8396. magicString = finalise( this, magicString.trim(), { exportMode, getPath, indentString, intro, outro }, options );
  8397. timeEnd( 'render format' );
  8398. const banner = [ options.banner ]
  8399. .concat( this.plugins.map( plugin => plugin.banner ) )
  8400. .map( callIfFunction )
  8401. .filter( Boolean )
  8402. .join( '\n' );
  8403. const footer = [ options.footer ]
  8404. .concat( this.plugins.map( plugin => plugin.footer ) )
  8405. .map( callIfFunction )
  8406. .filter( Boolean )
  8407. .join( '\n' );
  8408. if ( banner ) { magicString.prepend( banner + '\n' ); }
  8409. if ( footer ) { magicString.append( '\n' + footer ); }
  8410. const prevCode = magicString.toString();
  8411. let map = null;
  8412. const bundleSourcemapChain = [];
  8413. return transformBundle( prevCode, this.plugins, bundleSourcemapChain, options ).then( code => {
  8414. if ( options.sourcemap ) {
  8415. timeStart( 'sourcemap' );
  8416. let file = options.sourcemapFile || options.file;
  8417. if ( file ) { file = resolve( typeof process !== 'undefined' ? process.cwd() : '', file ); }
  8418. if ( this.hasLoaders || find( this.plugins, plugin => plugin.transform || plugin.transformBundle ) ) {
  8419. map = magicString.generateMap( {} );
  8420. if ( typeof map.mappings === 'string' ) {
  8421. map.mappings = decode$$1( map.mappings );
  8422. }
  8423. map = collapseSourcemaps( this, file, map, usedModules, bundleSourcemapChain );
  8424. } else {
  8425. map = magicString.generateMap( { file, includeContent: true } );
  8426. }
  8427. map.sources = map.sources.map( normalize );
  8428. timeEnd( 'sourcemap' );
  8429. }
  8430. if ( code[ code.length - 1 ] !== '\n' ) { code += '\n'; }
  8431. return { code, map };
  8432. } );
  8433. } );
  8434. }
  8435. sort () {
  8436. let hasCycles;
  8437. const seen = {};
  8438. const ordered = [];
  8439. const stronglyDependsOn = blank();
  8440. const dependsOn = blank();
  8441. this.modules.forEach( module => {
  8442. stronglyDependsOn[ module.id ] = blank();
  8443. dependsOn[ module.id ] = blank();
  8444. } );
  8445. this.modules.forEach( module => {
  8446. function processStrongDependency ( dependency ) {
  8447. if ( dependency === module || stronglyDependsOn[ module.id ][ dependency.id ] ) { return; }
  8448. stronglyDependsOn[ module.id ][ dependency.id ] = true;
  8449. dependency.strongDependencies.forEach( processStrongDependency );
  8450. }
  8451. function processDependency ( dependency ) {
  8452. if ( dependency === module || dependsOn[ module.id ][ dependency.id ] ) { return; }
  8453. dependsOn[ module.id ][ dependency.id ] = true;
  8454. dependency.dependencies.forEach( processDependency );
  8455. }
  8456. module.strongDependencies.forEach( processStrongDependency );
  8457. module.dependencies.forEach( processDependency );
  8458. } );
  8459. const visit = module => {
  8460. if ( seen[ module.id ] ) {
  8461. hasCycles = true;
  8462. return;
  8463. }
  8464. seen[ module.id ] = true;
  8465. module.dependencies.forEach( visit );
  8466. ordered.push( module );
  8467. };
  8468. visit( this.entryModule );
  8469. if ( hasCycles ) {
  8470. ordered.forEach( ( a, i ) => {
  8471. for ( i += 1; i < ordered.length; i += 1 ) {
  8472. const b = ordered[ i ];
  8473. // TODO reinstate this! it no longer works
  8474. if ( stronglyDependsOn[ a.id ][ b.id ] ) {
  8475. // somewhere, there is a module that imports b before a. Because
  8476. // b imports a, a is placed before b. We need to find the module
  8477. // in question, so we can provide a useful error message
  8478. let parent = '[[unknown]]';
  8479. const visited = {};
  8480. const findParent = module => {
  8481. if ( dependsOn[ module.id ][ a.id ] && dependsOn[ module.id ][ b.id ] ) {
  8482. parent = module.id;
  8483. return true;
  8484. }
  8485. visited[ module.id ] = true;
  8486. for ( let i = 0; i < module.dependencies.length; i += 1 ) {
  8487. const dependency = module.dependencies[ i ];
  8488. if ( !visited[ dependency.id ] && findParent( dependency ) ) { return true; }
  8489. }
  8490. };
  8491. findParent( this.entryModule );
  8492. this.onwarn(
  8493. `Module ${a.id} may be unable to evaluate without ${b.id}, but is included first due to a cyclical dependency. Consider swapping the import statements in ${parent} to ensure correct ordering`
  8494. );
  8495. }
  8496. }
  8497. } );
  8498. }
  8499. return ordered;
  8500. }
  8501. warn ( warning ) {
  8502. warning.toString = () => {
  8503. let str = '';
  8504. if ( warning.plugin ) { str += `(${warning.plugin} plugin) `; }
  8505. if ( warning.loc ) { str += `${relativeId( warning.loc.file )} (${warning.loc.line}:${warning.loc.column}) `; }
  8506. str += warning.message;
  8507. return str;
  8508. };
  8509. this.onwarn( warning );
  8510. }
  8511. }
  8512. const ALLOWED_KEYS = [
  8513. 'acorn',
  8514. 'amd',
  8515. 'banner',
  8516. 'cache',
  8517. 'context',
  8518. 'entry',
  8519. 'exports',
  8520. 'extend',
  8521. 'external',
  8522. 'file',
  8523. 'footer',
  8524. 'format',
  8525. 'globals',
  8526. 'indent',
  8527. 'input',
  8528. 'interop',
  8529. 'intro',
  8530. 'legacy',
  8531. 'moduleContext',
  8532. 'name',
  8533. 'noConflict',
  8534. 'onwarn',
  8535. 'output',
  8536. 'outro',
  8537. 'paths',
  8538. 'plugins',
  8539. 'preferConst',
  8540. 'pureExternalModules',
  8541. 'sourcemap',
  8542. 'sourcemapFile',
  8543. 'strict',
  8544. 'targets',
  8545. 'treeshake',
  8546. 'watch'
  8547. ];
  8548. function checkAmd ( options ) {
  8549. if ( options.moduleId ) {
  8550. if ( options.amd ) { throw new Error( 'Cannot have both options.amd and options.moduleId' ); }
  8551. options.amd = { id: options.moduleId };
  8552. delete options.moduleId;
  8553. const message = `options.moduleId is deprecated in favour of options.amd = { id: moduleId }`;
  8554. if ( options.onwarn ) {
  8555. options.onwarn({ message });
  8556. } else {
  8557. console.warn( message ); // eslint-disable-line no-console
  8558. }
  8559. }
  8560. }
  8561. function checkInputOptions ( options, warn ) {
  8562. if ( options.transform || options.load || options.resolveId || options.resolveExternal ) {
  8563. throw new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' );
  8564. }
  8565. if ( options.entry && !options.input ) {
  8566. options.input = options.entry;
  8567. warn({
  8568. message: `options.entry is deprecated, use options.input`
  8569. });
  8570. }
  8571. const err = validateKeys( keys(options), ALLOWED_KEYS );
  8572. if ( err ) { throw err; }
  8573. }
  8574. const deprecated = {
  8575. dest: 'file',
  8576. moduleName: 'name',
  8577. sourceMap: 'sourcemap',
  8578. sourceMapFile: 'sourcemapFile',
  8579. useStrict: 'strict'
  8580. };
  8581. function checkOutputOptions ( options, warn ) {
  8582. if ( options.format === 'es6' ) {
  8583. error({
  8584. message: 'The `es6` output format is deprecated – use `es` instead',
  8585. url: `https://github.com/rollup/rollup/wiki/JavaScript-API#format`
  8586. });
  8587. }
  8588. if ( !options.format ) {
  8589. error({
  8590. message: `You must specify options.format, which can be one of 'amd', 'cjs', 'es', 'iife' or 'umd'`,
  8591. url: `https://github.com/rollup/rollup/wiki/JavaScript-API#format`
  8592. });
  8593. }
  8594. if ( options.moduleId ) {
  8595. if ( options.amd ) { throw new Error( 'Cannot have both options.amd and options.moduleId' ); }
  8596. options.amd = { id: options.moduleId };
  8597. delete options.moduleId;
  8598. warn({
  8599. message: `options.moduleId is deprecated in favour of options.amd = { id: moduleId }`
  8600. });
  8601. }
  8602. const deprecations = [];
  8603. Object.keys( deprecated ).forEach( old => {
  8604. if ( old in options ) {
  8605. deprecations.push({ old, new: deprecated[ old ] });
  8606. options[ deprecated[ old ] ] = options[ old ];
  8607. delete options[ old ];
  8608. }
  8609. });
  8610. if ( deprecations.length ) {
  8611. const message = `The following options have been renamed — please update your config: ${deprecations.map(option => `${option.old} -> ${option.new}`).join(', ')}`;
  8612. warn({
  8613. code: 'DEPRECATED_OPTIONS',
  8614. message,
  8615. deprecations
  8616. });
  8617. }
  8618. }
  8619. const throwAsyncGenerateError = {
  8620. get () {
  8621. throw new Error( `bundle.generate(...) now returns a Promise instead of a { code, map } object` );
  8622. }
  8623. };
  8624. function rollup ( options ) {
  8625. try {
  8626. if ( !options ) {
  8627. throw new Error( 'You must supply an options object to rollup' );
  8628. }
  8629. const warn = options.onwarn || (warning => console.warn( warning.message )); // eslint-disable-line no-console
  8630. checkInputOptions( options, warn );
  8631. const bundle = new Bundle$$1( options );
  8632. timeStart( '--BUILD--' );
  8633. return bundle.build().then( () => {
  8634. timeEnd( '--BUILD--' );
  8635. function generate ( options ) {
  8636. if ( !options ) {
  8637. throw new Error( 'You must supply an options object' );
  8638. }
  8639. checkOutputOptions( options, warn );
  8640. checkAmd( options );
  8641. timeStart( '--GENERATE--' );
  8642. const promise = Promise.resolve()
  8643. .then( () => bundle.render( options ) )
  8644. .then( rendered => {
  8645. timeEnd( '--GENERATE--' );
  8646. bundle.plugins.forEach( plugin => {
  8647. if ( plugin.ongenerate ) {
  8648. plugin.ongenerate( assign({
  8649. bundle: result
  8650. }, options ), rendered);
  8651. }
  8652. });
  8653. flushTime();
  8654. return rendered;
  8655. });
  8656. Object.defineProperty( promise, 'code', throwAsyncGenerateError );
  8657. Object.defineProperty( promise, 'map', throwAsyncGenerateError );
  8658. return promise;
  8659. }
  8660. const result = {
  8661. imports: bundle.externalModules.map( module => module.id ),
  8662. exports: keys( bundle.entryModule.exports ),
  8663. modules: bundle.orderedModules.map( module => module.toJSON() ),
  8664. generate,
  8665. write: options => {
  8666. if ( !options || (!options.file && !options.dest) ) {
  8667. error({
  8668. code: 'MISSING_OPTION',
  8669. message: 'You must specify options.file'
  8670. });
  8671. }
  8672. return generate( options ).then( result => {
  8673. const file = options.file;
  8674. var code = result.code;
  8675. var map = result.map;
  8676. const promises = [];
  8677. if ( options.sourcemap ) {
  8678. let url;
  8679. if ( options.sourcemap === 'inline' ) {
  8680. url = map.toUrl();
  8681. } else {
  8682. url = `${basename( file )}.map`;
  8683. promises.push( writeFile$1( file + '.map', map.toString() ) );
  8684. }
  8685. code += `//# ${SOURCEMAPPING_URL}=${url}\n`;
  8686. }
  8687. promises.push( writeFile$1( file, code ) );
  8688. return Promise.all( promises ).then( () => {
  8689. return mapSequence( bundle.plugins.filter( plugin => plugin.onwrite ), plugin => {
  8690. return Promise.resolve( plugin.onwrite( assign({
  8691. bundle: result
  8692. }, options ), result));
  8693. });
  8694. });
  8695. });
  8696. }
  8697. };
  8698. return result;
  8699. });
  8700. } catch ( err ) {
  8701. return Promise.reject( err );
  8702. }
  8703. }
  8704. function createCommonjsModule(fn, module) {
  8705. return module = { exports: {} }, fn(module, module.exports), module.exports;
  8706. }
  8707. /*!
  8708. * filename-regex <https://github.com/regexps/filename-regex>
  8709. *
  8710. * Copyright (c) 2014-2015, Jon Schlinkert
  8711. * Licensed under the MIT license.
  8712. */
  8713. var filenameRegex = function filenameRegex() {
  8714. return /([^\\\/]+)$/;
  8715. };
  8716. /*!
  8717. * arr-flatten <https://github.com/jonschlinkert/arr-flatten>
  8718. *
  8719. * Copyright (c) 2014-2017, Jon Schlinkert.
  8720. * Released under the MIT License.
  8721. */
  8722. var arrFlatten = function (arr) {
  8723. return flat(arr, []);
  8724. };
  8725. function flat(arr, res) {
  8726. var i = 0, cur;
  8727. var len = arr.length;
  8728. for (; i < len; i++) {
  8729. cur = arr[i];
  8730. Array.isArray(cur) ? flat(cur, res) : res.push(cur);
  8731. }
  8732. return res;
  8733. }
  8734. var slice = [].slice;
  8735. /**
  8736. * Return the difference between the first array and
  8737. * additional arrays.
  8738. *
  8739. * ```js
  8740. * var diff = require('{%= name %}');
  8741. *
  8742. * var a = ['a', 'b', 'c', 'd'];
  8743. * var b = ['b', 'c'];
  8744. *
  8745. * console.log(diff(a, b))
  8746. * //=> ['a', 'd']
  8747. * ```
  8748. *
  8749. * @param {Array} `a`
  8750. * @param {Array} `b`
  8751. * @return {Array}
  8752. * @api public
  8753. */
  8754. function diff(arr, arrays) {
  8755. var argsLen = arguments.length;
  8756. var len = arr.length, i = -1;
  8757. var res = [], arrays;
  8758. if (argsLen === 1) {
  8759. return arr;
  8760. }
  8761. if (argsLen > 2) {
  8762. arrays = arrFlatten(slice.call(arguments, 1));
  8763. }
  8764. while (++i < len) {
  8765. if (!~arrays.indexOf(arr[i])) {
  8766. res.push(arr[i]);
  8767. }
  8768. }
  8769. return res;
  8770. }
  8771. /**
  8772. * Expose `diff`
  8773. */
  8774. var arrDiff = diff;
  8775. /*!
  8776. * array-unique <https://github.com/jonschlinkert/array-unique>
  8777. *
  8778. * Copyright (c) 2014-2015, Jon Schlinkert.
  8779. * Licensed under the MIT License.
  8780. */
  8781. var arrayUnique = function unique(arr) {
  8782. if (!Array.isArray(arr)) {
  8783. throw new TypeError('array-unique expects an array.');
  8784. }
  8785. var len = arr.length;
  8786. var i = -1;
  8787. while (i++ < len) {
  8788. var j = i + 1;
  8789. for (; j < arr.length; ++j) {
  8790. if (arr[i] === arr[j]) {
  8791. arr.splice(j--, 1);
  8792. }
  8793. }
  8794. }
  8795. return arr;
  8796. };
  8797. var toString$1$1 = {}.toString;
  8798. var isarray = Array.isArray || function (arr) {
  8799. return toString$1$1.call(arr) == '[object Array]';
  8800. };
  8801. var isobject = function isObject(val) {
  8802. return val != null && typeof val === 'object' && isarray(val) === false;
  8803. };
  8804. /*!
  8805. * Determine if an object is a Buffer
  8806. *
  8807. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  8808. * @license MIT
  8809. */
  8810. // The _isBuffer check is for Safari 5-7 support, because it's missing
  8811. // Object.prototype.constructor. Remove this eventually
  8812. var isBuffer_1 = function (obj) {
  8813. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  8814. };
  8815. function isBuffer (obj) {
  8816. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  8817. }
  8818. // For Node v0.10 support. Remove this eventually.
  8819. function isSlowBuffer (obj) {
  8820. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  8821. }
  8822. var toString$2 = Object.prototype.toString;
  8823. /**
  8824. * Get the native `typeof` a value.
  8825. *
  8826. * @param {*} `val`
  8827. * @return {*} Native javascript type
  8828. */
  8829. var kindOf = function kindOf(val) {
  8830. // primitivies
  8831. if (typeof val === 'undefined') {
  8832. return 'undefined';
  8833. }
  8834. if (val === null) {
  8835. return 'null';
  8836. }
  8837. if (val === true || val === false || val instanceof Boolean) {
  8838. return 'boolean';
  8839. }
  8840. if (typeof val === 'string' || val instanceof String) {
  8841. return 'string';
  8842. }
  8843. if (typeof val === 'number' || val instanceof Number) {
  8844. return 'number';
  8845. }
  8846. // functions
  8847. if (typeof val === 'function' || val instanceof Function) {
  8848. return 'function';
  8849. }
  8850. // array
  8851. if (typeof Array.isArray !== 'undefined' && Array.isArray(val)) {
  8852. return 'array';
  8853. }
  8854. // check for instances of RegExp and Date before calling `toString`
  8855. if (val instanceof RegExp) {
  8856. return 'regexp';
  8857. }
  8858. if (val instanceof Date) {
  8859. return 'date';
  8860. }
  8861. // other objects
  8862. var type = toString$2.call(val);
  8863. if (type === '[object RegExp]') {
  8864. return 'regexp';
  8865. }
  8866. if (type === '[object Date]') {
  8867. return 'date';
  8868. }
  8869. if (type === '[object Arguments]') {
  8870. return 'arguments';
  8871. }
  8872. if (type === '[object Error]') {
  8873. return 'error';
  8874. }
  8875. // buffer
  8876. if (isBuffer_1(val)) {
  8877. return 'buffer';
  8878. }
  8879. // es6: Map, WeakMap, Set, WeakSet
  8880. if (type === '[object Set]') {
  8881. return 'set';
  8882. }
  8883. if (type === '[object WeakSet]') {
  8884. return 'weakset';
  8885. }
  8886. if (type === '[object Map]') {
  8887. return 'map';
  8888. }
  8889. if (type === '[object WeakMap]') {
  8890. return 'weakmap';
  8891. }
  8892. if (type === '[object Symbol]') {
  8893. return 'symbol';
  8894. }
  8895. // typed arrays
  8896. if (type === '[object Int8Array]') {
  8897. return 'int8array';
  8898. }
  8899. if (type === '[object Uint8Array]') {
  8900. return 'uint8array';
  8901. }
  8902. if (type === '[object Uint8ClampedArray]') {
  8903. return 'uint8clampedarray';
  8904. }
  8905. if (type === '[object Int16Array]') {
  8906. return 'int16array';
  8907. }
  8908. if (type === '[object Uint16Array]') {
  8909. return 'uint16array';
  8910. }
  8911. if (type === '[object Int32Array]') {
  8912. return 'int32array';
  8913. }
  8914. if (type === '[object Uint32Array]') {
  8915. return 'uint32array';
  8916. }
  8917. if (type === '[object Float32Array]') {
  8918. return 'float32array';
  8919. }
  8920. if (type === '[object Float64Array]') {
  8921. return 'float64array';
  8922. }
  8923. // must be a plain object
  8924. return 'object';
  8925. };
  8926. var isNumber = function isNumber(num) {
  8927. var type = kindOf(num);
  8928. if (type !== 'number' && type !== 'string') {
  8929. return false;
  8930. }
  8931. var n = +num;
  8932. return (n - n + 1) >= 0 && num !== '';
  8933. };
  8934. var toString$3 = Object.prototype.toString;
  8935. /**
  8936. * Get the native `typeof` a value.
  8937. *
  8938. * @param {*} `val`
  8939. * @return {*} Native javascript type
  8940. */
  8941. var kindOf$2 = function kindOf(val) {
  8942. // primitivies
  8943. if (typeof val === 'undefined') {
  8944. return 'undefined';
  8945. }
  8946. if (val === null) {
  8947. return 'null';
  8948. }
  8949. if (val === true || val === false || val instanceof Boolean) {
  8950. return 'boolean';
  8951. }
  8952. if (typeof val === 'string' || val instanceof String) {
  8953. return 'string';
  8954. }
  8955. if (typeof val === 'number' || val instanceof Number) {
  8956. return 'number';
  8957. }
  8958. // functions
  8959. if (typeof val === 'function' || val instanceof Function) {
  8960. return 'function';
  8961. }
  8962. // array
  8963. if (typeof Array.isArray !== 'undefined' && Array.isArray(val)) {
  8964. return 'array';
  8965. }
  8966. // check for instances of RegExp and Date before calling `toString`
  8967. if (val instanceof RegExp) {
  8968. return 'regexp';
  8969. }
  8970. if (val instanceof Date) {
  8971. return 'date';
  8972. }
  8973. // other objects
  8974. var type = toString$3.call(val);
  8975. if (type === '[object RegExp]') {
  8976. return 'regexp';
  8977. }
  8978. if (type === '[object Date]') {
  8979. return 'date';
  8980. }
  8981. if (type === '[object Arguments]') {
  8982. return 'arguments';
  8983. }
  8984. if (type === '[object Error]') {
  8985. return 'error';
  8986. }
  8987. // buffer
  8988. if (isBuffer_1(val)) {
  8989. return 'buffer';
  8990. }
  8991. // es6: Map, WeakMap, Set, WeakSet
  8992. if (type === '[object Set]') {
  8993. return 'set';
  8994. }
  8995. if (type === '[object WeakSet]') {
  8996. return 'weakset';
  8997. }
  8998. if (type === '[object Map]') {
  8999. return 'map';
  9000. }
  9001. if (type === '[object WeakMap]') {
  9002. return 'weakmap';
  9003. }
  9004. if (type === '[object Symbol]') {
  9005. return 'symbol';
  9006. }
  9007. // typed arrays
  9008. if (type === '[object Int8Array]') {
  9009. return 'int8array';
  9010. }
  9011. if (type === '[object Uint8Array]') {
  9012. return 'uint8array';
  9013. }
  9014. if (type === '[object Uint8ClampedArray]') {
  9015. return 'uint8clampedarray';
  9016. }
  9017. if (type === '[object Int16Array]') {
  9018. return 'int16array';
  9019. }
  9020. if (type === '[object Uint16Array]') {
  9021. return 'uint16array';
  9022. }
  9023. if (type === '[object Int32Array]') {
  9024. return 'int32array';
  9025. }
  9026. if (type === '[object Uint32Array]') {
  9027. return 'uint32array';
  9028. }
  9029. if (type === '[object Float32Array]') {
  9030. return 'float32array';
  9031. }
  9032. if (type === '[object Float64Array]') {
  9033. return 'float64array';
  9034. }
  9035. // must be a plain object
  9036. return 'object';
  9037. };
  9038. var isNumber$2 = function isNumber(num) {
  9039. var type = kindOf$2(num);
  9040. if (type === 'string') {
  9041. if (!num.trim()) return false;
  9042. } else if (type !== 'number') {
  9043. return false;
  9044. }
  9045. return (num - num + 1) >= 0;
  9046. };
  9047. var toString$4 = Object.prototype.toString;
  9048. /**
  9049. * Get the native `typeof` a value.
  9050. *
  9051. * @param {*} `val`
  9052. * @return {*} Native javascript type
  9053. */
  9054. var kindOf$4 = function kindOf(val) {
  9055. // primitivies
  9056. if (typeof val === 'undefined') {
  9057. return 'undefined';
  9058. }
  9059. if (val === null) {
  9060. return 'null';
  9061. }
  9062. if (val === true || val === false || val instanceof Boolean) {
  9063. return 'boolean';
  9064. }
  9065. if (typeof val === 'string' || val instanceof String) {
  9066. return 'string';
  9067. }
  9068. if (typeof val === 'number' || val instanceof Number) {
  9069. return 'number';
  9070. }
  9071. // functions
  9072. if (typeof val === 'function' || val instanceof Function) {
  9073. return 'function';
  9074. }
  9075. // array
  9076. if (typeof Array.isArray !== 'undefined' && Array.isArray(val)) {
  9077. return 'array';
  9078. }
  9079. // check for instances of RegExp and Date before calling `toString`
  9080. if (val instanceof RegExp) {
  9081. return 'regexp';
  9082. }
  9083. if (val instanceof Date) {
  9084. return 'date';
  9085. }
  9086. // other objects
  9087. var type = toString$4.call(val);
  9088. if (type === '[object RegExp]') {
  9089. return 'regexp';
  9090. }
  9091. if (type === '[object Date]') {
  9092. return 'date';
  9093. }
  9094. if (type === '[object Arguments]') {
  9095. return 'arguments';
  9096. }
  9097. if (type === '[object Error]') {
  9098. return 'error';
  9099. }
  9100. if (type === '[object Promise]') {
  9101. return 'promise';
  9102. }
  9103. // buffer
  9104. if (isBuffer_1(val)) {
  9105. return 'buffer';
  9106. }
  9107. // es6: Map, WeakMap, Set, WeakSet
  9108. if (type === '[object Set]') {
  9109. return 'set';
  9110. }
  9111. if (type === '[object WeakSet]') {
  9112. return 'weakset';
  9113. }
  9114. if (type === '[object Map]') {
  9115. return 'map';
  9116. }
  9117. if (type === '[object WeakMap]') {
  9118. return 'weakmap';
  9119. }
  9120. if (type === '[object Symbol]') {
  9121. return 'symbol';
  9122. }
  9123. // typed arrays
  9124. if (type === '[object Int8Array]') {
  9125. return 'int8array';
  9126. }
  9127. if (type === '[object Uint8Array]') {
  9128. return 'uint8array';
  9129. }
  9130. if (type === '[object Uint8ClampedArray]') {
  9131. return 'uint8clampedarray';
  9132. }
  9133. if (type === '[object Int16Array]') {
  9134. return 'int16array';
  9135. }
  9136. if (type === '[object Uint16Array]') {
  9137. return 'uint16array';
  9138. }
  9139. if (type === '[object Int32Array]') {
  9140. return 'int32array';
  9141. }
  9142. if (type === '[object Uint32Array]') {
  9143. return 'uint32array';
  9144. }
  9145. if (type === '[object Float32Array]') {
  9146. return 'float32array';
  9147. }
  9148. if (type === '[object Float64Array]') {
  9149. return 'float64array';
  9150. }
  9151. // must be a plain object
  9152. return 'object';
  9153. };
  9154. /**
  9155. * Expose `randomatic`
  9156. */
  9157. var randomatic_1 = randomatic;
  9158. /**
  9159. * Available mask characters
  9160. */
  9161. var type = {
  9162. lower: 'abcdefghijklmnopqrstuvwxyz',
  9163. upper: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  9164. number: '0123456789',
  9165. special: '~!@#$%^&()_+-={}[];\',.'
  9166. };
  9167. type.all = type.lower + type.upper + type.number + type.special;
  9168. /**
  9169. * Generate random character sequences of a specified `length`,
  9170. * based on the given `pattern`.
  9171. *
  9172. * @param {String} `pattern` The pattern to use for generating the random string.
  9173. * @param {String} `length` The length of the string to generate.
  9174. * @param {String} `options`
  9175. * @return {String}
  9176. * @api public
  9177. */
  9178. function randomatic(pattern, length, options) {
  9179. if (typeof pattern === 'undefined') {
  9180. throw new Error('randomatic expects a string or number.');
  9181. }
  9182. var custom = false;
  9183. if (arguments.length === 1) {
  9184. if (typeof pattern === 'string') {
  9185. length = pattern.length;
  9186. } else if (isNumber$2(pattern)) {
  9187. options = {}; length = pattern; pattern = '*';
  9188. }
  9189. }
  9190. if (kindOf$4(length) === 'object' && length.hasOwnProperty('chars')) {
  9191. options = length;
  9192. pattern = options.chars;
  9193. length = pattern.length;
  9194. custom = true;
  9195. }
  9196. var opts = options || {};
  9197. var mask = '';
  9198. var res = '';
  9199. // Characters to be used
  9200. if (pattern.indexOf('?') !== -1) mask += opts.chars;
  9201. if (pattern.indexOf('a') !== -1) mask += type.lower;
  9202. if (pattern.indexOf('A') !== -1) mask += type.upper;
  9203. if (pattern.indexOf('0') !== -1) mask += type.number;
  9204. if (pattern.indexOf('!') !== -1) mask += type.special;
  9205. if (pattern.indexOf('*') !== -1) mask += type.all;
  9206. if (custom) mask += pattern;
  9207. while (length--) {
  9208. res += mask.charAt(parseInt(Math.random() * mask.length, 10));
  9209. }
  9210. return res;
  9211. }
  9212. /*!
  9213. * repeat-string <https://github.com/jonschlinkert/repeat-string>
  9214. *
  9215. * Copyright (c) 2014-2015, Jon Schlinkert.
  9216. * Licensed under the MIT License.
  9217. */
  9218. /**
  9219. * Results cache
  9220. */
  9221. var res = '';
  9222. var cache;
  9223. /**
  9224. * Expose `repeat`
  9225. */
  9226. var repeatString = repeat;
  9227. /**
  9228. * Repeat the given `string` the specified `number`
  9229. * of times.
  9230. *
  9231. * **Example:**
  9232. *
  9233. * ```js
  9234. * var repeat = require('repeat-string');
  9235. * repeat('A', 5);
  9236. * //=> AAAAA
  9237. * ```
  9238. *
  9239. * @param {String} `string` The string to repeat
  9240. * @param {Number} `number` The number of times to repeat the string
  9241. * @return {String} Repeated string
  9242. * @api public
  9243. */
  9244. function repeat(str, num) {
  9245. if (typeof str !== 'string') {
  9246. throw new TypeError('expected a string');
  9247. }
  9248. // cover common, quick use cases
  9249. if (num === 1) return str;
  9250. if (num === 2) return str + str;
  9251. var max = str.length * num;
  9252. if (cache !== str || typeof cache === 'undefined') {
  9253. cache = str;
  9254. res = '';
  9255. } else if (res.length >= max) {
  9256. return res.substr(0, max);
  9257. }
  9258. while (max > res.length && num > 1) {
  9259. if (num & 1) {
  9260. res += str;
  9261. }
  9262. num >>= 1;
  9263. str += str;
  9264. }
  9265. res += str;
  9266. res = res.substr(0, max);
  9267. return res;
  9268. }
  9269. /*!
  9270. * repeat-element <https://github.com/jonschlinkert/repeat-element>
  9271. *
  9272. * Copyright (c) 2015 Jon Schlinkert.
  9273. * Licensed under the MIT license.
  9274. */
  9275. var repeatElement = function repeat(ele, num) {
  9276. var arr = new Array(num);
  9277. for (var i = 0; i < num; i++) {
  9278. arr[i] = ele;
  9279. }
  9280. return arr;
  9281. };
  9282. /**
  9283. * Expose `fillRange`
  9284. */
  9285. var fillRange_1 = fillRange;
  9286. /**
  9287. * Return a range of numbers or letters.
  9288. *
  9289. * @param {String} `a` Start of the range
  9290. * @param {String} `b` End of the range
  9291. * @param {String} `step` Increment or decrement to use.
  9292. * @param {Function} `fn` Custom function to modify each element in the range.
  9293. * @return {Array}
  9294. */
  9295. function fillRange(a, b, step, options, fn) {
  9296. if (a == null || b == null) {
  9297. throw new Error('fill-range expects the first and second args to be strings.');
  9298. }
  9299. if (typeof step === 'function') {
  9300. fn = step; options = {}; step = null;
  9301. }
  9302. if (typeof options === 'function') {
  9303. fn = options; options = {};
  9304. }
  9305. if (isobject(step)) {
  9306. options = step; step = '';
  9307. }
  9308. var expand, regex = false, sep$$1 = '';
  9309. var opts = options || {};
  9310. if (typeof opts.silent === 'undefined') {
  9311. opts.silent = true;
  9312. }
  9313. step = step || opts.step;
  9314. // store a ref to unmodified arg
  9315. var origA = a, origB = b;
  9316. b = (b.toString() === '-0') ? 0 : b;
  9317. if (opts.optimize || opts.makeRe) {
  9318. step = step ? (step += '~') : step;
  9319. expand = true;
  9320. regex = true;
  9321. sep$$1 = '~';
  9322. }
  9323. // handle special step characters
  9324. if (typeof step === 'string') {
  9325. var match = stepRe().exec(step);
  9326. if (match) {
  9327. var i = match.index;
  9328. var m = match[0];
  9329. // repeat string
  9330. if (m === '+') {
  9331. return repeatElement(a, b);
  9332. // randomize a, `b` times
  9333. } else if (m === '?') {
  9334. return [randomatic_1(a, b)];
  9335. // expand right, no regex reduction
  9336. } else if (m === '>') {
  9337. step = step.substr(0, i) + step.substr(i + 1);
  9338. expand = true;
  9339. // expand to an array, or if valid create a reduced
  9340. // string for a regex logic `or`
  9341. } else if (m === '|') {
  9342. step = step.substr(0, i) + step.substr(i + 1);
  9343. expand = true;
  9344. regex = true;
  9345. sep$$1 = m;
  9346. // expand to an array, or if valid create a reduced
  9347. // string for a regex range
  9348. } else if (m === '~') {
  9349. step = step.substr(0, i) + step.substr(i + 1);
  9350. expand = true;
  9351. regex = true;
  9352. sep$$1 = m;
  9353. }
  9354. } else if (!isNumber(step)) {
  9355. if (!opts.silent) {
  9356. throw new TypeError('fill-range: invalid step.');
  9357. }
  9358. return null;
  9359. }
  9360. }
  9361. if (/[.&*()[\]^%$#@!]/.test(a) || /[.&*()[\]^%$#@!]/.test(b)) {
  9362. if (!opts.silent) {
  9363. throw new RangeError('fill-range: invalid range arguments.');
  9364. }
  9365. return null;
  9366. }
  9367. // has neither a letter nor number, or has both letters and numbers
  9368. // this needs to be after the step logic
  9369. if (!noAlphaNum(a) || !noAlphaNum(b) || hasBoth(a) || hasBoth(b)) {
  9370. if (!opts.silent) {
  9371. throw new RangeError('fill-range: invalid range arguments.');
  9372. }
  9373. return null;
  9374. }
  9375. // validate arguments
  9376. var isNumA = isNumber(zeros(a));
  9377. var isNumB = isNumber(zeros(b));
  9378. if ((!isNumA && isNumB) || (isNumA && !isNumB)) {
  9379. if (!opts.silent) {
  9380. throw new TypeError('fill-range: first range argument is incompatible with second.');
  9381. }
  9382. return null;
  9383. }
  9384. // by this point both are the same, so we
  9385. // can use A to check going forward.
  9386. var isNum = isNumA;
  9387. var num = formatStep(step);
  9388. // is the range alphabetical? or numeric?
  9389. if (isNum) {
  9390. // if numeric, coerce to an integer
  9391. a = +a; b = +b;
  9392. } else {
  9393. // otherwise, get the charCode to expand alpha ranges
  9394. a = a.charCodeAt(0);
  9395. b = b.charCodeAt(0);
  9396. }
  9397. // is the pattern descending?
  9398. var isDescending = a > b;
  9399. // don't create a character class if the args are < 0
  9400. if (a < 0 || b < 0) {
  9401. expand = false;
  9402. regex = false;
  9403. }
  9404. // detect padding
  9405. var padding = isPadded(origA, origB);
  9406. var res, pad, arr = [];
  9407. var ii = 0;
  9408. // character classes, ranges and logical `or`
  9409. if (regex) {
  9410. if (shouldExpand(a, b, num, isNum, padding, opts)) {
  9411. // make sure the correct separator is used
  9412. if (sep$$1 === '|' || sep$$1 === '~') {
  9413. sep$$1 = detectSeparator(a, b, num, isNum, isDescending);
  9414. }
  9415. return wrap$1([origA, origB], sep$$1, opts);
  9416. }
  9417. }
  9418. while (isDescending ? (a >= b) : (a <= b)) {
  9419. if (padding && isNum) {
  9420. pad = padding(a);
  9421. }
  9422. // custom function
  9423. if (typeof fn === 'function') {
  9424. res = fn(a, isNum, pad, ii++);
  9425. // letters
  9426. } else if (!isNum) {
  9427. if (regex && isInvalidChar(a)) {
  9428. res = null;
  9429. } else {
  9430. res = String.fromCharCode(a);
  9431. }
  9432. // numbers
  9433. } else {
  9434. res = formatPadding(a, pad);
  9435. }
  9436. // add result to the array, filtering any nulled values
  9437. if (res !== null) arr.push(res);
  9438. // increment or decrement
  9439. if (isDescending) {
  9440. a -= num;
  9441. } else {
  9442. a += num;
  9443. }
  9444. }
  9445. // now that the array is expanded, we need to handle regex
  9446. // character classes, ranges or logical `or` that wasn't
  9447. // already handled before the loop
  9448. if ((regex || expand) && !opts.noexpand) {
  9449. // make sure the correct separator is used
  9450. if (sep$$1 === '|' || sep$$1 === '~') {
  9451. sep$$1 = detectSeparator(a, b, num, isNum, isDescending);
  9452. }
  9453. if (arr.length === 1 || a < 0 || b < 0) { return arr; }
  9454. return wrap$1(arr, sep$$1, opts);
  9455. }
  9456. return arr;
  9457. }
  9458. /**
  9459. * Wrap the string with the correct regex
  9460. * syntax.
  9461. */
  9462. function wrap$1(arr, sep$$1, opts) {
  9463. if (sep$$1 === '~') { sep$$1 = '-'; }
  9464. var str = arr.join(sep$$1);
  9465. var pre = opts && opts.regexPrefix;
  9466. // regex logical `or`
  9467. if (sep$$1 === '|') {
  9468. str = pre ? pre + str : str;
  9469. str = '(' + str + ')';
  9470. }
  9471. // regex character class
  9472. if (sep$$1 === '-') {
  9473. str = (pre && pre === '^')
  9474. ? pre + str
  9475. : str;
  9476. str = '[' + str + ']';
  9477. }
  9478. return [str];
  9479. }
  9480. /**
  9481. * Check for invalid characters
  9482. */
  9483. function isCharClass(a, b, step, isNum, isDescending) {
  9484. if (isDescending) { return false; }
  9485. if (isNum) { return a <= 9 && b <= 9; }
  9486. if (a < b) { return step === 1; }
  9487. return false;
  9488. }
  9489. /**
  9490. * Detect the correct separator to use
  9491. */
  9492. function shouldExpand(a, b, num, isNum, padding, opts) {
  9493. if (isNum && (a > 9 || b > 9)) { return false; }
  9494. return !padding && num === 1 && a < b;
  9495. }
  9496. /**
  9497. * Detect the correct separator to use
  9498. */
  9499. function detectSeparator(a, b, step, isNum, isDescending) {
  9500. var isChar = isCharClass(a, b, step, isNum, isDescending);
  9501. if (!isChar) {
  9502. return '|';
  9503. }
  9504. return '~';
  9505. }
  9506. /**
  9507. * Correctly format the step based on type
  9508. */
  9509. function formatStep(step) {
  9510. return Math.abs(step >> 0) || 1;
  9511. }
  9512. /**
  9513. * Format padding, taking leading `-` into account
  9514. */
  9515. function formatPadding(ch, pad) {
  9516. var res = pad ? pad + ch : ch;
  9517. if (pad && ch.toString().charAt(0) === '-') {
  9518. res = '-' + pad + ch.toString().substr(1);
  9519. }
  9520. return res.toString();
  9521. }
  9522. /**
  9523. * Check for invalid characters
  9524. */
  9525. function isInvalidChar(str) {
  9526. var ch = toStr(str);
  9527. return ch === '\\'
  9528. || ch === '['
  9529. || ch === ']'
  9530. || ch === '^'
  9531. || ch === '('
  9532. || ch === ')'
  9533. || ch === '`';
  9534. }
  9535. /**
  9536. * Convert to a string from a charCode
  9537. */
  9538. function toStr(ch) {
  9539. return String.fromCharCode(ch);
  9540. }
  9541. /**
  9542. * Step regex
  9543. */
  9544. function stepRe() {
  9545. return /\?|>|\||\+|\~/g;
  9546. }
  9547. /**
  9548. * Return true if `val` has either a letter
  9549. * or a number
  9550. */
  9551. function noAlphaNum(val) {
  9552. return /[a-z0-9]/i.test(val);
  9553. }
  9554. /**
  9555. * Return true if `val` has both a letter and
  9556. * a number (invalid)
  9557. */
  9558. function hasBoth(val) {
  9559. return /[a-z][0-9]|[0-9][a-z]/i.test(val);
  9560. }
  9561. /**
  9562. * Normalize zeros for checks
  9563. */
  9564. function zeros(val) {
  9565. if (/^-*0+$/.test(val.toString())) {
  9566. return '0';
  9567. }
  9568. return val;
  9569. }
  9570. /**
  9571. * Return true if `val` has leading zeros,
  9572. * or a similar valid pattern.
  9573. */
  9574. function hasZeros(val) {
  9575. return /[^.]\.|^-*0+[0-9]/.test(val);
  9576. }
  9577. /**
  9578. * If the string is padded, returns a curried function with
  9579. * the a cached padding string, or `false` if no padding.
  9580. *
  9581. * @param {*} `origA` String or number.
  9582. * @return {String|Boolean}
  9583. */
  9584. function isPadded(origA, origB) {
  9585. if (hasZeros(origA) || hasZeros(origB)) {
  9586. var alen = length(origA);
  9587. var blen = length(origB);
  9588. var len = alen >= blen
  9589. ? alen
  9590. : blen;
  9591. return function (a) {
  9592. return repeatString('0', len - length(a));
  9593. };
  9594. }
  9595. return false;
  9596. }
  9597. /**
  9598. * Get the string length of `val`
  9599. */
  9600. function length(val) {
  9601. return val.toString().length;
  9602. }
  9603. var expandRange = function expandRange(str, options, fn) {
  9604. if (typeof str !== 'string') {
  9605. throw new TypeError('expand-range expects a string.');
  9606. }
  9607. if (typeof options === 'function') {
  9608. fn = options;
  9609. options = {};
  9610. }
  9611. if (typeof options === 'boolean') {
  9612. options = {};
  9613. options.makeRe = true;
  9614. }
  9615. // create arguments to pass to fill-range
  9616. var opts = options || {};
  9617. var args = str.split('..');
  9618. var len = args.length;
  9619. if (len > 3) { return str; }
  9620. // if only one argument, it can't expand so return it
  9621. if (len === 1) { return args; }
  9622. // if `true`, tell fill-range to regexify the string
  9623. if (typeof fn === 'boolean' && fn === true) {
  9624. opts.makeRe = true;
  9625. }
  9626. args.push(opts);
  9627. return fillRange_1.apply(null, args.concat(fn));
  9628. };
  9629. /*!
  9630. * preserve <https://github.com/jonschlinkert/preserve>
  9631. *
  9632. * Copyright (c) 2014-2015, Jon Schlinkert.
  9633. * Licensed under the MIT license.
  9634. */
  9635. /**
  9636. * Replace tokens in `str` with a temporary, heuristic placeholder.
  9637. *
  9638. * ```js
  9639. * tokens.before('{a\\,b}');
  9640. * //=> '{__ID1__}'
  9641. * ```
  9642. *
  9643. * @param {String} `str`
  9644. * @return {String} String with placeholders.
  9645. * @api public
  9646. */
  9647. var before = function before(str, re) {
  9648. return str.replace(re, function (match) {
  9649. var id = randomize$1();
  9650. cache$1[id] = match;
  9651. return '__ID' + id + '__';
  9652. });
  9653. };
  9654. /**
  9655. * Replace placeholders in `str` with original tokens.
  9656. *
  9657. * ```js
  9658. * tokens.after('{__ID1__}');
  9659. * //=> '{a\\,b}'
  9660. * ```
  9661. *
  9662. * @param {String} `str` String with placeholders
  9663. * @return {String} `str` String with original tokens.
  9664. * @api public
  9665. */
  9666. var after = function after(str) {
  9667. return str.replace(/__ID(.{5})__/g, function (_, id) {
  9668. return cache$1[id];
  9669. });
  9670. };
  9671. function randomize$1() {
  9672. return Math.random().toString().slice(2, 7);
  9673. }
  9674. var cache$1 = {};
  9675. var preserve = {
  9676. before: before,
  9677. after: after
  9678. };
  9679. /**
  9680. * Module dependencies
  9681. */
  9682. /**
  9683. * Expose `braces`
  9684. */
  9685. var braces_1 = function(str, options) {
  9686. if (typeof str !== 'string') {
  9687. throw new Error('braces expects a string');
  9688. }
  9689. return braces(str, options);
  9690. };
  9691. /**
  9692. * Expand `{foo,bar}` or `{1..5}` braces in the
  9693. * given `string`.
  9694. *
  9695. * @param {String} `str`
  9696. * @param {Array} `arr`
  9697. * @param {Object} `options`
  9698. * @return {Array}
  9699. */
  9700. function braces(str, arr, options) {
  9701. if (str === '') {
  9702. return [];
  9703. }
  9704. if (!Array.isArray(arr)) {
  9705. options = arr;
  9706. arr = [];
  9707. }
  9708. var opts = options || {};
  9709. arr = arr || [];
  9710. if (typeof opts.nodupes === 'undefined') {
  9711. opts.nodupes = true;
  9712. }
  9713. var fn = opts.fn;
  9714. var es6;
  9715. if (typeof opts === 'function') {
  9716. fn = opts;
  9717. opts = {};
  9718. }
  9719. if (!(patternRe instanceof RegExp)) {
  9720. patternRe = patternRegex();
  9721. }
  9722. var matches = str.match(patternRe) || [];
  9723. var m = matches[0];
  9724. switch(m) {
  9725. case '\\,':
  9726. return escapeCommas(str, arr, opts);
  9727. case '\\.':
  9728. return escapeDots(str, arr, opts);
  9729. case '\/.':
  9730. return escapePaths(str, arr, opts);
  9731. case ' ':
  9732. return splitWhitespace(str);
  9733. case '{,}':
  9734. return exponential(str, opts, braces);
  9735. case '{}':
  9736. return emptyBraces(str, arr, opts);
  9737. case '\\{':
  9738. case '\\}':
  9739. return escapeBraces(str, arr, opts);
  9740. case '${':
  9741. if (!/\{[^{]+\{/.test(str)) {
  9742. return arr.concat(str);
  9743. } else {
  9744. es6 = true;
  9745. str = preserve.before(str, es6Regex());
  9746. }
  9747. }
  9748. if (!(braceRe instanceof RegExp)) {
  9749. braceRe = braceRegex();
  9750. }
  9751. var match = braceRe.exec(str);
  9752. if (match == null) {
  9753. return [str];
  9754. }
  9755. var outter = match[1];
  9756. var inner = match[2];
  9757. if (inner === '') { return [str]; }
  9758. var segs, segsLength;
  9759. if (inner.indexOf('..') !== -1) {
  9760. segs = expandRange(inner, opts, fn) || inner.split(',');
  9761. segsLength = segs.length;
  9762. } else if (inner[0] === '"' || inner[0] === '\'') {
  9763. return arr.concat(str.split(/['"]/).join(''));
  9764. } else {
  9765. segs = inner.split(',');
  9766. if (opts.makeRe) {
  9767. return braces(str.replace(outter, wrap(segs, '|')), opts);
  9768. }
  9769. segsLength = segs.length;
  9770. if (segsLength === 1 && opts.bash) {
  9771. segs[0] = wrap(segs[0], '\\');
  9772. }
  9773. }
  9774. var len = segs.length;
  9775. var i = 0, val;
  9776. while (len--) {
  9777. var path$$1 = segs[i++];
  9778. if (/(\.[^.\/])/.test(path$$1)) {
  9779. if (segsLength > 1) {
  9780. return segs;
  9781. } else {
  9782. return [str];
  9783. }
  9784. }
  9785. val = splice(str, outter, path$$1);
  9786. if (/\{[^{}]+?\}/.test(val)) {
  9787. arr = braces(val, arr, opts);
  9788. } else if (val !== '') {
  9789. if (opts.nodupes && arr.indexOf(val) !== -1) { continue; }
  9790. arr.push(es6 ? preserve.after(val) : val);
  9791. }
  9792. }
  9793. if (opts.strict) { return filter$1(arr, filterEmpty); }
  9794. return arr;
  9795. }
  9796. /**
  9797. * Expand exponential ranges
  9798. *
  9799. * `a{,}{,}` => ['a', 'a', 'a', 'a']
  9800. */
  9801. function exponential(str, options, fn) {
  9802. if (typeof options === 'function') {
  9803. fn = options;
  9804. options = null;
  9805. }
  9806. var opts = options || {};
  9807. var esc = '__ESC_EXP__';
  9808. var exp = 0;
  9809. var res;
  9810. var parts = str.split('{,}');
  9811. if (opts.nodupes) {
  9812. return fn(parts.join(''), opts);
  9813. }
  9814. exp = parts.length - 1;
  9815. res = fn(parts.join(esc), opts);
  9816. var len = res.length;
  9817. var arr = [];
  9818. var i = 0;
  9819. while (len--) {
  9820. var ele = res[i++];
  9821. var idx = ele.indexOf(esc);
  9822. if (idx === -1) {
  9823. arr.push(ele);
  9824. } else {
  9825. ele = ele.split('__ESC_EXP__').join('');
  9826. if (!!ele && opts.nodupes !== false) {
  9827. arr.push(ele);
  9828. } else {
  9829. var num = Math.pow(2, exp);
  9830. arr.push.apply(arr, repeatElement(ele, num));
  9831. }
  9832. }
  9833. }
  9834. return arr;
  9835. }
  9836. /**
  9837. * Wrap a value with parens, brackets or braces,
  9838. * based on the given character/separator.
  9839. *
  9840. * @param {String|Array} `val`
  9841. * @param {String} `ch`
  9842. * @return {String}
  9843. */
  9844. function wrap(val, ch) {
  9845. if (ch === '|') {
  9846. return '(' + val.join(ch) + ')';
  9847. }
  9848. if (ch === ',') {
  9849. return '{' + val.join(ch) + '}';
  9850. }
  9851. if (ch === '-') {
  9852. return '[' + val.join(ch) + ']';
  9853. }
  9854. if (ch === '\\') {
  9855. return '\\{' + val + '\\}';
  9856. }
  9857. }
  9858. /**
  9859. * Handle empty braces: `{}`
  9860. */
  9861. function emptyBraces(str, arr, opts) {
  9862. return braces(str.split('{}').join('\\{\\}'), arr, opts);
  9863. }
  9864. /**
  9865. * Filter out empty-ish values
  9866. */
  9867. function filterEmpty(ele) {
  9868. return !!ele && ele !== '\\';
  9869. }
  9870. /**
  9871. * Handle patterns with whitespace
  9872. */
  9873. function splitWhitespace(str) {
  9874. var segs = str.split(' ');
  9875. var len = segs.length;
  9876. var res = [];
  9877. var i = 0;
  9878. while (len--) {
  9879. res.push.apply(res, braces(segs[i++]));
  9880. }
  9881. return res;
  9882. }
  9883. /**
  9884. * Handle escaped braces: `\\{foo,bar}`
  9885. */
  9886. function escapeBraces(str, arr, opts) {
  9887. if (!/\{[^{]+\{/.test(str)) {
  9888. return arr.concat(str.split('\\').join(''));
  9889. } else {
  9890. str = str.split('\\{').join('__LT_BRACE__');
  9891. str = str.split('\\}').join('__RT_BRACE__');
  9892. return map$1(braces(str, arr, opts), function(ele) {
  9893. ele = ele.split('__LT_BRACE__').join('{');
  9894. return ele.split('__RT_BRACE__').join('}');
  9895. });
  9896. }
  9897. }
  9898. /**
  9899. * Handle escaped dots: `{1\\.2}`
  9900. */
  9901. function escapeDots(str, arr, opts) {
  9902. if (!/[^\\]\..+\\\./.test(str)) {
  9903. return arr.concat(str.split('\\').join(''));
  9904. } else {
  9905. str = str.split('\\.').join('__ESC_DOT__');
  9906. return map$1(braces(str, arr, opts), function(ele) {
  9907. return ele.split('__ESC_DOT__').join('.');
  9908. });
  9909. }
  9910. }
  9911. /**
  9912. * Handle escaped dots: `{1\\.2}`
  9913. */
  9914. function escapePaths(str, arr, opts) {
  9915. str = str.split('\/.').join('__ESC_PATH__');
  9916. return map$1(braces(str, arr, opts), function(ele) {
  9917. return ele.split('__ESC_PATH__').join('\/.');
  9918. });
  9919. }
  9920. /**
  9921. * Handle escaped commas: `{a\\,b}`
  9922. */
  9923. function escapeCommas(str, arr, opts) {
  9924. if (!/\w,/.test(str)) {
  9925. return arr.concat(str.split('\\').join(''));
  9926. } else {
  9927. str = str.split('\\,').join('__ESC_COMMA__');
  9928. return map$1(braces(str, arr, opts), function(ele) {
  9929. return ele.split('__ESC_COMMA__').join(',');
  9930. });
  9931. }
  9932. }
  9933. /**
  9934. * Regex for common patterns
  9935. */
  9936. function patternRegex() {
  9937. return /\${|( (?=[{,}])|(?=[{,}]) )|{}|{,}|\\,(?=.*[{}])|\/\.(?=.*[{}])|\\\.(?={)|\\{|\\}/;
  9938. }
  9939. /**
  9940. * Braces regex.
  9941. */
  9942. function braceRegex() {
  9943. return /.*(\\?\{([^}]+)\})/;
  9944. }
  9945. /**
  9946. * es6 delimiter regex.
  9947. */
  9948. function es6Regex() {
  9949. return /\$\{([^}]+)\}/;
  9950. }
  9951. var braceRe;
  9952. var patternRe;
  9953. /**
  9954. * Faster alternative to `String.replace()` when the
  9955. * index of the token to be replaces can't be supplied
  9956. */
  9957. function splice(str, token, replacement) {
  9958. var i = str.indexOf(token);
  9959. return str.substr(0, i) + replacement
  9960. + str.substr(i + token.length);
  9961. }
  9962. /**
  9963. * Fast array map
  9964. */
  9965. function map$1(arr, fn) {
  9966. if (arr == null) {
  9967. return [];
  9968. }
  9969. var len = arr.length;
  9970. var res = new Array(len);
  9971. var i = -1;
  9972. while (++i < len) {
  9973. res[i] = fn(arr[i], i, arr);
  9974. }
  9975. return res;
  9976. }
  9977. /**
  9978. * Fast array filter
  9979. */
  9980. function filter$1(arr, cb) {
  9981. if (arr == null) return [];
  9982. if (typeof cb !== 'function') {
  9983. throw new TypeError('braces: filter expects a callback function.');
  9984. }
  9985. var len = arr.length;
  9986. var res = arr.slice();
  9987. var i = 0;
  9988. while (len--) {
  9989. if (!cb(arr[len], i++)) {
  9990. res.splice(len, 1);
  9991. }
  9992. }
  9993. return res;
  9994. }
  9995. /*!
  9996. * is-posix-bracket <https://github.com/jonschlinkert/is-posix-bracket>
  9997. *
  9998. * Copyright (c) 2015-2016, Jon Schlinkert.
  9999. * Licensed under the MIT License.
  10000. */
  10001. var isPosixBracket = function isPosixBracket(str) {
  10002. return typeof str === 'string' && /\[([:.=+])(?:[^\[\]]|)+\1\]/.test(str);
  10003. };
  10004. /**
  10005. * POSIX character classes
  10006. */
  10007. var POSIX = {
  10008. alnum: 'a-zA-Z0-9',
  10009. alpha: 'a-zA-Z',
  10010. blank: ' \\t',
  10011. cntrl: '\\x00-\\x1F\\x7F',
  10012. digit: '0-9',
  10013. graph: '\\x21-\\x7E',
  10014. lower: 'a-z',
  10015. print: '\\x20-\\x7E',
  10016. punct: '-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
  10017. space: ' \\t\\r\\n\\v\\f',
  10018. upper: 'A-Z',
  10019. word: 'A-Za-z0-9_',
  10020. xdigit: 'A-Fa-f0-9',
  10021. };
  10022. /**
  10023. * Expose `brackets`
  10024. */
  10025. var expandBrackets = brackets;
  10026. function brackets(str) {
  10027. if (!isPosixBracket(str)) {
  10028. return str;
  10029. }
  10030. var negated = false;
  10031. if (str.indexOf('[^') !== -1) {
  10032. negated = true;
  10033. str = str.split('[^').join('[');
  10034. }
  10035. if (str.indexOf('[!') !== -1) {
  10036. negated = true;
  10037. str = str.split('[!').join('[');
  10038. }
  10039. var a = str.split('[');
  10040. var b = str.split(']');
  10041. var imbalanced = a.length !== b.length;
  10042. var parts = str.split(/(?::\]\[:|\[?\[:|:\]\]?)/);
  10043. var len = parts.length, i = 0;
  10044. var end = '', beg = '';
  10045. var res = [];
  10046. // start at the end (innermost) first
  10047. while (len--) {
  10048. var inner = parts[i++];
  10049. if (inner === '^[!' || inner === '[!') {
  10050. inner = '';
  10051. negated = true;
  10052. }
  10053. var prefix = negated ? '^' : '';
  10054. var ch = POSIX[inner];
  10055. if (ch) {
  10056. res.push('[' + prefix + ch + ']');
  10057. } else if (inner) {
  10058. if (/^\[?\w-\w\]?$/.test(inner)) {
  10059. if (i === parts.length) {
  10060. res.push('[' + prefix + inner);
  10061. } else if (i === 1) {
  10062. res.push(prefix + inner + ']');
  10063. } else {
  10064. res.push(prefix + inner);
  10065. }
  10066. } else {
  10067. if (i === 1) {
  10068. beg += inner;
  10069. } else if (i === parts.length) {
  10070. end += inner;
  10071. } else {
  10072. res.push('[' + prefix + inner + ']');
  10073. }
  10074. }
  10075. }
  10076. }
  10077. var result = res.join('|');
  10078. var rlen = res.length || 1;
  10079. if (rlen > 1) {
  10080. result = '(?:' + result + ')';
  10081. rlen = 1;
  10082. }
  10083. if (beg) {
  10084. rlen++;
  10085. if (beg.charAt(0) === '[') {
  10086. if (imbalanced) {
  10087. beg = '\\[' + beg.slice(1);
  10088. } else {
  10089. beg += ']';
  10090. }
  10091. }
  10092. result = beg + result;
  10093. }
  10094. if (end) {
  10095. rlen++;
  10096. if (end.slice(-1) === ']') {
  10097. if (imbalanced) {
  10098. end = end.slice(0, end.length - 1) + '\\]';
  10099. } else {
  10100. end = '[' + end;
  10101. }
  10102. }
  10103. result += end;
  10104. }
  10105. if (rlen > 1) {
  10106. result = result.split('][').join(']|[');
  10107. if (result.indexOf('|') !== -1 && !/\(\?/.test(result)) {
  10108. result = '(?:' + result + ')';
  10109. }
  10110. }
  10111. result = result.replace(/\[+=|=\]+/g, '\\b');
  10112. return result;
  10113. }
  10114. brackets.makeRe = function(pattern) {
  10115. try {
  10116. return new RegExp(brackets(pattern));
  10117. } catch (err) {}
  10118. };
  10119. brackets.isMatch = function(str, pattern) {
  10120. try {
  10121. return brackets.makeRe(pattern).test(str);
  10122. } catch (err) {
  10123. return false;
  10124. }
  10125. };
  10126. brackets.match = function(arr, pattern) {
  10127. var len = arr.length, i = 0;
  10128. var res = arr.slice();
  10129. var re = brackets.makeRe(pattern);
  10130. while (i < len) {
  10131. var ele = arr[i++];
  10132. if (!re.test(ele)) {
  10133. continue;
  10134. }
  10135. res.splice(i, 1);
  10136. }
  10137. return res;
  10138. };
  10139. /*!
  10140. * is-extglob <https://github.com/jonschlinkert/is-extglob>
  10141. *
  10142. * Copyright (c) 2014-2015, Jon Schlinkert.
  10143. * Licensed under the MIT License.
  10144. */
  10145. var isExtglob = function isExtglob(str) {
  10146. return typeof str === 'string'
  10147. && /[@?!+*]\(/.test(str);
  10148. };
  10149. /**
  10150. * Module dependencies
  10151. */
  10152. var re;
  10153. var cache$2 = {};
  10154. /**
  10155. * Expose `extglob`
  10156. */
  10157. var extglob_1 = extglob;
  10158. /**
  10159. * Convert the given extglob `string` to a regex-compatible
  10160. * string.
  10161. *
  10162. * ```js
  10163. * var extglob = require('extglob');
  10164. * extglob('!(a?(b))');
  10165. * //=> '(?!a(?:b)?)[^/]*?'
  10166. * ```
  10167. *
  10168. * @param {String} `str` The string to convert.
  10169. * @param {Object} `options`
  10170. * @option {Boolean} [options] `esc` If `false` special characters will not be escaped. Defaults to `true`.
  10171. * @option {Boolean} [options] `regex` If `true` a regular expression is returned instead of a string.
  10172. * @return {String}
  10173. * @api public
  10174. */
  10175. function extglob(str, opts) {
  10176. opts = opts || {};
  10177. var o = {}, i = 0;
  10178. // fix common character reversals
  10179. // '*!(.js)' => '*.!(js)'
  10180. str = str.replace(/!\(([^\w*()])/g, '$1!(');
  10181. // support file extension negation
  10182. str = str.replace(/([*\/])\.!\([*]\)/g, function (m, ch) {
  10183. if (ch === '/') {
  10184. return escape('\\/[^.]+');
  10185. }
  10186. return escape('[^.]+');
  10187. });
  10188. // create a unique key for caching by
  10189. // combining the string and options
  10190. var key = str
  10191. + String(!!opts.regex)
  10192. + String(!!opts.contains)
  10193. + String(!!opts.escape);
  10194. if (cache$2.hasOwnProperty(key)) {
  10195. return cache$2[key];
  10196. }
  10197. if (!(re instanceof RegExp)) {
  10198. re = regex();
  10199. }
  10200. opts.negate = false;
  10201. var m;
  10202. while (m = re.exec(str)) {
  10203. var prefix = m[1];
  10204. var inner = m[3];
  10205. if (prefix === '!') {
  10206. opts.negate = true;
  10207. }
  10208. var id = '__EXTGLOB_' + (i++) + '__';
  10209. // use the prefix of the _last_ (outtermost) pattern
  10210. o[id] = wrap$2(inner, prefix, opts.escape);
  10211. str = str.split(m[0]).join(id);
  10212. }
  10213. var keys = Object.keys(o);
  10214. var len = keys.length;
  10215. // we have to loop again to allow us to convert
  10216. // patterns in reverse order (starting with the
  10217. // innermost/last pattern first)
  10218. while (len--) {
  10219. var prop = keys[len];
  10220. str = str.split(prop).join(o[prop]);
  10221. }
  10222. var result = opts.regex
  10223. ? toRegex$1(str, opts.contains, opts.negate)
  10224. : str;
  10225. result = result.split('.').join('\\.');
  10226. // cache the result and return it
  10227. return (cache$2[key] = result);
  10228. }
  10229. /**
  10230. * Convert `string` to a regex string.
  10231. *
  10232. * @param {String} `str`
  10233. * @param {String} `prefix` Character that determines how to wrap the string.
  10234. * @param {Boolean} `esc` If `false` special characters will not be escaped. Defaults to `true`.
  10235. * @return {String}
  10236. */
  10237. function wrap$2(inner, prefix, esc) {
  10238. if (esc) inner = escape(inner);
  10239. switch (prefix) {
  10240. case '!':
  10241. return '(?!' + inner + ')[^/]' + (esc ? '%%%~' : '*?');
  10242. case '@':
  10243. return '(?:' + inner + ')';
  10244. case '+':
  10245. return '(?:' + inner + ')+';
  10246. case '*':
  10247. return '(?:' + inner + ')' + (esc ? '%%' : '*')
  10248. case '?':
  10249. return '(?:' + inner + '|)';
  10250. default:
  10251. return inner;
  10252. }
  10253. }
  10254. function escape(str) {
  10255. str = str.split('*').join('[^/]%%%~');
  10256. str = str.split('.').join('\\.');
  10257. return str;
  10258. }
  10259. /**
  10260. * extglob regex.
  10261. */
  10262. function regex() {
  10263. return /(\\?[@?!+*$]\\?)(\(([^()]*?)\))/;
  10264. }
  10265. /**
  10266. * Negation regex
  10267. */
  10268. function negate(str) {
  10269. return '(?!^' + str + ').*$';
  10270. }
  10271. /**
  10272. * Create the regex to do the matching. If
  10273. * the leading character in the `pattern` is `!`
  10274. * a negation regex is returned.
  10275. *
  10276. * @param {String} `pattern`
  10277. * @param {Boolean} `contains` Allow loose matching.
  10278. * @param {Boolean} `isNegated` True if the pattern is a negation pattern.
  10279. */
  10280. function toRegex$1(pattern, contains, isNegated) {
  10281. var prefix = contains ? '^' : '';
  10282. var after = contains ? '$' : '';
  10283. pattern = ('(?:' + pattern + ')' + after);
  10284. if (isNegated) {
  10285. pattern = prefix + negate(pattern);
  10286. }
  10287. return new RegExp(prefix + pattern);
  10288. }
  10289. /*!
  10290. * is-glob <https://github.com/jonschlinkert/is-glob>
  10291. *
  10292. * Copyright (c) 2014-2015, Jon Schlinkert.
  10293. * Licensed under the MIT License.
  10294. */
  10295. var isGlob = function isGlob(str) {
  10296. return typeof str === 'string'
  10297. && (/[*!?{}(|)[\]]/.test(str)
  10298. || isExtglob(str));
  10299. };
  10300. var isWin = process.platform === 'win32';
  10301. var removeTrailingSeparator = function (str) {
  10302. var i = str.length - 1;
  10303. if (i < 2) {
  10304. return str;
  10305. }
  10306. while (isSeparator(str, i)) {
  10307. i--;
  10308. }
  10309. return str.substr(0, i + 1);
  10310. };
  10311. function isSeparator(str, i) {
  10312. var char = str[i];
  10313. return i > 0 && (char === '/' || (isWin && char === '\\'));
  10314. }
  10315. /*!
  10316. * normalize-path <https://github.com/jonschlinkert/normalize-path>
  10317. *
  10318. * Copyright (c) 2014-2017, Jon Schlinkert.
  10319. * Released under the MIT License.
  10320. */
  10321. var normalizePath = function normalizePath(str, stripTrailing) {
  10322. if (typeof str !== 'string') {
  10323. throw new TypeError('expected a string');
  10324. }
  10325. str = str.replace(/[\\\/]+/g, '/');
  10326. if (stripTrailing !== false) {
  10327. str = removeTrailingSeparator(str);
  10328. }
  10329. return str;
  10330. };
  10331. /*!
  10332. * is-extendable <https://github.com/jonschlinkert/is-extendable>
  10333. *
  10334. * Copyright (c) 2015, Jon Schlinkert.
  10335. * Licensed under the MIT License.
  10336. */
  10337. var isExtendable = function isExtendable(val) {
  10338. return typeof val !== 'undefined' && val !== null
  10339. && (typeof val === 'object' || typeof val === 'function');
  10340. };
  10341. /*!
  10342. * for-in <https://github.com/jonschlinkert/for-in>
  10343. *
  10344. * Copyright (c) 2014-2017, Jon Schlinkert.
  10345. * Released under the MIT License.
  10346. */
  10347. var forIn = function forIn(obj, fn, thisArg) {
  10348. for (var key in obj) {
  10349. if (fn.call(thisArg, obj[key], key, obj) === false) {
  10350. break;
  10351. }
  10352. }
  10353. };
  10354. var hasOwn = Object.prototype.hasOwnProperty;
  10355. var forOwn$1 = function forOwn(obj, fn, thisArg) {
  10356. forIn(obj, function(val, key) {
  10357. if (hasOwn.call(obj, key)) {
  10358. return fn.call(thisArg, obj[key], key, obj);
  10359. }
  10360. });
  10361. };
  10362. var object_omit = function omit(obj, keys) {
  10363. if (!isExtendable(obj)) return {};
  10364. keys = [].concat.apply([], [].slice.call(arguments, 1));
  10365. var last = keys[keys.length - 1];
  10366. var res = {}, fn;
  10367. if (typeof last === 'function') {
  10368. fn = keys.pop();
  10369. }
  10370. var isFunction = typeof fn === 'function';
  10371. if (!keys.length && !isFunction) {
  10372. return obj;
  10373. }
  10374. forOwn$1(obj, function(value, key) {
  10375. if (keys.indexOf(key) === -1) {
  10376. if (!isFunction) {
  10377. res[key] = value;
  10378. } else if (fn(value, key, obj)) {
  10379. res[key] = value;
  10380. }
  10381. }
  10382. });
  10383. return res;
  10384. };
  10385. var globParent = function globParent(str) {
  10386. str += 'a'; // preserves full path in case of trailing path separator
  10387. do {str = path.dirname(str);} while (isGlob(str));
  10388. return str;
  10389. };
  10390. var globBase = function globBase(pattern) {
  10391. if (typeof pattern !== 'string') {
  10392. throw new TypeError('glob-base expects a string.');
  10393. }
  10394. var res = {};
  10395. res.base = globParent(pattern);
  10396. res.isGlob = isGlob(pattern);
  10397. if (res.base !== '.') {
  10398. res.glob = pattern.substr(res.base.length);
  10399. if (res.glob.charAt(0) === '/') {
  10400. res.glob = res.glob.substr(1);
  10401. }
  10402. } else {
  10403. res.glob = pattern;
  10404. }
  10405. if (!res.isGlob) {
  10406. res.base = dirname$1(pattern);
  10407. res.glob = res.base !== '.'
  10408. ? pattern.substr(res.base.length)
  10409. : pattern;
  10410. }
  10411. if (res.glob.substr(0, 2) === './') {
  10412. res.glob = res.glob.substr(2);
  10413. }
  10414. if (res.glob.charAt(0) === '/') {
  10415. res.glob = res.glob.substr(1);
  10416. }
  10417. return res;
  10418. };
  10419. function dirname$1(glob) {
  10420. if (glob.slice(-1) === '/') return glob;
  10421. return path.dirname(glob);
  10422. }
  10423. /*!
  10424. * is-dotfile <https://github.com/jonschlinkert/is-dotfile>
  10425. *
  10426. * Copyright (c) 2015-2017, Jon Schlinkert.
  10427. * Released under the MIT License.
  10428. */
  10429. var isDotfile = function(str) {
  10430. if (str.charCodeAt(0) === 46 /* . */ && str.indexOf('/', 1) === -1) {
  10431. return true;
  10432. }
  10433. var slash = str.lastIndexOf('/');
  10434. return slash !== -1 ? str.charCodeAt(slash + 1) === 46 /* . */ : false;
  10435. };
  10436. var parseGlob = createCommonjsModule(function (module) {
  10437. /*!
  10438. * parse-glob <https://github.com/jonschlinkert/parse-glob>
  10439. *
  10440. * Copyright (c) 2015, Jon Schlinkert.
  10441. * Licensed under the MIT License.
  10442. */
  10443. 'use strict';
  10444. /**
  10445. * Expose `cache`
  10446. */
  10447. var cache = module.exports.cache = {};
  10448. /**
  10449. * Parse a glob pattern into tokens.
  10450. *
  10451. * When no paths or '**' are in the glob, we use a
  10452. * different strategy for parsing the filename, since
  10453. * file names can contain braces and other difficult
  10454. * patterns. such as:
  10455. *
  10456. * - `*.{a,b}`
  10457. * - `(**|*.js)`
  10458. */
  10459. module.exports = function parseGlob(glob) {
  10460. if (cache.hasOwnProperty(glob)) {
  10461. return cache[glob];
  10462. }
  10463. var tok = {};
  10464. tok.orig = glob;
  10465. tok.is = {};
  10466. // unescape dots and slashes in braces/brackets
  10467. glob = escape(glob);
  10468. var parsed = globBase(glob);
  10469. tok.is.glob = parsed.isGlob;
  10470. tok.glob = parsed.glob;
  10471. tok.base = parsed.base;
  10472. var segs = /([^\/]*)$/.exec(glob);
  10473. tok.path = {};
  10474. tok.path.dirname = '';
  10475. tok.path.basename = segs[1] || '';
  10476. tok.path.dirname = glob.split(tok.path.basename).join('') || '';
  10477. var basename$$1 = (tok.path.basename || '').split('.') || '';
  10478. tok.path.filename = basename$$1[0] || '';
  10479. tok.path.extname = basename$$1.slice(1).join('.') || '';
  10480. tok.path.ext = '';
  10481. if (isGlob(tok.path.dirname) && !tok.path.basename) {
  10482. if (!/\/$/.test(tok.glob)) {
  10483. tok.path.basename = tok.glob;
  10484. }
  10485. tok.path.dirname = tok.base;
  10486. }
  10487. if (glob.indexOf('/') === -1 && !tok.is.globstar) {
  10488. tok.path.dirname = '';
  10489. tok.path.basename = tok.orig;
  10490. }
  10491. var dot = tok.path.basename.indexOf('.');
  10492. if (dot !== -1) {
  10493. tok.path.filename = tok.path.basename.slice(0, dot);
  10494. tok.path.extname = tok.path.basename.slice(dot);
  10495. }
  10496. if (tok.path.extname.charAt(0) === '.') {
  10497. var exts = tok.path.extname.split('.');
  10498. tok.path.ext = exts[exts.length - 1];
  10499. }
  10500. // unescape dots and slashes in braces/brackets
  10501. tok.glob = unescape(tok.glob);
  10502. tok.path.dirname = unescape(tok.path.dirname);
  10503. tok.path.basename = unescape(tok.path.basename);
  10504. tok.path.filename = unescape(tok.path.filename);
  10505. tok.path.extname = unescape(tok.path.extname);
  10506. // Booleans
  10507. var is = (glob && tok.is.glob);
  10508. tok.is.negated = glob && glob.charAt(0) === '!';
  10509. tok.is.extglob = glob && isExtglob(glob);
  10510. tok.is.braces = has(is, glob, '{');
  10511. tok.is.brackets = has(is, glob, '[:');
  10512. tok.is.globstar = has(is, glob, '**');
  10513. tok.is.dotfile = isDotfile(tok.path.basename) || isDotfile(tok.path.filename);
  10514. tok.is.dotdir = dotdir(tok.path.dirname);
  10515. return (cache[glob] = tok);
  10516. };
  10517. /**
  10518. * Returns true if the glob matches dot-directories.
  10519. *
  10520. * @param {Object} `tok` The tokens object
  10521. * @param {Object} `path` The path object
  10522. * @return {Object}
  10523. */
  10524. function dotdir(base) {
  10525. if (base.indexOf('/.') !== -1) {
  10526. return true;
  10527. }
  10528. if (base.charAt(0) === '.' && base.charAt(1) !== '/') {
  10529. return true;
  10530. }
  10531. return false;
  10532. }
  10533. /**
  10534. * Returns true if the pattern has the given `ch`aracter(s)
  10535. *
  10536. * @param {Object} `glob` The glob pattern.
  10537. * @param {Object} `ch` The character to test for
  10538. * @return {Object}
  10539. */
  10540. function has(is, glob, ch) {
  10541. return is && glob.indexOf(ch) !== -1;
  10542. }
  10543. /**
  10544. * Escape/unescape utils
  10545. */
  10546. function escape(str) {
  10547. var re = /\{([^{}]*?)}|\(([^()]*?)\)|\[([^\[\]]*?)\]/g;
  10548. return str.replace(re, function (outter, braces, parens, brackets) {
  10549. var inner = braces || parens || brackets;
  10550. if (!inner) { return outter; }
  10551. return outter.split(inner).join(esc(inner));
  10552. });
  10553. }
  10554. function esc(str) {
  10555. str = str.split('/').join('__SLASH__');
  10556. str = str.split('.').join('__DOT__');
  10557. return str;
  10558. }
  10559. function unescape(str) {
  10560. str = str.split('__SLASH__').join('/');
  10561. str = str.split('__DOT__').join('.');
  10562. return str;
  10563. }
  10564. });
  10565. /*!
  10566. * is-primitive <https://github.com/jonschlinkert/is-primitive>
  10567. *
  10568. * Copyright (c) 2014-2015, Jon Schlinkert.
  10569. * Licensed under the MIT License.
  10570. */
  10571. // see http://jsperf.com/testing-value-is-primitive/7
  10572. var isPrimitive = function isPrimitive(value) {
  10573. return value == null || (typeof value !== 'function' && typeof value !== 'object');
  10574. };
  10575. var isEqualShallow = function isEqual(a, b) {
  10576. if (!a && !b) { return true; }
  10577. if (!a && b || a && !b) { return false; }
  10578. var numKeysA = 0, numKeysB = 0, key;
  10579. for (key in b) {
  10580. numKeysB++;
  10581. if (!isPrimitive(b[key]) || !a.hasOwnProperty(key) || (a[key] !== b[key])) {
  10582. return false;
  10583. }
  10584. }
  10585. for (key in a) {
  10586. numKeysA++;
  10587. }
  10588. return numKeysA === numKeysB;
  10589. };
  10590. var basic = {};
  10591. var cache$3 = {};
  10592. /**
  10593. * Expose `regexCache`
  10594. */
  10595. var regexCache_1 = regexCache;
  10596. /**
  10597. * Memoize the results of a call to the new RegExp constructor.
  10598. *
  10599. * @param {Function} fn [description]
  10600. * @param {String} str [description]
  10601. * @param {Options} options [description]
  10602. * @param {Boolean} nocompare [description]
  10603. * @return {RegExp}
  10604. */
  10605. function regexCache(fn, str, opts) {
  10606. var key = '_default_', regex, cached;
  10607. if (!str && !opts) {
  10608. if (typeof fn !== 'function') {
  10609. return fn;
  10610. }
  10611. return basic[key] || (basic[key] = fn(str));
  10612. }
  10613. var isString = typeof str === 'string';
  10614. if (isString) {
  10615. if (!opts) {
  10616. return basic[str] || (basic[str] = fn(str));
  10617. }
  10618. key = str;
  10619. } else {
  10620. opts = str;
  10621. }
  10622. cached = cache$3[key];
  10623. if (cached && isEqualShallow(cached.opts, opts)) {
  10624. return cached.regex;
  10625. }
  10626. memo(key, opts, (regex = fn(str, opts)));
  10627. return regex;
  10628. }
  10629. function memo(key, opts, regex) {
  10630. cache$3[key] = {regex: regex, opts: opts};
  10631. }
  10632. /**
  10633. * Expose `cache`
  10634. */
  10635. var cache_1 = cache$3;
  10636. var basic_1 = basic;
  10637. regexCache_1.cache = cache_1;
  10638. regexCache_1.basic = basic_1;
  10639. var utils_1 = createCommonjsModule(function (module) {
  10640. 'use strict';
  10641. var win32 = process && process.platform === 'win32';
  10642. var utils = module.exports;
  10643. /**
  10644. * Module dependencies
  10645. */
  10646. utils.diff = arrDiff;
  10647. utils.unique = arrayUnique;
  10648. utils.braces = braces_1;
  10649. utils.brackets = expandBrackets;
  10650. utils.extglob = extglob_1;
  10651. utils.isExtglob = isExtglob;
  10652. utils.isGlob = isGlob;
  10653. utils.typeOf = kindOf;
  10654. utils.normalize = normalizePath;
  10655. utils.omit = object_omit;
  10656. utils.parseGlob = parseGlob;
  10657. utils.cache = regexCache_1;
  10658. /**
  10659. * Get the filename of a filepath
  10660. *
  10661. * @param {String} `string`
  10662. * @return {String}
  10663. */
  10664. utils.filename = function filename(fp) {
  10665. var seg = fp.match(filenameRegex());
  10666. return seg && seg[0];
  10667. };
  10668. /**
  10669. * Returns a function that returns true if the given
  10670. * pattern is the same as a given `filepath`
  10671. *
  10672. * @param {String} `pattern`
  10673. * @return {Function}
  10674. */
  10675. utils.isPath = function isPath(pattern, opts) {
  10676. opts = opts || {};
  10677. return function(fp) {
  10678. var unixified = utils.unixify(fp, opts);
  10679. if(opts.nocase){
  10680. return pattern.toLowerCase() === unixified.toLowerCase();
  10681. }
  10682. return pattern === unixified;
  10683. };
  10684. };
  10685. /**
  10686. * Returns a function that returns true if the given
  10687. * pattern contains a `filepath`
  10688. *
  10689. * @param {String} `pattern`
  10690. * @return {Function}
  10691. */
  10692. utils.hasPath = function hasPath(pattern, opts) {
  10693. return function(fp) {
  10694. return utils.unixify(pattern, opts).indexOf(fp) !== -1;
  10695. };
  10696. };
  10697. /**
  10698. * Returns a function that returns true if the given
  10699. * pattern matches or contains a `filepath`
  10700. *
  10701. * @param {String} `pattern`
  10702. * @return {Function}
  10703. */
  10704. utils.matchPath = function matchPath(pattern, opts) {
  10705. var fn = (opts && opts.contains)
  10706. ? utils.hasPath(pattern, opts)
  10707. : utils.isPath(pattern, opts);
  10708. return fn;
  10709. };
  10710. /**
  10711. * Returns a function that returns true if the given
  10712. * regex matches the `filename` of a file path.
  10713. *
  10714. * @param {RegExp} `re`
  10715. * @return {Boolean}
  10716. */
  10717. utils.hasFilename = function hasFilename(re) {
  10718. return function(fp) {
  10719. var name = utils.filename(fp);
  10720. return name && re.test(name);
  10721. };
  10722. };
  10723. /**
  10724. * Coerce `val` to an array
  10725. *
  10726. * @param {*} val
  10727. * @return {Array}
  10728. */
  10729. utils.arrayify = function arrayify(val) {
  10730. return !Array.isArray(val)
  10731. ? [val]
  10732. : val;
  10733. };
  10734. /**
  10735. * Normalize all slashes in a file path or glob pattern to
  10736. * forward slashes.
  10737. */
  10738. utils.unixify = function unixify(fp, opts) {
  10739. if (opts && opts.unixify === false) return fp;
  10740. if (opts && opts.unixify === true || win32 || path.sep === '\\') {
  10741. return utils.normalize(fp, false);
  10742. }
  10743. if (opts && opts.unescape === true) {
  10744. return fp ? fp.toString().replace(/\\(\w)/g, '$1') : '';
  10745. }
  10746. return fp;
  10747. };
  10748. /**
  10749. * Escape/unescape utils
  10750. */
  10751. utils.escapePath = function escapePath(fp) {
  10752. return fp.replace(/[\\.]/g, '\\$&');
  10753. };
  10754. utils.unescapeGlob = function unescapeGlob(fp) {
  10755. return fp.replace(/[\\"']/g, '');
  10756. };
  10757. utils.escapeRe = function escapeRe(str) {
  10758. return str.replace(/[-[\\$*+?.#^\s{}(|)\]]/g, '\\$&');
  10759. };
  10760. /**
  10761. * Expose `utils`
  10762. */
  10763. module.exports = utils;
  10764. });
  10765. var chars = {};
  10766. var unesc;
  10767. var temp;
  10768. function reverse(object, prepender) {
  10769. return Object.keys(object).reduce(function(reversed, key) {
  10770. var newKey = prepender ? prepender + key : key; // Optionally prepend a string to key.
  10771. reversed[object[key]] = newKey; // Swap key and value.
  10772. return reversed; // Return the result.
  10773. }, {});
  10774. }
  10775. /**
  10776. * Regex for common characters
  10777. */
  10778. chars.escapeRegex = {
  10779. '?': /\?/g,
  10780. '@': /\@/g,
  10781. '!': /\!/g,
  10782. '+': /\+/g,
  10783. '*': /\*/g,
  10784. '(': /\(/g,
  10785. ')': /\)/g,
  10786. '[': /\[/g,
  10787. ']': /\]/g
  10788. };
  10789. /**
  10790. * Escape characters
  10791. */
  10792. chars.ESC = {
  10793. '?': '__UNESC_QMRK__',
  10794. '@': '__UNESC_AMPE__',
  10795. '!': '__UNESC_EXCL__',
  10796. '+': '__UNESC_PLUS__',
  10797. '*': '__UNESC_STAR__',
  10798. ',': '__UNESC_COMMA__',
  10799. '(': '__UNESC_LTPAREN__',
  10800. ')': '__UNESC_RTPAREN__',
  10801. '[': '__UNESC_LTBRACK__',
  10802. ']': '__UNESC_RTBRACK__'
  10803. };
  10804. /**
  10805. * Unescape characters
  10806. */
  10807. chars.UNESC = unesc || (unesc = reverse(chars.ESC, '\\'));
  10808. chars.ESC_TEMP = {
  10809. '?': '__TEMP_QMRK__',
  10810. '@': '__TEMP_AMPE__',
  10811. '!': '__TEMP_EXCL__',
  10812. '*': '__TEMP_STAR__',
  10813. '+': '__TEMP_PLUS__',
  10814. ',': '__TEMP_COMMA__',
  10815. '(': '__TEMP_LTPAREN__',
  10816. ')': '__TEMP_RTPAREN__',
  10817. '[': '__TEMP_LTBRACK__',
  10818. ']': '__TEMP_RTBRACK__'
  10819. };
  10820. chars.TEMP = temp || (temp = reverse(chars.ESC_TEMP));
  10821. var chars_1 = chars;
  10822. var glob = createCommonjsModule(function (module) {
  10823. 'use strict';
  10824. /**
  10825. * Expose `Glob`
  10826. */
  10827. var Glob = module.exports = function Glob(pattern, options) {
  10828. if (!(this instanceof Glob)) {
  10829. return new Glob(pattern, options);
  10830. }
  10831. this.options = options || {};
  10832. this.pattern = pattern;
  10833. this.history = [];
  10834. this.tokens = {};
  10835. this.init(pattern);
  10836. };
  10837. /**
  10838. * Initialize defaults
  10839. */
  10840. Glob.prototype.init = function(pattern) {
  10841. this.orig = pattern;
  10842. this.negated = this.isNegated();
  10843. this.options.track = this.options.track || false;
  10844. this.options.makeRe = true;
  10845. };
  10846. /**
  10847. * Push a change into `glob.history`. Useful
  10848. * for debugging.
  10849. */
  10850. Glob.prototype.track = function(msg) {
  10851. if (this.options.track) {
  10852. this.history.push({msg: msg, pattern: this.pattern});
  10853. }
  10854. };
  10855. /**
  10856. * Return true if `glob.pattern` was negated
  10857. * with `!`, also remove the `!` from the pattern.
  10858. *
  10859. * @return {Boolean}
  10860. */
  10861. Glob.prototype.isNegated = function() {
  10862. if (this.pattern.charCodeAt(0) === 33 /* '!' */) {
  10863. this.pattern = this.pattern.slice(1);
  10864. return true;
  10865. }
  10866. return false;
  10867. };
  10868. /**
  10869. * Expand braces in the given glob pattern.
  10870. *
  10871. * We only need to use the [braces] lib when
  10872. * patterns are nested.
  10873. */
  10874. Glob.prototype.braces = function() {
  10875. if (this.options.nobraces !== true && this.options.nobrace !== true) {
  10876. // naive/fast check for imbalanced characters
  10877. var a = this.pattern.match(/[\{\(\[]/g);
  10878. var b = this.pattern.match(/[\}\)\]]/g);
  10879. // if imbalanced, don't optimize the pattern
  10880. if (a && b && (a.length !== b.length)) {
  10881. this.options.makeRe = false;
  10882. }
  10883. // expand brace patterns and join the resulting array
  10884. var expanded = utils_1.braces(this.pattern, this.options);
  10885. this.pattern = expanded.join('|');
  10886. }
  10887. };
  10888. /**
  10889. * Expand bracket expressions in `glob.pattern`
  10890. */
  10891. Glob.prototype.brackets = function() {
  10892. if (this.options.nobrackets !== true) {
  10893. this.pattern = utils_1.brackets(this.pattern);
  10894. }
  10895. };
  10896. /**
  10897. * Expand bracket expressions in `glob.pattern`
  10898. */
  10899. Glob.prototype.extglob = function() {
  10900. if (this.options.noextglob === true) return;
  10901. if (utils_1.isExtglob(this.pattern)) {
  10902. this.pattern = utils_1.extglob(this.pattern, {escape: true});
  10903. }
  10904. };
  10905. /**
  10906. * Parse the given pattern
  10907. */
  10908. Glob.prototype.parse = function(pattern) {
  10909. this.tokens = utils_1.parseGlob(pattern || this.pattern, true);
  10910. return this.tokens;
  10911. };
  10912. /**
  10913. * Replace `a` with `b`. Also tracks the change before and
  10914. * after each replacement. This is disabled by default, but
  10915. * can be enabled by setting `options.track` to true.
  10916. *
  10917. * Also, when the pattern is a string, `.split()` is used,
  10918. * because it's much faster than replace.
  10919. *
  10920. * @param {RegExp|String} `a`
  10921. * @param {String} `b`
  10922. * @param {Boolean} `escape` When `true`, escapes `*` and `?` in the replacement.
  10923. * @return {String}
  10924. */
  10925. Glob.prototype._replace = function(a, b, escape) {
  10926. this.track('before (find): "' + a + '" (replace with): "' + b + '"');
  10927. if (escape) b = esc(b);
  10928. if (a && b && typeof a === 'string') {
  10929. this.pattern = this.pattern.split(a).join(b);
  10930. } else {
  10931. this.pattern = this.pattern.replace(a, b);
  10932. }
  10933. this.track('after');
  10934. };
  10935. /**
  10936. * Escape special characters in the given string.
  10937. *
  10938. * @param {String} `str` Glob pattern
  10939. * @return {String}
  10940. */
  10941. Glob.prototype.escape = function(str) {
  10942. this.track('before escape: ');
  10943. var re = /["\\](['"]?[^"'\\]['"]?)/g;
  10944. this.pattern = str.replace(re, function($0, $1) {
  10945. var o = chars_1.ESC;
  10946. var ch = o && o[$1];
  10947. if (ch) {
  10948. return ch;
  10949. }
  10950. if (/[a-z]/i.test($0)) {
  10951. return $0.split('\\').join('');
  10952. }
  10953. return $0;
  10954. });
  10955. this.track('after escape: ');
  10956. };
  10957. /**
  10958. * Unescape special characters in the given string.
  10959. *
  10960. * @param {String} `str`
  10961. * @return {String}
  10962. */
  10963. Glob.prototype.unescape = function(str) {
  10964. var re = /__([A-Z]+)_([A-Z]+)__/g;
  10965. this.pattern = str.replace(re, function($0, $1) {
  10966. return chars_1[$1][$0];
  10967. });
  10968. this.pattern = unesc(this.pattern);
  10969. };
  10970. /**
  10971. * Escape/unescape utils
  10972. */
  10973. function esc(str) {
  10974. str = str.split('?').join('%~');
  10975. str = str.split('*').join('%%');
  10976. return str;
  10977. }
  10978. function unesc(str) {
  10979. str = str.split('%~').join('?');
  10980. str = str.split('%%').join('*');
  10981. return str;
  10982. }
  10983. });
  10984. /**
  10985. * Expose `expand`
  10986. */
  10987. var expand_1 = expand;
  10988. /**
  10989. * Expand a glob pattern to resolve braces and
  10990. * similar patterns before converting to regex.
  10991. *
  10992. * @param {String|Array} `pattern`
  10993. * @param {Array} `files`
  10994. * @param {Options} `opts`
  10995. * @return {Array}
  10996. */
  10997. function expand(pattern, options) {
  10998. if (typeof pattern !== 'string') {
  10999. throw new TypeError('micromatch.expand(): argument should be a string.');
  11000. }
  11001. var glob$$1 = new glob(pattern, options || {});
  11002. var opts = glob$$1.options;
  11003. if (!utils_1.isGlob(pattern)) {
  11004. glob$$1.pattern = glob$$1.pattern.replace(/([\/.])/g, '\\$1');
  11005. return glob$$1;
  11006. }
  11007. glob$$1.pattern = glob$$1.pattern.replace(/(\+)(?!\()/g, '\\$1');
  11008. glob$$1.pattern = glob$$1.pattern.split('$').join('\\$');
  11009. if (typeof opts.braces !== 'boolean' && typeof opts.nobraces !== 'boolean') {
  11010. opts.braces = true;
  11011. }
  11012. if (glob$$1.pattern === '.*') {
  11013. return {
  11014. pattern: '\\.' + star,
  11015. tokens: tok,
  11016. options: opts
  11017. };
  11018. }
  11019. if (glob$$1.pattern === '*') {
  11020. return {
  11021. pattern: oneStar(opts.dot),
  11022. tokens: tok,
  11023. options: opts
  11024. };
  11025. }
  11026. // parse the glob pattern into tokens
  11027. glob$$1.parse();
  11028. var tok = glob$$1.tokens;
  11029. tok.is.negated = opts.negated;
  11030. // dotfile handling
  11031. if ((opts.dotfiles === true || tok.is.dotfile) && opts.dot !== false) {
  11032. opts.dotfiles = true;
  11033. opts.dot = true;
  11034. }
  11035. if ((opts.dotdirs === true || tok.is.dotdir) && opts.dot !== false) {
  11036. opts.dotdirs = true;
  11037. opts.dot = true;
  11038. }
  11039. // check for braces with a dotfile pattern
  11040. if (/[{,]\./.test(glob$$1.pattern)) {
  11041. opts.makeRe = false;
  11042. opts.dot = true;
  11043. }
  11044. if (opts.nonegate !== true) {
  11045. opts.negated = glob$$1.negated;
  11046. }
  11047. // if the leading character is a dot or a slash, escape it
  11048. if (glob$$1.pattern.charAt(0) === '.' && glob$$1.pattern.charAt(1) !== '/') {
  11049. glob$$1.pattern = '\\' + glob$$1.pattern;
  11050. }
  11051. /**
  11052. * Extended globs
  11053. */
  11054. // expand braces, e.g `{1..5}`
  11055. glob$$1.track('before braces');
  11056. if (tok.is.braces) {
  11057. glob$$1.braces();
  11058. }
  11059. glob$$1.track('after braces');
  11060. // expand extglobs, e.g `foo/!(a|b)`
  11061. glob$$1.track('before extglob');
  11062. if (tok.is.extglob) {
  11063. glob$$1.extglob();
  11064. }
  11065. glob$$1.track('after extglob');
  11066. // expand brackets, e.g `[[:alpha:]]`
  11067. glob$$1.track('before brackets');
  11068. if (tok.is.brackets) {
  11069. glob$$1.brackets();
  11070. }
  11071. glob$$1.track('after brackets');
  11072. // special patterns
  11073. glob$$1._replace('[!', '[^');
  11074. glob$$1._replace('(?', '(%~');
  11075. glob$$1._replace(/\[\]/, '\\[\\]');
  11076. glob$$1._replace('/[', '/' + (opts.dot ? dotfiles : nodot) + '[', true);
  11077. glob$$1._replace('/?', '/' + (opts.dot ? dotfiles : nodot) + '[^/]', true);
  11078. glob$$1._replace('/.', '/(?=.)\\.', true);
  11079. // windows drives
  11080. glob$$1._replace(/^(\w):([\\\/]+?)/gi, '(?=.)$1:$2', true);
  11081. // negate slashes in exclusion ranges
  11082. if (glob$$1.pattern.indexOf('[^') !== -1) {
  11083. glob$$1.pattern = negateSlash(glob$$1.pattern);
  11084. }
  11085. if (opts.globstar !== false && glob$$1.pattern === '**') {
  11086. glob$$1.pattern = globstar(opts.dot);
  11087. } else {
  11088. glob$$1.pattern = balance(glob$$1.pattern, '[', ']');
  11089. glob$$1.escape(glob$$1.pattern);
  11090. // if the pattern has `**`
  11091. if (tok.is.globstar) {
  11092. glob$$1.pattern = collapse(glob$$1.pattern, '/**');
  11093. glob$$1.pattern = collapse(glob$$1.pattern, '**/');
  11094. glob$$1._replace('/**/', '(?:/' + globstar(opts.dot) + '/|/)', true);
  11095. glob$$1._replace(/\*{2,}/g, '**');
  11096. // 'foo/*'
  11097. glob$$1._replace(/(\w+)\*(?!\/)/g, '$1[^/]*?', true);
  11098. glob$$1._replace(/\*\*\/\*(\w)/g, globstar(opts.dot) + '\\/' + (opts.dot ? dotfiles : nodot) + '[^/]*?$1', true);
  11099. if (opts.dot !== true) {
  11100. glob$$1._replace(/\*\*\/(.)/g, '(?:**\\/|)$1');
  11101. }
  11102. // 'foo/**' or '{**,*}', but not 'foo**'
  11103. if (tok.path.dirname !== '' || /,\*\*|\*\*,/.test(glob$$1.orig)) {
  11104. glob$$1._replace('**', globstar(opts.dot), true);
  11105. }
  11106. }
  11107. // ends with /*
  11108. glob$$1._replace(/\/\*$/, '\\/' + oneStar(opts.dot), true);
  11109. // ends with *, no slashes
  11110. glob$$1._replace(/(?!\/)\*$/, star, true);
  11111. // has 'n*.' (partial wildcard w/ file extension)
  11112. glob$$1._replace(/([^\/]+)\*/, '$1' + oneStar(true), true);
  11113. // has '*'
  11114. glob$$1._replace('*', oneStar(opts.dot), true);
  11115. glob$$1._replace('?.', '?\\.', true);
  11116. glob$$1._replace('?:', '?:', true);
  11117. glob$$1._replace(/\?+/g, function(match) {
  11118. var len = match.length;
  11119. if (len === 1) {
  11120. return qmark;
  11121. }
  11122. return qmark + '{' + len + '}';
  11123. });
  11124. // escape '.abc' => '\\.abc'
  11125. glob$$1._replace(/\.([*\w]+)/g, '\\.$1');
  11126. // fix '[^\\\\/]'
  11127. glob$$1._replace(/\[\^[\\\/]+\]/g, qmark);
  11128. // '///' => '\/'
  11129. glob$$1._replace(/\/+/g, '\\/');
  11130. // '\\\\\\' => '\\'
  11131. glob$$1._replace(/\\{2,}/g, '\\');
  11132. }
  11133. // unescape previously escaped patterns
  11134. glob$$1.unescape(glob$$1.pattern);
  11135. glob$$1._replace('__UNESC_STAR__', '*');
  11136. // escape dots that follow qmarks
  11137. glob$$1._replace('?.', '?\\.');
  11138. // remove unnecessary slashes in character classes
  11139. glob$$1._replace('[^\\/]', qmark);
  11140. if (glob$$1.pattern.length > 1) {
  11141. if (/^[\[?*]/.test(glob$$1.pattern)) {
  11142. // only prepend the string if we don't want to match dotfiles
  11143. glob$$1.pattern = (opts.dot ? dotfiles : nodot) + glob$$1.pattern;
  11144. }
  11145. }
  11146. return glob$$1;
  11147. }
  11148. /**
  11149. * Collapse repeated character sequences.
  11150. *
  11151. * ```js
  11152. * collapse('a/../../../b', '../');
  11153. * //=> 'a/../b'
  11154. * ```
  11155. *
  11156. * @param {String} `str`
  11157. * @param {String} `ch` Character sequence to collapse
  11158. * @return {String}
  11159. */
  11160. function collapse(str, ch) {
  11161. var res = str.split(ch);
  11162. var isFirst = res[0] === '';
  11163. var isLast = res[res.length - 1] === '';
  11164. res = res.filter(Boolean);
  11165. if (isFirst) res.unshift('');
  11166. if (isLast) res.push('');
  11167. return res.join(ch);
  11168. }
  11169. /**
  11170. * Negate slashes in exclusion ranges, per glob spec:
  11171. *
  11172. * ```js
  11173. * negateSlash('[^foo]');
  11174. * //=> '[^\\/foo]'
  11175. * ```
  11176. *
  11177. * @param {String} `str` glob pattern
  11178. * @return {String}
  11179. */
  11180. function negateSlash(str) {
  11181. return str.replace(/\[\^([^\]]*?)\]/g, function(match, inner) {
  11182. if (inner.indexOf('/') === -1) {
  11183. inner = '\\/' + inner;
  11184. }
  11185. return '[^' + inner + ']';
  11186. });
  11187. }
  11188. /**
  11189. * Escape imbalanced braces/bracket. This is a very
  11190. * basic, naive implementation that only does enough
  11191. * to serve the purpose.
  11192. */
  11193. function balance(str, a, b) {
  11194. var aarr = str.split(a);
  11195. var alen = aarr.join('').length;
  11196. var blen = str.split(b).join('').length;
  11197. if (alen !== blen) {
  11198. str = aarr.join('\\' + a);
  11199. return str.split(b).join('\\' + b);
  11200. }
  11201. return str;
  11202. }
  11203. /**
  11204. * Special patterns to be converted to regex.
  11205. * Heuristics are used to simplify patterns
  11206. * and speed up processing.
  11207. */
  11208. /* eslint no-multi-spaces: 0 */
  11209. var qmark = '[^/]';
  11210. var star = qmark + '*?';
  11211. var nodot = '(?!\\.)(?=.)';
  11212. var dotfileGlob = '(?:\\/|^)\\.{1,2}($|\\/)';
  11213. var dotfiles = '(?!' + dotfileGlob + ')(?=.)';
  11214. var twoStarDot = '(?:(?!' + dotfileGlob + ').)*?';
  11215. /**
  11216. * Create a regex for `*`.
  11217. *
  11218. * If `dot` is true, or the pattern does not begin with
  11219. * a leading star, then return the simpler regex.
  11220. */
  11221. function oneStar(dotfile) {
  11222. return dotfile ? '(?!' + dotfileGlob + ')(?=.)' + star : (nodot + star);
  11223. }
  11224. function globstar(dotfile) {
  11225. if (dotfile) { return twoStarDot; }
  11226. return '(?:(?!(?:\\/|^)\\.).)*?';
  11227. }
  11228. /**
  11229. * The main function. Pass an array of filepaths,
  11230. * and a string or array of glob patterns
  11231. *
  11232. * @param {Array|String} `files`
  11233. * @param {Array|String} `patterns`
  11234. * @param {Object} `opts`
  11235. * @return {Array} Array of matches
  11236. */
  11237. function micromatch(files, patterns, opts) {
  11238. if (!files || !patterns) return [];
  11239. opts = opts || {};
  11240. if (typeof opts.cache === 'undefined') {
  11241. opts.cache = true;
  11242. }
  11243. if (!Array.isArray(patterns)) {
  11244. return match(files, patterns, opts);
  11245. }
  11246. var len = patterns.length, i = 0;
  11247. var omit = [], keep = [];
  11248. while (len--) {
  11249. var glob = patterns[i++];
  11250. if (typeof glob === 'string' && glob.charCodeAt(0) === 33 /* ! */) {
  11251. omit.push.apply(omit, match(files, glob.slice(1), opts));
  11252. } else {
  11253. keep.push.apply(keep, match(files, glob, opts));
  11254. }
  11255. }
  11256. return utils_1.diff(keep, omit);
  11257. }
  11258. /**
  11259. * Return an array of files that match the given glob pattern.
  11260. *
  11261. * This function is called by the main `micromatch` function If you only
  11262. * need to pass a single pattern you might get very minor speed improvements
  11263. * using this function.
  11264. *
  11265. * @param {Array} `files`
  11266. * @param {String} `pattern`
  11267. * @param {Object} `options`
  11268. * @return {Array}
  11269. */
  11270. function match(files, pattern, opts) {
  11271. if (utils_1.typeOf(files) !== 'string' && !Array.isArray(files)) {
  11272. throw new Error(msg('match', 'files', 'a string or array'));
  11273. }
  11274. files = utils_1.arrayify(files);
  11275. opts = opts || {};
  11276. var negate = opts.negate || false;
  11277. var orig = pattern;
  11278. if (typeof pattern === 'string') {
  11279. negate = pattern.charAt(0) === '!';
  11280. if (negate) {
  11281. pattern = pattern.slice(1);
  11282. }
  11283. // we need to remove the character regardless,
  11284. // so the above logic is still needed
  11285. if (opts.nonegate === true) {
  11286. negate = false;
  11287. }
  11288. }
  11289. var _isMatch = matcher(pattern, opts);
  11290. var len = files.length, i = 0;
  11291. var res = [];
  11292. while (i < len) {
  11293. var file = files[i++];
  11294. var fp = utils_1.unixify(file, opts);
  11295. if (!_isMatch(fp)) { continue; }
  11296. res.push(fp);
  11297. }
  11298. if (res.length === 0) {
  11299. if (opts.failglob === true) {
  11300. throw new Error('micromatch.match() found no matches for: "' + orig + '".');
  11301. }
  11302. if (opts.nonull || opts.nullglob) {
  11303. res.push(utils_1.unescapeGlob(orig));
  11304. }
  11305. }
  11306. // if `negate` was defined, diff negated files
  11307. if (negate) { res = utils_1.diff(files, res); }
  11308. // if `ignore` was defined, diff ignored filed
  11309. if (opts.ignore && opts.ignore.length) {
  11310. pattern = opts.ignore;
  11311. opts = utils_1.omit(opts, ['ignore']);
  11312. res = utils_1.diff(res, micromatch(res, pattern, opts));
  11313. }
  11314. if (opts.nodupes) {
  11315. return utils_1.unique(res);
  11316. }
  11317. return res;
  11318. }
  11319. /**
  11320. * Returns a function that takes a glob pattern or array of glob patterns
  11321. * to be used with `Array#filter()`. (Internally this function generates
  11322. * the matching function using the [matcher] method).
  11323. *
  11324. * ```js
  11325. * var fn = mm.filter('[a-c]');
  11326. * ['a', 'b', 'c', 'd', 'e'].filter(fn);
  11327. * //=> ['a', 'b', 'c']
  11328. * ```
  11329. * @param {String|Array} `patterns` Can be a glob or array of globs.
  11330. * @param {Options} `opts` Options to pass to the [matcher] method.
  11331. * @return {Function} Filter function to be passed to `Array#filter()`.
  11332. */
  11333. function filter(patterns, opts) {
  11334. if (!Array.isArray(patterns) && typeof patterns !== 'string') {
  11335. throw new TypeError(msg('filter', 'patterns', 'a string or array'));
  11336. }
  11337. patterns = utils_1.arrayify(patterns);
  11338. var len = patterns.length, i = 0;
  11339. var patternMatchers = Array(len);
  11340. while (i < len) {
  11341. patternMatchers[i] = matcher(patterns[i++], opts);
  11342. }
  11343. return function(fp) {
  11344. if (fp == null) return [];
  11345. var len = patternMatchers.length, i = 0;
  11346. var res = true;
  11347. fp = utils_1.unixify(fp, opts);
  11348. while (i < len) {
  11349. var fn = patternMatchers[i++];
  11350. if (!fn(fp)) {
  11351. res = false;
  11352. break;
  11353. }
  11354. }
  11355. return res;
  11356. };
  11357. }
  11358. /**
  11359. * Returns true if the filepath contains the given
  11360. * pattern. Can also return a function for matching.
  11361. *
  11362. * ```js
  11363. * isMatch('foo.md', '*.md', {});
  11364. * //=> true
  11365. *
  11366. * isMatch('*.md', {})('foo.md')
  11367. * //=> true
  11368. * ```
  11369. * @param {String} `fp`
  11370. * @param {String} `pattern`
  11371. * @param {Object} `opts`
  11372. * @return {Boolean}
  11373. */
  11374. function isMatch(fp, pattern, opts) {
  11375. if (typeof fp !== 'string') {
  11376. throw new TypeError(msg('isMatch', 'filepath', 'a string'));
  11377. }
  11378. fp = utils_1.unixify(fp, opts);
  11379. if (utils_1.typeOf(pattern) === 'object') {
  11380. return matcher(fp, pattern);
  11381. }
  11382. return matcher(pattern, opts)(fp);
  11383. }
  11384. /**
  11385. * Returns true if the filepath matches the
  11386. * given pattern.
  11387. */
  11388. function contains(fp, pattern, opts) {
  11389. if (typeof fp !== 'string') {
  11390. throw new TypeError(msg('contains', 'pattern', 'a string'));
  11391. }
  11392. opts = opts || {};
  11393. opts.contains = (pattern !== '');
  11394. fp = utils_1.unixify(fp, opts);
  11395. if (opts.contains && !utils_1.isGlob(pattern)) {
  11396. return fp.indexOf(pattern) !== -1;
  11397. }
  11398. return matcher(pattern, opts)(fp);
  11399. }
  11400. /**
  11401. * Returns true if a file path matches any of the
  11402. * given patterns.
  11403. *
  11404. * @param {String} `fp` The filepath to test.
  11405. * @param {String|Array} `patterns` Glob patterns to use.
  11406. * @param {Object} `opts` Options to pass to the `matcher()` function.
  11407. * @return {String}
  11408. */
  11409. function any(fp, patterns, opts) {
  11410. if (!Array.isArray(patterns) && typeof patterns !== 'string') {
  11411. throw new TypeError(msg('any', 'patterns', 'a string or array'));
  11412. }
  11413. patterns = utils_1.arrayify(patterns);
  11414. var len = patterns.length;
  11415. fp = utils_1.unixify(fp, opts);
  11416. while (len--) {
  11417. var isMatch = matcher(patterns[len], opts);
  11418. if (isMatch(fp)) {
  11419. return true;
  11420. }
  11421. }
  11422. return false;
  11423. }
  11424. /**
  11425. * Filter the keys of an object with the given `glob` pattern
  11426. * and `options`
  11427. *
  11428. * @param {Object} `object`
  11429. * @param {Pattern} `object`
  11430. * @return {Array}
  11431. */
  11432. function matchKeys(obj, glob, options) {
  11433. if (utils_1.typeOf(obj) !== 'object') {
  11434. throw new TypeError(msg('matchKeys', 'first argument', 'an object'));
  11435. }
  11436. var fn = matcher(glob, options);
  11437. var res = {};
  11438. for (var key in obj) {
  11439. if (obj.hasOwnProperty(key) && fn(key)) {
  11440. res[key] = obj[key];
  11441. }
  11442. }
  11443. return res;
  11444. }
  11445. /**
  11446. * Return a function for matching based on the
  11447. * given `pattern` and `options`.
  11448. *
  11449. * @param {String} `pattern`
  11450. * @param {Object} `options`
  11451. * @return {Function}
  11452. */
  11453. function matcher(pattern, opts) {
  11454. // pattern is a function
  11455. if (typeof pattern === 'function') {
  11456. return pattern;
  11457. }
  11458. // pattern is a regex
  11459. if (pattern instanceof RegExp) {
  11460. return function(fp) {
  11461. return pattern.test(fp);
  11462. };
  11463. }
  11464. if (typeof pattern !== 'string') {
  11465. throw new TypeError(msg('matcher', 'pattern', 'a string, regex, or function'));
  11466. }
  11467. // strings, all the way down...
  11468. pattern = utils_1.unixify(pattern, opts);
  11469. // pattern is a non-glob string
  11470. if (!utils_1.isGlob(pattern)) {
  11471. return utils_1.matchPath(pattern, opts);
  11472. }
  11473. // pattern is a glob string
  11474. var re = makeRe(pattern, opts);
  11475. // `matchBase` is defined
  11476. if (opts && opts.matchBase) {
  11477. return utils_1.hasFilename(re, opts);
  11478. }
  11479. // `matchBase` is not defined
  11480. return function(fp) {
  11481. fp = utils_1.unixify(fp, opts);
  11482. return re.test(fp);
  11483. };
  11484. }
  11485. /**
  11486. * Create and cache a regular expression for matching
  11487. * file paths.
  11488. *
  11489. * If the leading character in the `glob` is `!`, a negation
  11490. * regex is returned.
  11491. *
  11492. * @param {String} `glob`
  11493. * @param {Object} `options`
  11494. * @return {RegExp}
  11495. */
  11496. function toRegex(glob, options) {
  11497. // clone options to prevent mutating the original object
  11498. var opts = Object.create(options || {});
  11499. var flags = opts.flags || '';
  11500. if (opts.nocase && flags.indexOf('i') === -1) {
  11501. flags += 'i';
  11502. }
  11503. var parsed = expand_1(glob, opts);
  11504. // pass in tokens to avoid parsing more than once
  11505. opts.negated = opts.negated || parsed.negated;
  11506. opts.negate = opts.negated;
  11507. glob = wrapGlob(parsed.pattern, opts);
  11508. var re;
  11509. try {
  11510. re = new RegExp(glob, flags);
  11511. return re;
  11512. } catch (err) {
  11513. err.reason = 'micromatch invalid regex: (' + re + ')';
  11514. if (opts.strict) throw new SyntaxError(err);
  11515. }
  11516. // we're only here if a bad pattern was used and the user
  11517. // passed `options.silent`, so match nothing
  11518. return /$^/;
  11519. }
  11520. /**
  11521. * Create the regex to do the matching. If the leading
  11522. * character in the `glob` is `!` a negation regex is returned.
  11523. *
  11524. * @param {String} `glob`
  11525. * @param {Boolean} `negate`
  11526. */
  11527. function wrapGlob(glob, opts) {
  11528. var prefix = (opts && !opts.contains) ? '^' : '';
  11529. var after = (opts && !opts.contains) ? '$' : '';
  11530. glob = ('(?:' + glob + ')' + after);
  11531. if (opts && opts.negate) {
  11532. return prefix + ('(?!^' + glob + ').*$');
  11533. }
  11534. return prefix + glob;
  11535. }
  11536. /**
  11537. * Create and cache a regular expression for matching file paths.
  11538. * If the leading character in the `glob` is `!`, a negation
  11539. * regex is returned.
  11540. *
  11541. * @param {String} `glob`
  11542. * @param {Object} `options`
  11543. * @return {RegExp}
  11544. */
  11545. function makeRe(glob, opts) {
  11546. if (utils_1.typeOf(glob) !== 'string') {
  11547. throw new Error(msg('makeRe', 'glob', 'a string'));
  11548. }
  11549. return utils_1.cache(toRegex, glob, opts);
  11550. }
  11551. /**
  11552. * Make error messages consistent. Follows this format:
  11553. *
  11554. * ```js
  11555. * msg(methodName, argNumber, nativeType);
  11556. * // example:
  11557. * msg('matchKeys', 'first', 'an object');
  11558. * ```
  11559. *
  11560. * @param {String} `method`
  11561. * @param {String} `num`
  11562. * @param {String} `type`
  11563. * @return {String}
  11564. */
  11565. function msg(method, what, type) {
  11566. return 'micromatch.' + method + '(): ' + what + ' should be ' + type + '.';
  11567. }
  11568. /**
  11569. * Public methods
  11570. */
  11571. /* eslint no-multi-spaces: 0 */
  11572. micromatch.any = any;
  11573. micromatch.braces = micromatch.braceExpand = utils_1.braces;
  11574. micromatch.contains = contains;
  11575. micromatch.expand = expand_1;
  11576. micromatch.filter = filter;
  11577. micromatch.isMatch = isMatch;
  11578. micromatch.makeRe = makeRe;
  11579. micromatch.match = match;
  11580. micromatch.matcher = matcher;
  11581. micromatch.matchKeys = matchKeys;
  11582. /**
  11583. * Expose `micromatch`
  11584. */
  11585. var micromatch_1 = micromatch;
  11586. function ensureArray$1 ( thing ) {
  11587. if ( Array.isArray( thing ) ) return thing;
  11588. if ( thing == undefined ) return [];
  11589. return [ thing ];
  11590. }
  11591. function createFilter ( include, exclude ) {
  11592. const getMatcher = id => ( isRegexp( id ) ? id : { test: micromatch_1.matcher( resolve( id ) ) } );
  11593. include = ensureArray$1( include ).map( getMatcher );
  11594. exclude = ensureArray$1( exclude ).map( getMatcher );
  11595. return function ( id ) {
  11596. if ( typeof id !== 'string' ) return false;
  11597. if ( /\0/.test( id ) ) return false;
  11598. id = id.split( sep ).join( '/' );
  11599. for ( let i = 0; i < exclude.length; ++i ) {
  11600. const matcher = exclude[i];
  11601. if ( matcher.test( id ) ) return false;
  11602. }
  11603. for ( let i = 0; i < include.length; ++i ) {
  11604. const matcher = include[i];
  11605. if ( matcher.test( id ) ) return true;
  11606. }
  11607. return !include.length;
  11608. };
  11609. }
  11610. function isRegexp ( val ) {
  11611. return val instanceof RegExp;
  11612. }
  11613. var modules = {};
  11614. var getModule = function(dir) {
  11615. var rootPath = dir ? path.resolve(dir) : process.cwd();
  11616. var rootName = path.join(rootPath, '@root');
  11617. var root = modules[rootName];
  11618. if (!root) {
  11619. root = new module$1(rootName);
  11620. root.filename = rootName;
  11621. root.paths = module$1._nodeModulePaths(rootPath);
  11622. modules[rootName] = root;
  11623. }
  11624. return root;
  11625. };
  11626. var requireRelative = function(requested, relativeTo) {
  11627. var root = getModule(relativeTo);
  11628. return root.require(requested);
  11629. };
  11630. requireRelative.resolve = function(requested, relativeTo) {
  11631. var root = getModule(relativeTo);
  11632. return module$1._resolveFilename(requested, root);
  11633. };
  11634. var requireRelative_1$1 = requireRelative;
  11635. let chokidar;
  11636. try {
  11637. chokidar = requireRelative_1$1( 'chokidar', process.cwd() );
  11638. } catch (err) {
  11639. chokidar = null;
  11640. }
  11641. var chokidar$1 = chokidar;
  11642. const opts = { encoding: 'utf-8', persistent: true };
  11643. const watchers = new Map();
  11644. function addTask(id, task, chokidarOptions, chokidarOptionsHash) {
  11645. if (!watchers.has(chokidarOptionsHash)) { watchers.set(chokidarOptionsHash, new Map()); }
  11646. const group = watchers.get(chokidarOptionsHash);
  11647. if (!group.has(id)) {
  11648. const watcher = new FileWatcher(id, chokidarOptions, () => {
  11649. group.delete(id);
  11650. });
  11651. if (watcher.fileExists) {
  11652. group.set(id, watcher);
  11653. } else {
  11654. return;
  11655. }
  11656. }
  11657. group.get(id).tasks.add(task);
  11658. }
  11659. function deleteTask(id, target, chokidarOptionsHash) {
  11660. const group = watchers.get(chokidarOptionsHash);
  11661. const watcher = group.get(id);
  11662. if (watcher) {
  11663. watcher.tasks.delete(target);
  11664. if (watcher.tasks.size === 0) {
  11665. watcher.close();
  11666. group.delete(id);
  11667. }
  11668. }
  11669. }
  11670. class FileWatcher {
  11671. constructor(id, chokidarOptions, dispose) {
  11672. this.tasks = new Set();
  11673. let data;
  11674. try {
  11675. statSync(id);
  11676. this.fileExists = true;
  11677. } catch (err) {
  11678. if (err.code === 'ENOENT') {
  11679. // can't watch files that don't exist (e.g. injected
  11680. // by plugins somehow)
  11681. this.fileExists = false;
  11682. return;
  11683. } else {
  11684. throw err;
  11685. }
  11686. }
  11687. const handleWatchEvent = event => {
  11688. if (event === 'rename' || event === 'unlink') {
  11689. this.fsWatcher.close();
  11690. this.trigger();
  11691. dispose();
  11692. } else {
  11693. // this is necessary because we get duplicate events...
  11694. const contents = readFileSync(id, 'utf-8');
  11695. if (contents !== data) {
  11696. data = contents;
  11697. this.trigger();
  11698. }
  11699. }
  11700. };
  11701. if (chokidarOptions) {
  11702. this.fsWatcher = chokidar$1
  11703. .watch(id, chokidarOptions)
  11704. .on('all', handleWatchEvent);
  11705. } else {
  11706. this.fsWatcher = watch(id, opts, handleWatchEvent);
  11707. }
  11708. }
  11709. close() {
  11710. this.fsWatcher.close();
  11711. }
  11712. trigger() {
  11713. this.tasks.forEach(task => {
  11714. task.makeDirty();
  11715. });
  11716. }
  11717. }
  11718. const DELAY = 100;
  11719. class Watcher extends EventEmitter {
  11720. constructor(configs) {
  11721. super();
  11722. this.dirty = true;
  11723. this.running = false;
  11724. this.tasks = ensureArray(configs).map(config => new Task(this, config));
  11725. this.succeeded = false;
  11726. process.nextTick(() => {
  11727. this._run();
  11728. });
  11729. }
  11730. close() {
  11731. this.tasks.forEach(task => {
  11732. task.close();
  11733. });
  11734. this.removeAllListeners();
  11735. }
  11736. _makeDirty() {
  11737. if (this.dirty) { return; }
  11738. this.dirty = true;
  11739. if (!this.running) {
  11740. setTimeout(() => {
  11741. this._run();
  11742. }, DELAY);
  11743. }
  11744. }
  11745. _run() {
  11746. this.running = true;
  11747. this.dirty = false;
  11748. this.emit('event', {
  11749. code: 'START'
  11750. });
  11751. mapSequence(this.tasks, task => task.run())
  11752. .then(() => {
  11753. this.succeeded = true;
  11754. this.emit('event', {
  11755. code: 'END'
  11756. });
  11757. })
  11758. .catch(error => {
  11759. this.emit('event', {
  11760. code: this.succeeded ? 'ERROR' : 'FATAL',
  11761. error
  11762. });
  11763. })
  11764. .then(() => {
  11765. this.running = false;
  11766. if (this.dirty) {
  11767. this._run();
  11768. }
  11769. });
  11770. }
  11771. }
  11772. class Task {
  11773. constructor(watcher, config) {
  11774. this.cache = null;
  11775. this.watcher = watcher;
  11776. this.dirty = true;
  11777. this.closed = false;
  11778. this.watched = new Set();
  11779. this.inputOptions = {
  11780. input: config.input,
  11781. entry: config.input, // legacy, for e.g. commonjs plugin
  11782. legacy: config.legacy,
  11783. treeshake: config.treeshake,
  11784. plugins: config.plugins,
  11785. external: config.external,
  11786. onwarn: config.onwarn || (warning => console.warn(warning.message)), // eslint-disable-line no-console
  11787. acorn: config.acorn,
  11788. context: config.context,
  11789. moduleContext: config.moduleContext
  11790. };
  11791. const baseOutputOptions = {
  11792. extend: config.extend,
  11793. exports: config.exports,
  11794. amd: config.amd,
  11795. banner: config.banner,
  11796. footer: config.footer,
  11797. intro: config.intro,
  11798. outro: config.outro,
  11799. sourcemap: config.sourcemap,
  11800. sourcemapFile: config.sourcemapFile,
  11801. name: config.name,
  11802. globals: config.globals,
  11803. interop: config.interop,
  11804. legacy: config.legacy,
  11805. indent: config.indent,
  11806. strict: config.strict,
  11807. noConflict: config.noConflict,
  11808. paths: config.paths,
  11809. preferConst: config.preferConst
  11810. };
  11811. this.outputs = ensureArray(config.output).map(output => {
  11812. return Object.assign({}, baseOutputOptions, output);
  11813. });
  11814. this.outputFiles = this.outputs.map(output => path.resolve(output.file));
  11815. const watchOptions = config.watch || {};
  11816. if ('useChokidar' in watchOptions) { watchOptions.chokidar = watchOptions.useChokidar; }
  11817. let chokidarOptions = 'chokidar' in watchOptions ? watchOptions.chokidar : !!chokidar$1;
  11818. if (chokidarOptions) {
  11819. chokidarOptions = Object.assign(
  11820. chokidarOptions === true ? {} : chokidarOptions,
  11821. {
  11822. ignoreInitial: true
  11823. }
  11824. );
  11825. }
  11826. if (chokidarOptions && !chokidar$1) {
  11827. throw new Error(`options.watch.chokidar was provided, but chokidar could not be found. Have you installed it?`);
  11828. }
  11829. this.chokidarOptions = chokidarOptions;
  11830. this.chokidarOptionsHash = JSON.stringify(chokidarOptions);
  11831. this.filter = createFilter(watchOptions.include, watchOptions.exclude);
  11832. this.deprecations = watchOptions._deprecations;
  11833. }
  11834. close() {
  11835. this.closed = true;
  11836. this.watched.forEach(id => {
  11837. deleteTask(id, this, this.chokidarOptionsHash);
  11838. });
  11839. }
  11840. makeDirty() {
  11841. if (!this.dirty) {
  11842. this.dirty = true;
  11843. this.watcher._makeDirty();
  11844. }
  11845. }
  11846. run() {
  11847. if (!this.dirty) { return; }
  11848. this.dirty = false;
  11849. const options = Object.assign(this.inputOptions, {
  11850. cache: this.cache
  11851. });
  11852. const start = Date.now();
  11853. this.watcher.emit('event', {
  11854. code: 'BUNDLE_START',
  11855. input: this.inputOptions.input,
  11856. output: this.outputFiles
  11857. });
  11858. if (this.deprecations) {
  11859. this.inputOptions.onwarn({
  11860. code: 'DEPRECATED_OPTIONS',
  11861. deprecations: this.deprecations
  11862. });
  11863. }
  11864. return rollup(options)
  11865. .then(bundle => {
  11866. if (this.closed) { return; }
  11867. this.cache = bundle;
  11868. const watched = new Set();
  11869. bundle.modules.forEach(module => {
  11870. watched.add(module.id);
  11871. this.watchFile(module.id);
  11872. });
  11873. this.watched.forEach(id => {
  11874. if (!watched.has(id)) { deleteTask(id, this, this.chokidarOptionsHash); }
  11875. });
  11876. this.watched = watched;
  11877. return Promise.all(
  11878. this.outputs.map(output => bundle.write(output))
  11879. );
  11880. })
  11881. .then(() => {
  11882. this.watcher.emit('event', {
  11883. code: 'BUNDLE_END',
  11884. input: this.inputOptions.input,
  11885. output: this.outputFiles,
  11886. duration: Date.now() - start
  11887. });
  11888. })
  11889. .catch(error => {
  11890. if (this.closed) { return; }
  11891. if (this.cache) {
  11892. this.cache.modules.forEach(module => {
  11893. // this is necessary to ensure that any 'renamed' files
  11894. // continue to be watched following an error
  11895. this.watchFile(module.id);
  11896. });
  11897. }
  11898. throw error;
  11899. });
  11900. }
  11901. watchFile(id) {
  11902. if (!this.filter(id)) { return; }
  11903. if (this.outputFiles.some(file => file === id)) {
  11904. throw new Error('Cannot import the generated bundle');
  11905. }
  11906. // this is necessary to ensure that any 'renamed' files
  11907. // continue to be watched following an error
  11908. addTask(id, this, this.chokidarOptions, this.chokidarOptionsHash);
  11909. }
  11910. }
  11911. function watch$1(configs) {
  11912. return new Watcher(configs);
  11913. }
  11914. var version$1 = "0.50.0";
  11915. export { rollup, watch$1 as watch, version$1 as VERSION };
  11916. //# sourceMappingURL=rollup.es.js.map