amd2common.bundle.js 400 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/ // The require function
  5. /******/ function __webpack_require__(moduleId) {
  6. /******/ // Check if module is in cache
  7. /******/ if(installedModules[moduleId])
  8. /******/ return installedModules[moduleId].exports;
  9. /******/ // Create a new module (and put it into the cache)
  10. /******/ var module = installedModules[moduleId] = {
  11. /******/ exports: {},
  12. /******/ id: moduleId,
  13. /******/ loaded: false
  14. /******/ };
  15. /******/ // Execute the module function
  16. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  17. /******/ // Flag the module as loaded
  18. /******/ module.loaded = true;
  19. /******/ // Return the exports of the module
  20. /******/ return module.exports;
  21. /******/ }
  22. /******/ // expose the modules object (__webpack_modules__)
  23. /******/ __webpack_require__.m = modules;
  24. /******/ // expose the module cache
  25. /******/ __webpack_require__.c = installedModules;
  26. /******/ // __webpack_public_path__
  27. /******/ __webpack_require__.p = "";
  28. /******/ // Load entry module and return exports
  29. /******/ return __webpack_require__(0);
  30. /******/ })
  31. /************************************************************************/
  32. /******/ ([
  33. /* 0 */
  34. /***/ function(module, exports, __webpack_require__) {
  35. var glob = __webpack_require__(1);
  36. var fsExtra = __webpack_require__(18);
  37. var esprima = __webpack_require__(63);
  38. glob('**/*.js', {
  39. cwd: __dirname + '/../src/'
  40. }, function (err, files) {
  41. files.forEach(function (filePath) {
  42. var code = parse(fsExtra.readFileSync(
  43. __dirname + '/../src/' + filePath, 'utf-8'));
  44. code = code.replace(/require\(([\'"])zrender\//g, 'require($1zrender/lib/');
  45. fsExtra.outputFileSync(
  46. __dirname + '/../lib/' + filePath,
  47. code, 'utf-8');
  48. });
  49. });
  50. var MAGIC_DEPS = {
  51. 'exports' : true,
  52. 'module' : true,
  53. 'require' : true
  54. };
  55. var SIMPLIFIED_CJS = ['require', 'exports', 'module'];
  56. // Convert AMD-style JavaScript string into node.js compatible module
  57. function parse (raw){
  58. var output = '';
  59. var ast = esprima.parse(raw, {
  60. range: true,
  61. raw: true
  62. });
  63. var defines = ast.body.filter(isDefine);
  64. if ( defines.length > 1 ){
  65. throw new Error('Each file can have only a single define call. Found "'+ defines.length +'"');
  66. } else if (!defines.length){
  67. return raw;
  68. }
  69. var def = defines[0];
  70. var args = def.expression['arguments'];
  71. var factory = getFactory( args );
  72. var useStrict = getUseStrict( factory );
  73. // do replacements in-place to avoid modifying the code more than needed
  74. if (useStrict) {
  75. output += useStrict.expression.raw +';\n';
  76. }
  77. output += raw.substring( 0, def.range[0] ); // anything before define
  78. output += getRequires(args, factory); // add requires
  79. output += getBody(raw, factory.body, useStrict); // module body
  80. output += raw.substring( def.range[1], raw.length ); // anything after define
  81. return output;
  82. }
  83. function getRequires(args, factory){
  84. var requires = [];
  85. var deps = getDependenciesNames( args );
  86. var params = factory.params.map(function(param, i){
  87. return {
  88. name : param.name,
  89. // simplified cjs doesn't have deps
  90. dep : (deps.length)? deps[i] : SIMPLIFIED_CJS[i]
  91. };
  92. });
  93. params.forEach(function(param){
  94. if ( MAGIC_DEPS[param.dep] && !MAGIC_DEPS[param.name] ) {
  95. // if user remaped magic dependency we declare a var
  96. requires.push( 'var '+ param.name +' = '+ param.dep +';' );
  97. } else if ( param.dep && !MAGIC_DEPS[param.dep] ) {
  98. // only do require for params that have a matching dependency also
  99. // skip "magic" dependencies
  100. requires.push( 'var '+ param.name +' = require(\''+ param.dep +'\');' );
  101. }
  102. });
  103. return requires.join('\n');
  104. }
  105. function getDependenciesNames(args){
  106. var deps = [];
  107. var arr = args.filter(function(arg){
  108. return arg.type === 'ArrayExpression';
  109. })[0];
  110. if (arr) {
  111. deps = arr.elements.map(function(el){
  112. return el.value;
  113. });
  114. }
  115. return deps;
  116. }
  117. function isDefine(node){
  118. return node.type === 'ExpressionStatement' &&
  119. node.expression.type === 'CallExpression' &&
  120. node.expression.callee.type === 'Identifier' &&
  121. node.expression.callee.name === 'define';
  122. }
  123. function getFactory(args){
  124. return args.filter(function(arg){
  125. return arg.type === 'FunctionExpression';
  126. })[0];
  127. }
  128. function getBody(raw, factoryBody, useStrict){
  129. var returnStatement = factoryBody.body.filter(function(node){
  130. return node.type === 'ReturnStatement';
  131. })[0];
  132. var body = '';
  133. var bodyStart = useStrict? useStrict.expression.range[1] + 1 : factoryBody.range[0] + 1;
  134. if (returnStatement) {
  135. body += raw.substring( bodyStart, returnStatement.range[0] );
  136. // "return ".length === 7 so we add "6" to returnStatement start
  137. body += 'module.exports ='+ raw.substring( returnStatement.range[0] + 6, factoryBody.range[1] - 1 );
  138. } else {
  139. // if using exports or module.exports or just a private module we
  140. // simply return the factoryBody content
  141. body = raw.substring( bodyStart, factoryBody.range[1] - 1 );
  142. }
  143. return body;
  144. }
  145. function getUseStrict(factory){
  146. return factory.body.body.filter(isUseStrict)[0];
  147. }
  148. function isUseStrict(node){
  149. return node.type === 'ExpressionStatement' &&
  150. node.expression.type === 'Literal' &&
  151. node.expression.value === 'use strict';
  152. }
  153. /***/ },
  154. /* 1 */
  155. /***/ function(module, exports, __webpack_require__) {
  156. // Approach:
  157. //
  158. // 1. Get the minimatch set
  159. // 2. For each pattern in the set, PROCESS(pattern, false)
  160. // 3. Store matches per-set, then uniq them
  161. //
  162. // PROCESS(pattern, inGlobStar)
  163. // Get the first [n] items from pattern that are all strings
  164. // Join these together. This is PREFIX.
  165. // If there is no more remaining, then stat(PREFIX) and
  166. // add to matches if it succeeds. END.
  167. //
  168. // If inGlobStar and PREFIX is symlink and points to dir
  169. // set ENTRIES = []
  170. // else readdir(PREFIX) as ENTRIES
  171. // If fail, END
  172. //
  173. // with ENTRIES
  174. // If pattern[n] is GLOBSTAR
  175. // // handle the case where the globstar match is empty
  176. // // by pruning it out, and testing the resulting pattern
  177. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  178. // // handle other cases.
  179. // for ENTRY in ENTRIES (not dotfiles)
  180. // // attach globstar + tail onto the entry
  181. // // Mark that this entry is a globstar match
  182. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  183. //
  184. // else // not globstar
  185. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  186. // Test ENTRY against pattern[n]
  187. // If fails, continue
  188. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  189. //
  190. // Caveat:
  191. // Cache all stats and readdirs results to minimize syscall. Since all
  192. // we ever care about is existence and directory-ness, we can just keep
  193. // `true` for files, and [children,...] for directories, or `false` for
  194. // things that don't exist.
  195. module.exports = glob
  196. var fs = __webpack_require__(2)
  197. var minimatch = __webpack_require__(3)
  198. var Minimatch = minimatch.Minimatch
  199. var inherits = __webpack_require__(8)
  200. var EE = __webpack_require__(10).EventEmitter
  201. var path = __webpack_require__(4)
  202. var assert = __webpack_require__(11)
  203. var isAbsolute = __webpack_require__(12)
  204. var globSync = __webpack_require__(13)
  205. var common = __webpack_require__(14)
  206. var alphasort = common.alphasort
  207. var alphasorti = common.alphasorti
  208. var setopts = common.setopts
  209. var ownProp = common.ownProp
  210. var inflight = __webpack_require__(15)
  211. var util = __webpack_require__(9)
  212. var childrenIgnored = common.childrenIgnored
  213. var isIgnored = common.isIgnored
  214. var once = __webpack_require__(17)
  215. function glob (pattern, options, cb) {
  216. if (typeof options === 'function') cb = options, options = {}
  217. if (!options) options = {}
  218. if (options.sync) {
  219. if (cb)
  220. throw new TypeError('callback provided to sync glob')
  221. return globSync(pattern, options)
  222. }
  223. return new Glob(pattern, options, cb)
  224. }
  225. glob.sync = globSync
  226. var GlobSync = glob.GlobSync = globSync.GlobSync
  227. // old api surface
  228. glob.glob = glob
  229. function extend (origin, add) {
  230. if (add === null || typeof add !== 'object') {
  231. return origin
  232. }
  233. var keys = Object.keys(add)
  234. var i = keys.length
  235. while (i--) {
  236. origin[keys[i]] = add[keys[i]]
  237. }
  238. return origin
  239. }
  240. glob.hasMagic = function (pattern, options_) {
  241. var options = extend({}, options_)
  242. options.noprocess = true
  243. var g = new Glob(pattern, options)
  244. var set = g.minimatch.set
  245. if (set.length > 1)
  246. return true
  247. for (var j = 0; j < set[0].length; j++) {
  248. if (typeof set[0][j] !== 'string')
  249. return true
  250. }
  251. return false
  252. }
  253. glob.Glob = Glob
  254. inherits(Glob, EE)
  255. function Glob (pattern, options, cb) {
  256. if (typeof options === 'function') {
  257. cb = options
  258. options = null
  259. }
  260. if (options && options.sync) {
  261. if (cb)
  262. throw new TypeError('callback provided to sync glob')
  263. return new GlobSync(pattern, options)
  264. }
  265. if (!(this instanceof Glob))
  266. return new Glob(pattern, options, cb)
  267. setopts(this, pattern, options)
  268. this._didRealPath = false
  269. // process each pattern in the minimatch set
  270. var n = this.minimatch.set.length
  271. // The matches are stored as {<filename>: true,...} so that
  272. // duplicates are automagically pruned.
  273. // Later, we do an Object.keys() on these.
  274. // Keep them as a list so we can fill in when nonull is set.
  275. this.matches = new Array(n)
  276. if (typeof cb === 'function') {
  277. cb = once(cb)
  278. this.on('error', cb)
  279. this.on('end', function (matches) {
  280. cb(null, matches)
  281. })
  282. }
  283. var self = this
  284. var n = this.minimatch.set.length
  285. this._processing = 0
  286. this.matches = new Array(n)
  287. this._emitQueue = []
  288. this._processQueue = []
  289. this.paused = false
  290. if (this.noprocess)
  291. return this
  292. if (n === 0)
  293. return done()
  294. for (var i = 0; i < n; i ++) {
  295. this._process(this.minimatch.set[i], i, false, done)
  296. }
  297. function done () {
  298. --self._processing
  299. if (self._processing <= 0)
  300. self._finish()
  301. }
  302. }
  303. Glob.prototype._finish = function () {
  304. assert(this instanceof Glob)
  305. if (this.aborted)
  306. return
  307. if (this.realpath && !this._didRealpath)
  308. return this._realpath()
  309. common.finish(this)
  310. this.emit('end', this.found)
  311. }
  312. Glob.prototype._realpath = function () {
  313. if (this._didRealpath)
  314. return
  315. this._didRealpath = true
  316. var n = this.matches.length
  317. if (n === 0)
  318. return this._finish()
  319. var self = this
  320. for (var i = 0; i < this.matches.length; i++)
  321. this._realpathSet(i, next)
  322. function next () {
  323. if (--n === 0)
  324. self._finish()
  325. }
  326. }
  327. Glob.prototype._realpathSet = function (index, cb) {
  328. var matchset = this.matches[index]
  329. if (!matchset)
  330. return cb()
  331. var found = Object.keys(matchset)
  332. var self = this
  333. var n = found.length
  334. if (n === 0)
  335. return cb()
  336. var set = this.matches[index] = Object.create(null)
  337. found.forEach(function (p, i) {
  338. // If there's a problem with the stat, then it means that
  339. // one or more of the links in the realpath couldn't be
  340. // resolved. just return the abs value in that case.
  341. p = self._makeAbs(p)
  342. fs.realpath(p, self.realpathCache, function (er, real) {
  343. if (!er)
  344. set[real] = true
  345. else if (er.syscall === 'stat')
  346. set[p] = true
  347. else
  348. self.emit('error', er) // srsly wtf right here
  349. if (--n === 0) {
  350. self.matches[index] = set
  351. cb()
  352. }
  353. })
  354. })
  355. }
  356. Glob.prototype._mark = function (p) {
  357. return common.mark(this, p)
  358. }
  359. Glob.prototype._makeAbs = function (f) {
  360. return common.makeAbs(this, f)
  361. }
  362. Glob.prototype.abort = function () {
  363. this.aborted = true
  364. this.emit('abort')
  365. }
  366. Glob.prototype.pause = function () {
  367. if (!this.paused) {
  368. this.paused = true
  369. this.emit('pause')
  370. }
  371. }
  372. Glob.prototype.resume = function () {
  373. if (this.paused) {
  374. this.emit('resume')
  375. this.paused = false
  376. if (this._emitQueue.length) {
  377. var eq = this._emitQueue.slice(0)
  378. this._emitQueue.length = 0
  379. for (var i = 0; i < eq.length; i ++) {
  380. var e = eq[i]
  381. this._emitMatch(e[0], e[1])
  382. }
  383. }
  384. if (this._processQueue.length) {
  385. var pq = this._processQueue.slice(0)
  386. this._processQueue.length = 0
  387. for (var i = 0; i < pq.length; i ++) {
  388. var p = pq[i]
  389. this._processing--
  390. this._process(p[0], p[1], p[2], p[3])
  391. }
  392. }
  393. }
  394. }
  395. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  396. assert(this instanceof Glob)
  397. assert(typeof cb === 'function')
  398. if (this.aborted)
  399. return
  400. this._processing++
  401. if (this.paused) {
  402. this._processQueue.push([pattern, index, inGlobStar, cb])
  403. return
  404. }
  405. //console.error('PROCESS %d', this._processing, pattern)
  406. // Get the first [n] parts of pattern that are all strings.
  407. var n = 0
  408. while (typeof pattern[n] === 'string') {
  409. n ++
  410. }
  411. // now n is the index of the first one that is *not* a string.
  412. // see if there's anything else
  413. var prefix
  414. switch (n) {
  415. // if not, then this is rather simple
  416. case pattern.length:
  417. this._processSimple(pattern.join('/'), index, cb)
  418. return
  419. case 0:
  420. // pattern *starts* with some non-trivial item.
  421. // going to readdir(cwd), but not include the prefix in matches.
  422. prefix = null
  423. break
  424. default:
  425. // pattern has some string bits in the front.
  426. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  427. // or 'relative' like '../baz'
  428. prefix = pattern.slice(0, n).join('/')
  429. break
  430. }
  431. var remain = pattern.slice(n)
  432. // get the list of entries.
  433. var read
  434. if (prefix === null)
  435. read = '.'
  436. else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
  437. if (!prefix || !isAbsolute(prefix))
  438. prefix = '/' + prefix
  439. read = prefix
  440. } else
  441. read = prefix
  442. var abs = this._makeAbs(read)
  443. //if ignored, skip _processing
  444. if (childrenIgnored(this, read))
  445. return cb()
  446. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  447. if (isGlobStar)
  448. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb)
  449. else
  450. this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb)
  451. }
  452. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  453. var self = this
  454. this._readdir(abs, inGlobStar, function (er, entries) {
  455. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  456. })
  457. }
  458. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  459. // if the abs isn't a dir, then nothing can match!
  460. if (!entries)
  461. return cb()
  462. // It will only match dot entries if it starts with a dot, or if
  463. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  464. var pn = remain[0]
  465. var negate = !!this.minimatch.negate
  466. var rawGlob = pn._glob
  467. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  468. var matchedEntries = []
  469. for (var i = 0; i < entries.length; i++) {
  470. var e = entries[i]
  471. if (e.charAt(0) !== '.' || dotOk) {
  472. var m
  473. if (negate && !prefix) {
  474. m = !e.match(pn)
  475. } else {
  476. m = e.match(pn)
  477. }
  478. if (m)
  479. matchedEntries.push(e)
  480. }
  481. }
  482. //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  483. var len = matchedEntries.length
  484. // If there are no matched entries, then nothing matches.
  485. if (len === 0)
  486. return cb()
  487. // if this is the last remaining pattern bit, then no need for
  488. // an additional stat *unless* the user has specified mark or
  489. // stat explicitly. We know they exist, since readdir returned
  490. // them.
  491. if (remain.length === 1 && !this.mark && !this.stat) {
  492. if (!this.matches[index])
  493. this.matches[index] = Object.create(null)
  494. for (var i = 0; i < len; i ++) {
  495. var e = matchedEntries[i]
  496. if (prefix) {
  497. if (prefix !== '/')
  498. e = prefix + '/' + e
  499. else
  500. e = prefix + e
  501. }
  502. if (e.charAt(0) === '/' && !this.nomount) {
  503. e = path.join(this.root, e)
  504. }
  505. this._emitMatch(index, e)
  506. }
  507. // This was the last one, and no stats were needed
  508. return cb()
  509. }
  510. // now test all matched entries as stand-ins for that part
  511. // of the pattern.
  512. remain.shift()
  513. for (var i = 0; i < len; i ++) {
  514. var e = matchedEntries[i]
  515. var newPattern
  516. if (prefix) {
  517. if (prefix !== '/')
  518. e = prefix + '/' + e
  519. else
  520. e = prefix + e
  521. }
  522. this._process([e].concat(remain), index, inGlobStar, cb)
  523. }
  524. cb()
  525. }
  526. Glob.prototype._emitMatch = function (index, e) {
  527. if (this.aborted)
  528. return
  529. if (this.matches[index][e])
  530. return
  531. if (isIgnored(this, e))
  532. return
  533. if (this.paused) {
  534. this._emitQueue.push([index, e])
  535. return
  536. }
  537. var abs = this._makeAbs(e)
  538. if (this.nodir) {
  539. var c = this.cache[abs]
  540. if (c === 'DIR' || Array.isArray(c))
  541. return
  542. }
  543. if (this.mark)
  544. e = this._mark(e)
  545. this.matches[index][e] = true
  546. var st = this.statCache[abs]
  547. if (st)
  548. this.emit('stat', e, st)
  549. this.emit('match', e)
  550. }
  551. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  552. if (this.aborted)
  553. return
  554. // follow all symlinked directories forever
  555. // just proceed as if this is a non-globstar situation
  556. if (this.follow)
  557. return this._readdir(abs, false, cb)
  558. var lstatkey = 'lstat\0' + abs
  559. var self = this
  560. var lstatcb = inflight(lstatkey, lstatcb_)
  561. if (lstatcb)
  562. fs.lstat(abs, lstatcb)
  563. function lstatcb_ (er, lstat) {
  564. if (er)
  565. return cb()
  566. var isSym = lstat.isSymbolicLink()
  567. self.symlinks[abs] = isSym
  568. // If it's not a symlink or a dir, then it's definitely a regular file.
  569. // don't bother doing a readdir in that case.
  570. if (!isSym && !lstat.isDirectory()) {
  571. self.cache[abs] = 'FILE'
  572. cb()
  573. } else
  574. self._readdir(abs, false, cb)
  575. }
  576. }
  577. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  578. if (this.aborted)
  579. return
  580. cb = inflight('readdir\0'+abs+'\0'+inGlobStar, cb)
  581. if (!cb)
  582. return
  583. //console.error('RD %j %j', +inGlobStar, abs)
  584. if (inGlobStar && !ownProp(this.symlinks, abs))
  585. return this._readdirInGlobStar(abs, cb)
  586. if (ownProp(this.cache, abs)) {
  587. var c = this.cache[abs]
  588. if (!c || c === 'FILE')
  589. return cb()
  590. if (Array.isArray(c))
  591. return cb(null, c)
  592. }
  593. var self = this
  594. fs.readdir(abs, readdirCb(this, abs, cb))
  595. }
  596. function readdirCb (self, abs, cb) {
  597. return function (er, entries) {
  598. if (er)
  599. self._readdirError(abs, er, cb)
  600. else
  601. self._readdirEntries(abs, entries, cb)
  602. }
  603. }
  604. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  605. if (this.aborted)
  606. return
  607. // if we haven't asked to stat everything, then just
  608. // assume that everything in there exists, so we can avoid
  609. // having to stat it a second time.
  610. if (!this.mark && !this.stat) {
  611. for (var i = 0; i < entries.length; i ++) {
  612. var e = entries[i]
  613. if (abs === '/')
  614. e = abs + e
  615. else
  616. e = abs + '/' + e
  617. this.cache[e] = true
  618. }
  619. }
  620. this.cache[abs] = entries
  621. return cb(null, entries)
  622. }
  623. Glob.prototype._readdirError = function (f, er, cb) {
  624. if (this.aborted)
  625. return
  626. // handle errors, and cache the information
  627. switch (er.code) {
  628. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  629. case 'ENOTDIR': // totally normal. means it *does* exist.
  630. this.cache[this._makeAbs(f)] = 'FILE'
  631. if (f === this.cwd) {
  632. var error = new Error(er.code + ' invalid cwd ' + f)
  633. error.path = f
  634. error.code = er.code
  635. this.emit('error', error)
  636. this.abort()
  637. }
  638. break
  639. case 'ENOENT': // not terribly unusual
  640. case 'ELOOP':
  641. case 'ENAMETOOLONG':
  642. case 'UNKNOWN':
  643. this.cache[this._makeAbs(f)] = false
  644. break
  645. default: // some unusual error. Treat as failure.
  646. this.cache[this._makeAbs(f)] = false
  647. if (this.strict) {
  648. this.emit('error', er)
  649. // If the error is handled, then we abort
  650. // if not, we threw out of here
  651. this.abort()
  652. }
  653. if (!this.silent)
  654. console.error('glob error', er)
  655. break
  656. }
  657. return cb()
  658. }
  659. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  660. var self = this
  661. this._readdir(abs, inGlobStar, function (er, entries) {
  662. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  663. })
  664. }
  665. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  666. //console.error('pgs2', prefix, remain[0], entries)
  667. // no entries means not a dir, so it can never have matches
  668. // foo.txt/** doesn't match foo.txt
  669. if (!entries)
  670. return cb()
  671. // test without the globstar, and with every child both below
  672. // and replacing the globstar.
  673. var remainWithoutGlobStar = remain.slice(1)
  674. var gspref = prefix ? [ prefix ] : []
  675. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  676. // the noGlobStar pattern exits the inGlobStar state
  677. this._process(noGlobStar, index, false, cb)
  678. var isSym = this.symlinks[abs]
  679. var len = entries.length
  680. // If it's a symlink, and we're in a globstar, then stop
  681. if (isSym && inGlobStar)
  682. return cb()
  683. for (var i = 0; i < len; i++) {
  684. var e = entries[i]
  685. if (e.charAt(0) === '.' && !this.dot)
  686. continue
  687. // these two cases enter the inGlobStar state
  688. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  689. this._process(instead, index, true, cb)
  690. var below = gspref.concat(entries[i], remain)
  691. this._process(below, index, true, cb)
  692. }
  693. cb()
  694. }
  695. Glob.prototype._processSimple = function (prefix, index, cb) {
  696. // XXX review this. Shouldn't it be doing the mounting etc
  697. // before doing stat? kinda weird?
  698. var self = this
  699. this._stat(prefix, function (er, exists) {
  700. self._processSimple2(prefix, index, er, exists, cb)
  701. })
  702. }
  703. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  704. //console.error('ps2', prefix, exists)
  705. if (!this.matches[index])
  706. this.matches[index] = Object.create(null)
  707. // If it doesn't exist, then just mark the lack of results
  708. if (!exists)
  709. return cb()
  710. if (prefix && isAbsolute(prefix) && !this.nomount) {
  711. var trail = /[\/\\]$/.test(prefix)
  712. if (prefix.charAt(0) === '/') {
  713. prefix = path.join(this.root, prefix)
  714. } else {
  715. prefix = path.resolve(this.root, prefix)
  716. if (trail)
  717. prefix += '/'
  718. }
  719. }
  720. if (process.platform === 'win32')
  721. prefix = prefix.replace(/\\/g, '/')
  722. // Mark this as a match
  723. this._emitMatch(index, prefix)
  724. cb()
  725. }
  726. // Returns either 'DIR', 'FILE', or false
  727. Glob.prototype._stat = function (f, cb) {
  728. var abs = this._makeAbs(f)
  729. var needDir = f.slice(-1) === '/'
  730. if (f.length > this.maxLength)
  731. return cb()
  732. if (!this.stat && ownProp(this.cache, abs)) {
  733. var c = this.cache[abs]
  734. if (Array.isArray(c))
  735. c = 'DIR'
  736. // It exists, but maybe not how we need it
  737. if (!needDir || c === 'DIR')
  738. return cb(null, c)
  739. if (needDir && c === 'FILE')
  740. return cb()
  741. // otherwise we have to stat, because maybe c=true
  742. // if we know it exists, but not what it is.
  743. }
  744. var exists
  745. var stat = this.statCache[abs]
  746. if (stat !== undefined) {
  747. if (stat === false)
  748. return cb(null, stat)
  749. else {
  750. var type = stat.isDirectory() ? 'DIR' : 'FILE'
  751. if (needDir && type === 'FILE')
  752. return cb()
  753. else
  754. return cb(null, type, stat)
  755. }
  756. }
  757. var self = this
  758. var statcb = inflight('stat\0' + abs, lstatcb_)
  759. if (statcb)
  760. fs.lstat(abs, statcb)
  761. function lstatcb_ (er, lstat) {
  762. if (lstat && lstat.isSymbolicLink()) {
  763. // If it's a symlink, then treat it as the target, unless
  764. // the target does not exist, then treat it as a file.
  765. return fs.stat(abs, function (er, stat) {
  766. if (er)
  767. self._stat2(f, abs, null, lstat, cb)
  768. else
  769. self._stat2(f, abs, er, stat, cb)
  770. })
  771. } else {
  772. self._stat2(f, abs, er, lstat, cb)
  773. }
  774. }
  775. }
  776. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  777. if (er) {
  778. this.statCache[abs] = false
  779. return cb()
  780. }
  781. var needDir = f.slice(-1) === '/'
  782. this.statCache[abs] = stat
  783. if (abs.slice(-1) === '/' && !stat.isDirectory())
  784. return cb(null, false, stat)
  785. var c = stat.isDirectory() ? 'DIR' : 'FILE'
  786. this.cache[abs] = this.cache[abs] || c
  787. if (needDir && c !== 'DIR')
  788. return cb()
  789. return cb(null, c, stat)
  790. }
  791. /***/ },
  792. /* 2 */
  793. /***/ function(module, exports) {
  794. module.exports = require("fs");
  795. /***/ },
  796. /* 3 */
  797. /***/ function(module, exports, __webpack_require__) {
  798. module.exports = minimatch
  799. minimatch.Minimatch = Minimatch
  800. var path = { sep: '/' }
  801. try {
  802. path = __webpack_require__(4)
  803. } catch (er) {}
  804. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
  805. var expand = __webpack_require__(5)
  806. // any single thing other than /
  807. // don't need to escape / when using new RegExp()
  808. var qmark = '[^/]'
  809. // * => any number of characters
  810. var star = qmark + '*?'
  811. // ** when dots are allowed. Anything goes, except .. and .
  812. // not (^ or / followed by one or two dots followed by $ or /),
  813. // followed by anything, any number of times.
  814. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
  815. // not a ^ or / followed by a dot,
  816. // followed by anything, any number of times.
  817. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
  818. // characters that need to be escaped in RegExp.
  819. var reSpecials = charSet('().*{}+?[]^$\\!')
  820. // "abc" -> { a:true, b:true, c:true }
  821. function charSet (s) {
  822. return s.split('').reduce(function (set, c) {
  823. set[c] = true
  824. return set
  825. }, {})
  826. }
  827. // normalizes slashes.
  828. var slashSplit = /\/+/
  829. minimatch.filter = filter
  830. function filter (pattern, options) {
  831. options = options || {}
  832. return function (p, i, list) {
  833. return minimatch(p, pattern, options)
  834. }
  835. }
  836. function ext (a, b) {
  837. a = a || {}
  838. b = b || {}
  839. var t = {}
  840. Object.keys(b).forEach(function (k) {
  841. t[k] = b[k]
  842. })
  843. Object.keys(a).forEach(function (k) {
  844. t[k] = a[k]
  845. })
  846. return t
  847. }
  848. minimatch.defaults = function (def) {
  849. if (!def || !Object.keys(def).length) return minimatch
  850. var orig = minimatch
  851. var m = function minimatch (p, pattern, options) {
  852. return orig.minimatch(p, pattern, ext(def, options))
  853. }
  854. m.Minimatch = function Minimatch (pattern, options) {
  855. return new orig.Minimatch(pattern, ext(def, options))
  856. }
  857. return m
  858. }
  859. Minimatch.defaults = function (def) {
  860. if (!def || !Object.keys(def).length) return Minimatch
  861. return minimatch.defaults(def).Minimatch
  862. }
  863. function minimatch (p, pattern, options) {
  864. if (typeof pattern !== 'string') {
  865. throw new TypeError('glob pattern string required')
  866. }
  867. if (!options) options = {}
  868. // shortcut: comments match nothing.
  869. if (!options.nocomment && pattern.charAt(0) === '#') {
  870. return false
  871. }
  872. // "" only matches ""
  873. if (pattern.trim() === '') return p === ''
  874. return new Minimatch(pattern, options).match(p)
  875. }
  876. function Minimatch (pattern, options) {
  877. if (!(this instanceof Minimatch)) {
  878. return new Minimatch(pattern, options)
  879. }
  880. if (typeof pattern !== 'string') {
  881. throw new TypeError('glob pattern string required')
  882. }
  883. if (!options) options = {}
  884. pattern = pattern.trim()
  885. // windows support: need to use /, not \
  886. if (path.sep !== '/') {
  887. pattern = pattern.split(path.sep).join('/')
  888. }
  889. this.options = options
  890. this.set = []
  891. this.pattern = pattern
  892. this.regexp = null
  893. this.negate = false
  894. this.comment = false
  895. this.empty = false
  896. // make the set of regexps etc.
  897. this.make()
  898. }
  899. Minimatch.prototype.debug = function () {}
  900. Minimatch.prototype.make = make
  901. function make () {
  902. // don't do it more than once.
  903. if (this._made) return
  904. var pattern = this.pattern
  905. var options = this.options
  906. // empty patterns and comments match nothing.
  907. if (!options.nocomment && pattern.charAt(0) === '#') {
  908. this.comment = true
  909. return
  910. }
  911. if (!pattern) {
  912. this.empty = true
  913. return
  914. }
  915. // step 1: figure out negation, etc.
  916. this.parseNegate()
  917. // step 2: expand braces
  918. var set = this.globSet = this.braceExpand()
  919. if (options.debug) this.debug = console.error
  920. this.debug(this.pattern, set)
  921. // step 3: now we have a set, so turn each one into a series of path-portion
  922. // matching patterns.
  923. // These will be regexps, except in the case of "**", which is
  924. // set to the GLOBSTAR object for globstar behavior,
  925. // and will not contain any / characters
  926. set = this.globParts = set.map(function (s) {
  927. return s.split(slashSplit)
  928. })
  929. this.debug(this.pattern, set)
  930. // glob --> regexps
  931. set = set.map(function (s, si, set) {
  932. return s.map(this.parse, this)
  933. }, this)
  934. this.debug(this.pattern, set)
  935. // filter out everything that didn't compile properly.
  936. set = set.filter(function (s) {
  937. return s.indexOf(false) === -1
  938. })
  939. this.debug(this.pattern, set)
  940. this.set = set
  941. }
  942. Minimatch.prototype.parseNegate = parseNegate
  943. function parseNegate () {
  944. var pattern = this.pattern
  945. var negate = false
  946. var options = this.options
  947. var negateOffset = 0
  948. if (options.nonegate) return
  949. for (var i = 0, l = pattern.length
  950. ; i < l && pattern.charAt(i) === '!'
  951. ; i++) {
  952. negate = !negate
  953. negateOffset++
  954. }
  955. if (negateOffset) this.pattern = pattern.substr(negateOffset)
  956. this.negate = negate
  957. }
  958. // Brace expansion:
  959. // a{b,c}d -> abd acd
  960. // a{b,}c -> abc ac
  961. // a{0..3}d -> a0d a1d a2d a3d
  962. // a{b,c{d,e}f}g -> abg acdfg acefg
  963. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  964. //
  965. // Invalid sets are not expanded.
  966. // a{2..}b -> a{2..}b
  967. // a{b}c -> a{b}c
  968. minimatch.braceExpand = function (pattern, options) {
  969. return braceExpand(pattern, options)
  970. }
  971. Minimatch.prototype.braceExpand = braceExpand
  972. function braceExpand (pattern, options) {
  973. if (!options) {
  974. if (this instanceof Minimatch) {
  975. options = this.options
  976. } else {
  977. options = {}
  978. }
  979. }
  980. pattern = typeof pattern === 'undefined'
  981. ? this.pattern : pattern
  982. if (typeof pattern === 'undefined') {
  983. throw new Error('undefined pattern')
  984. }
  985. if (options.nobrace ||
  986. !pattern.match(/\{.*\}/)) {
  987. // shortcut. no need to expand.
  988. return [pattern]
  989. }
  990. return expand(pattern)
  991. }
  992. // parse a component of the expanded set.
  993. // At this point, no pattern may contain "/" in it
  994. // so we're going to return a 2d array, where each entry is the full
  995. // pattern, split on '/', and then turned into a regular expression.
  996. // A regexp is made at the end which joins each array with an
  997. // escaped /, and another full one which joins each regexp with |.
  998. //
  999. // Following the lead of Bash 4.1, note that "**" only has special meaning
  1000. // when it is the *only* thing in a path portion. Otherwise, any series
  1001. // of * is equivalent to a single *. Globstar behavior is enabled by
  1002. // default, and can be disabled by setting options.noglobstar.
  1003. Minimatch.prototype.parse = parse
  1004. var SUBPARSE = {}
  1005. function parse (pattern, isSub) {
  1006. var options = this.options
  1007. // shortcuts
  1008. if (!options.noglobstar && pattern === '**') return GLOBSTAR
  1009. if (pattern === '') return ''
  1010. var re = ''
  1011. var hasMagic = !!options.nocase
  1012. var escaping = false
  1013. // ? => one single character
  1014. var patternListStack = []
  1015. var negativeLists = []
  1016. var plType
  1017. var stateChar
  1018. var inClass = false
  1019. var reClassStart = -1
  1020. var classStart = -1
  1021. // . and .. never match anything that doesn't start with .,
  1022. // even when options.dot is set.
  1023. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  1024. // not (start or / followed by . or .. followed by / or end)
  1025. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
  1026. : '(?!\\.)'
  1027. var self = this
  1028. function clearStateChar () {
  1029. if (stateChar) {
  1030. // we had some state-tracking character
  1031. // that wasn't consumed by this pass.
  1032. switch (stateChar) {
  1033. case '*':
  1034. re += star
  1035. hasMagic = true
  1036. break
  1037. case '?':
  1038. re += qmark
  1039. hasMagic = true
  1040. break
  1041. default:
  1042. re += '\\' + stateChar
  1043. break
  1044. }
  1045. self.debug('clearStateChar %j %j', stateChar, re)
  1046. stateChar = false
  1047. }
  1048. }
  1049. for (var i = 0, len = pattern.length, c
  1050. ; (i < len) && (c = pattern.charAt(i))
  1051. ; i++) {
  1052. this.debug('%s\t%s %s %j', pattern, i, re, c)
  1053. // skip over any that are escaped.
  1054. if (escaping && reSpecials[c]) {
  1055. re += '\\' + c
  1056. escaping = false
  1057. continue
  1058. }
  1059. switch (c) {
  1060. case '/':
  1061. // completely not allowed, even escaped.
  1062. // Should already be path-split by now.
  1063. return false
  1064. case '\\':
  1065. clearStateChar()
  1066. escaping = true
  1067. continue
  1068. // the various stateChar values
  1069. // for the "extglob" stuff.
  1070. case '?':
  1071. case '*':
  1072. case '+':
  1073. case '@':
  1074. case '!':
  1075. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)
  1076. // all of those are literals inside a class, except that
  1077. // the glob [!a] means [^a] in regexp
  1078. if (inClass) {
  1079. this.debug(' in class')
  1080. if (c === '!' && i === classStart + 1) c = '^'
  1081. re += c
  1082. continue
  1083. }
  1084. // if we already have a stateChar, then it means
  1085. // that there was something like ** or +? in there.
  1086. // Handle the stateChar, then proceed with this one.
  1087. self.debug('call clearStateChar %j', stateChar)
  1088. clearStateChar()
  1089. stateChar = c
  1090. // if extglob is disabled, then +(asdf|foo) isn't a thing.
  1091. // just clear the statechar *now*, rather than even diving into
  1092. // the patternList stuff.
  1093. if (options.noext) clearStateChar()
  1094. continue
  1095. case '(':
  1096. if (inClass) {
  1097. re += '('
  1098. continue
  1099. }
  1100. if (!stateChar) {
  1101. re += '\\('
  1102. continue
  1103. }
  1104. plType = stateChar
  1105. patternListStack.push({
  1106. type: plType,
  1107. start: i - 1,
  1108. reStart: re.length
  1109. })
  1110. // negation is (?:(?!js)[^/]*)
  1111. re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
  1112. this.debug('plType %j %j', stateChar, re)
  1113. stateChar = false
  1114. continue
  1115. case ')':
  1116. if (inClass || !patternListStack.length) {
  1117. re += '\\)'
  1118. continue
  1119. }
  1120. clearStateChar()
  1121. hasMagic = true
  1122. re += ')'
  1123. var pl = patternListStack.pop()
  1124. plType = pl.type
  1125. // negation is (?:(?!js)[^/]*)
  1126. // The others are (?:<pattern>)<type>
  1127. switch (plType) {
  1128. case '!':
  1129. negativeLists.push(pl)
  1130. re += ')[^/]*?)'
  1131. pl.reEnd = re.length
  1132. break
  1133. case '?':
  1134. case '+':
  1135. case '*':
  1136. re += plType
  1137. break
  1138. case '@': break // the default anyway
  1139. }
  1140. continue
  1141. case '|':
  1142. if (inClass || !patternListStack.length || escaping) {
  1143. re += '\\|'
  1144. escaping = false
  1145. continue
  1146. }
  1147. clearStateChar()
  1148. re += '|'
  1149. continue
  1150. // these are mostly the same in regexp and glob
  1151. case '[':
  1152. // swallow any state-tracking char before the [
  1153. clearStateChar()
  1154. if (inClass) {
  1155. re += '\\' + c
  1156. continue
  1157. }
  1158. inClass = true
  1159. classStart = i
  1160. reClassStart = re.length
  1161. re += c
  1162. continue
  1163. case ']':
  1164. // a right bracket shall lose its special
  1165. // meaning and represent itself in
  1166. // a bracket expression if it occurs
  1167. // first in the list. -- POSIX.2 2.8.3.2
  1168. if (i === classStart + 1 || !inClass) {
  1169. re += '\\' + c
  1170. escaping = false
  1171. continue
  1172. }
  1173. // handle the case where we left a class open.
  1174. // "[z-a]" is valid, equivalent to "\[z-a\]"
  1175. if (inClass) {
  1176. // split where the last [ was, make sure we don't have
  1177. // an invalid re. if so, re-walk the contents of the
  1178. // would-be class to re-translate any characters that
  1179. // were passed through as-is
  1180. // TODO: It would probably be faster to determine this
  1181. // without a try/catch and a new RegExp, but it's tricky
  1182. // to do safely. For now, this is safe and works.
  1183. var cs = pattern.substring(classStart + 1, i)
  1184. try {
  1185. RegExp('[' + cs + ']')
  1186. } catch (er) {
  1187. // not a valid class!
  1188. var sp = this.parse(cs, SUBPARSE)
  1189. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
  1190. hasMagic = hasMagic || sp[1]
  1191. inClass = false
  1192. continue
  1193. }
  1194. }
  1195. // finish up the class.
  1196. hasMagic = true
  1197. inClass = false
  1198. re += c
  1199. continue
  1200. default:
  1201. // swallow any state char that wasn't consumed
  1202. clearStateChar()
  1203. if (escaping) {
  1204. // no need
  1205. escaping = false
  1206. } else if (reSpecials[c]
  1207. && !(c === '^' && inClass)) {
  1208. re += '\\'
  1209. }
  1210. re += c
  1211. } // switch
  1212. } // for
  1213. // handle the case where we left a class open.
  1214. // "[abc" is valid, equivalent to "\[abc"
  1215. if (inClass) {
  1216. // split where the last [ was, and escape it
  1217. // this is a huge pita. We now have to re-walk
  1218. // the contents of the would-be class to re-translate
  1219. // any characters that were passed through as-is
  1220. cs = pattern.substr(classStart + 1)
  1221. sp = this.parse(cs, SUBPARSE)
  1222. re = re.substr(0, reClassStart) + '\\[' + sp[0]
  1223. hasMagic = hasMagic || sp[1]
  1224. }
  1225. // handle the case where we had a +( thing at the *end*
  1226. // of the pattern.
  1227. // each pattern list stack adds 3 chars, and we need to go through
  1228. // and escape any | chars that were passed through as-is for the regexp.
  1229. // Go through and escape them, taking care not to double-escape any
  1230. // | chars that were already escaped.
  1231. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  1232. var tail = re.slice(pl.reStart + 3)
  1233. // maybe some even number of \, then maybe 1 \, followed by a |
  1234. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  1235. if (!$2) {
  1236. // the | isn't already escaped, so escape it.
  1237. $2 = '\\'
  1238. }
  1239. // need to escape all those slashes *again*, without escaping the
  1240. // one that we need for escaping the | character. As it works out,
  1241. // escaping an even number of slashes can be done by simply repeating
  1242. // it exactly after itself. That's why this trick works.
  1243. //
  1244. // I am sorry that you have to see this.
  1245. return $1 + $1 + $2 + '|'
  1246. })
  1247. this.debug('tail=%j\n %s', tail, tail)
  1248. var t = pl.type === '*' ? star
  1249. : pl.type === '?' ? qmark
  1250. : '\\' + pl.type
  1251. hasMagic = true
  1252. re = re.slice(0, pl.reStart) + t + '\\(' + tail
  1253. }
  1254. // handle trailing things that only matter at the very end.
  1255. clearStateChar()
  1256. if (escaping) {
  1257. // trailing \\
  1258. re += '\\\\'
  1259. }
  1260. // only need to apply the nodot start if the re starts with
  1261. // something that could conceivably capture a dot
  1262. var addPatternStart = false
  1263. switch (re.charAt(0)) {
  1264. case '.':
  1265. case '[':
  1266. case '(': addPatternStart = true
  1267. }
  1268. // Hack to work around lack of negative lookbehind in JS
  1269. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  1270. // like 'a.xyz.yz' doesn't match. So, the first negative
  1271. // lookahead, has to look ALL the way ahead, to the end of
  1272. // the pattern.
  1273. for (var n = negativeLists.length - 1; n > -1; n--) {
  1274. var nl = negativeLists[n]
  1275. var nlBefore = re.slice(0, nl.reStart)
  1276. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8)
  1277. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd)
  1278. var nlAfter = re.slice(nl.reEnd)
  1279. nlLast += nlAfter
  1280. // Handle nested stuff like *(*.js|!(*.json)), where open parens
  1281. // mean that we should *not* include the ) in the bit that is considered
  1282. // "after" the negated section.
  1283. var openParensBefore = nlBefore.split('(').length - 1
  1284. var cleanAfter = nlAfter
  1285. for (i = 0; i < openParensBefore; i++) {
  1286. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '')
  1287. }
  1288. nlAfter = cleanAfter
  1289. var dollar = ''
  1290. if (nlAfter === '' && isSub !== SUBPARSE) {
  1291. dollar = '$'
  1292. }
  1293. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast
  1294. re = newRe
  1295. }
  1296. // if the re is not "" at this point, then we need to make sure
  1297. // it doesn't match against an empty path part.
  1298. // Otherwise a/* will match a/, which it should not.
  1299. if (re !== '' && hasMagic) {
  1300. re = '(?=.)' + re
  1301. }
  1302. if (addPatternStart) {
  1303. re = patternStart + re
  1304. }
  1305. // parsing just a piece of a larger pattern.
  1306. if (isSub === SUBPARSE) {
  1307. return [re, hasMagic]
  1308. }
  1309. // skip the regexp for non-magical patterns
  1310. // unescape anything in it, though, so that it'll be
  1311. // an exact match against a file etc.
  1312. if (!hasMagic) {
  1313. return globUnescape(pattern)
  1314. }
  1315. var flags = options.nocase ? 'i' : ''
  1316. var regExp = new RegExp('^' + re + '$', flags)
  1317. regExp._glob = pattern
  1318. regExp._src = re
  1319. return regExp
  1320. }
  1321. minimatch.makeRe = function (pattern, options) {
  1322. return new Minimatch(pattern, options || {}).makeRe()
  1323. }
  1324. Minimatch.prototype.makeRe = makeRe
  1325. function makeRe () {
  1326. if (this.regexp || this.regexp === false) return this.regexp
  1327. // at this point, this.set is a 2d array of partial
  1328. // pattern strings, or "**".
  1329. //
  1330. // It's better to use .match(). This function shouldn't
  1331. // be used, really, but it's pretty convenient sometimes,
  1332. // when you just want to work with a regex.
  1333. var set = this.set
  1334. if (!set.length) {
  1335. this.regexp = false
  1336. return this.regexp
  1337. }
  1338. var options = this.options
  1339. var twoStar = options.noglobstar ? star
  1340. : options.dot ? twoStarDot
  1341. : twoStarNoDot
  1342. var flags = options.nocase ? 'i' : ''
  1343. var re = set.map(function (pattern) {
  1344. return pattern.map(function (p) {
  1345. return (p === GLOBSTAR) ? twoStar
  1346. : (typeof p === 'string') ? regExpEscape(p)
  1347. : p._src
  1348. }).join('\\\/')
  1349. }).join('|')
  1350. // must match entire pattern
  1351. // ending in a * or ** will make it less strict.
  1352. re = '^(?:' + re + ')$'
  1353. // can match anything, as long as it's not this.
  1354. if (this.negate) re = '^(?!' + re + ').*$'
  1355. try {
  1356. this.regexp = new RegExp(re, flags)
  1357. } catch (ex) {
  1358. this.regexp = false
  1359. }
  1360. return this.regexp
  1361. }
  1362. minimatch.match = function (list, pattern, options) {
  1363. options = options || {}
  1364. var mm = new Minimatch(pattern, options)
  1365. list = list.filter(function (f) {
  1366. return mm.match(f)
  1367. })
  1368. if (mm.options.nonull && !list.length) {
  1369. list.push(pattern)
  1370. }
  1371. return list
  1372. }
  1373. Minimatch.prototype.match = match
  1374. function match (f, partial) {
  1375. this.debug('match', f, this.pattern)
  1376. // short-circuit in the case of busted things.
  1377. // comments, etc.
  1378. if (this.comment) return false
  1379. if (this.empty) return f === ''
  1380. if (f === '/' && partial) return true
  1381. var options = this.options
  1382. // windows: need to use /, not \
  1383. if (path.sep !== '/') {
  1384. f = f.split(path.sep).join('/')
  1385. }
  1386. // treat the test path as a set of pathparts.
  1387. f = f.split(slashSplit)
  1388. this.debug(this.pattern, 'split', f)
  1389. // just ONE of the pattern sets in this.set needs to match
  1390. // in order for it to be valid. If negating, then just one
  1391. // match means that we have failed.
  1392. // Either way, return on the first hit.
  1393. var set = this.set
  1394. this.debug(this.pattern, 'set', set)
  1395. // Find the basename of the path by looking for the last non-empty segment
  1396. var filename
  1397. var i
  1398. for (i = f.length - 1; i >= 0; i--) {
  1399. filename = f[i]
  1400. if (filename) break
  1401. }
  1402. for (i = 0; i < set.length; i++) {
  1403. var pattern = set[i]
  1404. var file = f
  1405. if (options.matchBase && pattern.length === 1) {
  1406. file = [filename]
  1407. }
  1408. var hit = this.matchOne(file, pattern, partial)
  1409. if (hit) {
  1410. if (options.flipNegate) return true
  1411. return !this.negate
  1412. }
  1413. }
  1414. // didn't get any hits. this is success if it's a negative
  1415. // pattern, failure otherwise.
  1416. if (options.flipNegate) return false
  1417. return this.negate
  1418. }
  1419. // set partial to true to test if, for example,
  1420. // "/a/b" matches the start of "/*/b/*/d"
  1421. // Partial means, if you run out of file before you run
  1422. // out of pattern, then that's fine, as long as all
  1423. // the parts match.
  1424. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  1425. var options = this.options
  1426. this.debug('matchOne',
  1427. { 'this': this, file: file, pattern: pattern })
  1428. this.debug('matchOne', file.length, pattern.length)
  1429. for (var fi = 0,
  1430. pi = 0,
  1431. fl = file.length,
  1432. pl = pattern.length
  1433. ; (fi < fl) && (pi < pl)
  1434. ; fi++, pi++) {
  1435. this.debug('matchOne loop')
  1436. var p = pattern[pi]
  1437. var f = file[fi]
  1438. this.debug(pattern, p, f)
  1439. // should be impossible.
  1440. // some invalid regexp stuff in the set.
  1441. if (p === false) return false
  1442. if (p === GLOBSTAR) {
  1443. this.debug('GLOBSTAR', [pattern, p, f])
  1444. // "**"
  1445. // a/**/b/**/c would match the following:
  1446. // a/b/x/y/z/c
  1447. // a/x/y/z/b/c
  1448. // a/b/x/b/x/c
  1449. // a/b/c
  1450. // To do this, take the rest of the pattern after
  1451. // the **, and see if it would match the file remainder.
  1452. // If so, return success.
  1453. // If not, the ** "swallows" a segment, and try again.
  1454. // This is recursively awful.
  1455. //
  1456. // a/**/b/**/c matching a/b/x/y/z/c
  1457. // - a matches a
  1458. // - doublestar
  1459. // - matchOne(b/x/y/z/c, b/**/c)
  1460. // - b matches b
  1461. // - doublestar
  1462. // - matchOne(x/y/z/c, c) -> no
  1463. // - matchOne(y/z/c, c) -> no
  1464. // - matchOne(z/c, c) -> no
  1465. // - matchOne(c, c) yes, hit
  1466. var fr = fi
  1467. var pr = pi + 1
  1468. if (pr === pl) {
  1469. this.debug('** at the end')
  1470. // a ** at the end will just swallow the rest.
  1471. // We have found a match.
  1472. // however, it will not swallow /.x, unless
  1473. // options.dot is set.
  1474. // . and .. are *never* matched by **, for explosively
  1475. // exponential reasons.
  1476. for (; fi < fl; fi++) {
  1477. if (file[fi] === '.' || file[fi] === '..' ||
  1478. (!options.dot && file[fi].charAt(0) === '.')) return false
  1479. }
  1480. return true
  1481. }
  1482. // ok, let's see if we can swallow whatever we can.
  1483. while (fr < fl) {
  1484. var swallowee = file[fr]
  1485. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee)
  1486. // XXX remove this slice. Just pass the start index.
  1487. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  1488. this.debug('globstar found match!', fr, fl, swallowee)
  1489. // found a match.
  1490. return true
  1491. } else {
  1492. // can't swallow "." or ".." ever.
  1493. // can only swallow ".foo" when explicitly asked.
  1494. if (swallowee === '.' || swallowee === '..' ||
  1495. (!options.dot && swallowee.charAt(0) === '.')) {
  1496. this.debug('dot detected!', file, fr, pattern, pr)
  1497. break
  1498. }
  1499. // ** swallows a segment, and continue.
  1500. this.debug('globstar swallow a segment, and continue')
  1501. fr++
  1502. }
  1503. }
  1504. // no match was found.
  1505. // However, in partial mode, we can't say this is necessarily over.
  1506. // If there's more *pattern* left, then
  1507. if (partial) {
  1508. // ran out of file
  1509. this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
  1510. if (fr === fl) return true
  1511. }
  1512. return false
  1513. }
  1514. // something other than **
  1515. // non-magic patterns just have to match exactly
  1516. // patterns with magic have been turned into regexps.
  1517. var hit
  1518. if (typeof p === 'string') {
  1519. if (options.nocase) {
  1520. hit = f.toLowerCase() === p.toLowerCase()
  1521. } else {
  1522. hit = f === p
  1523. }
  1524. this.debug('string match', p, f, hit)
  1525. } else {
  1526. hit = f.match(p)
  1527. this.debug('pattern match', p, f, hit)
  1528. }
  1529. if (!hit) return false
  1530. }
  1531. // Note: ending in / means that we'll get a final ""
  1532. // at the end of the pattern. This can only match a
  1533. // corresponding "" at the end of the file.
  1534. // If the file ends in /, then it can only match a
  1535. // a pattern that ends in /, unless the pattern just
  1536. // doesn't have any more for it. But, a/b/ should *not*
  1537. // match "a/b/*", even though "" matches against the
  1538. // [^/]*? pattern, except in partial mode, where it might
  1539. // simply not be reached yet.
  1540. // However, a/b/ should still satisfy a/*
  1541. // now either we fell off the end of the pattern, or we're done.
  1542. if (fi === fl && pi === pl) {
  1543. // ran out of pattern and filename at the same time.
  1544. // an exact hit!
  1545. return true
  1546. } else if (fi === fl) {
  1547. // ran out of file, but still had pattern left.
  1548. // this is ok if we're doing the match as part of
  1549. // a glob fs traversal.
  1550. return partial
  1551. } else if (pi === pl) {
  1552. // ran out of pattern, still have file left.
  1553. // this is only acceptable if we're on the very last
  1554. // empty segment of a file with a trailing slash.
  1555. // a/* should match a/b/
  1556. var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
  1557. return emptyFileEnd
  1558. }
  1559. // should be unreachable.
  1560. throw new Error('wtf?')
  1561. }
  1562. // replace stuff like \* with *
  1563. function globUnescape (s) {
  1564. return s.replace(/\\(.)/g, '$1')
  1565. }
  1566. function regExpEscape (s) {
  1567. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
  1568. }
  1569. /***/ },
  1570. /* 4 */
  1571. /***/ function(module, exports) {
  1572. module.exports = require("path");
  1573. /***/ },
  1574. /* 5 */
  1575. /***/ function(module, exports, __webpack_require__) {
  1576. var concatMap = __webpack_require__(6);
  1577. var balanced = __webpack_require__(7);
  1578. module.exports = expandTop;
  1579. var escSlash = '\0SLASH'+Math.random()+'\0';
  1580. var escOpen = '\0OPEN'+Math.random()+'\0';
  1581. var escClose = '\0CLOSE'+Math.random()+'\0';
  1582. var escComma = '\0COMMA'+Math.random()+'\0';
  1583. var escPeriod = '\0PERIOD'+Math.random()+'\0';
  1584. function numeric(str) {
  1585. return parseInt(str, 10) == str
  1586. ? parseInt(str, 10)
  1587. : str.charCodeAt(0);
  1588. }
  1589. function escapeBraces(str) {
  1590. return str.split('\\\\').join(escSlash)
  1591. .split('\\{').join(escOpen)
  1592. .split('\\}').join(escClose)
  1593. .split('\\,').join(escComma)
  1594. .split('\\.').join(escPeriod);
  1595. }
  1596. function unescapeBraces(str) {
  1597. return str.split(escSlash).join('\\')
  1598. .split(escOpen).join('{')
  1599. .split(escClose).join('}')
  1600. .split(escComma).join(',')
  1601. .split(escPeriod).join('.');
  1602. }
  1603. // Basically just str.split(","), but handling cases
  1604. // where we have nested braced sections, which should be
  1605. // treated as individual members, like {a,{b,c},d}
  1606. function parseCommaParts(str) {
  1607. if (!str)
  1608. return [''];
  1609. var parts = [];
  1610. var m = balanced('{', '}', str);
  1611. if (!m)
  1612. return str.split(',');
  1613. var pre = m.pre;
  1614. var body = m.body;
  1615. var post = m.post;
  1616. var p = pre.split(',');
  1617. p[p.length-1] += '{' + body + '}';
  1618. var postParts = parseCommaParts(post);
  1619. if (post.length) {
  1620. p[p.length-1] += postParts.shift();
  1621. p.push.apply(p, postParts);
  1622. }
  1623. parts.push.apply(parts, p);
  1624. return parts;
  1625. }
  1626. function expandTop(str) {
  1627. if (!str)
  1628. return [];
  1629. return expand(escapeBraces(str), true).map(unescapeBraces);
  1630. }
  1631. function identity(e) {
  1632. return e;
  1633. }
  1634. function embrace(str) {
  1635. return '{' + str + '}';
  1636. }
  1637. function isPadded(el) {
  1638. return /^-?0\d/.test(el);
  1639. }
  1640. function lte(i, y) {
  1641. return i <= y;
  1642. }
  1643. function gte(i, y) {
  1644. return i >= y;
  1645. }
  1646. function expand(str, isTop) {
  1647. var expansions = [];
  1648. var m = balanced('{', '}', str);
  1649. if (!m || /\$$/.test(m.pre)) return [str];
  1650. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  1651. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  1652. var isSequence = isNumericSequence || isAlphaSequence;
  1653. var isOptions = /^(.*,)+(.+)?$/.test(m.body);
  1654. if (!isSequence && !isOptions) {
  1655. // {a},b}
  1656. if (m.post.match(/,.*\}/)) {
  1657. str = m.pre + '{' + m.body + escClose + m.post;
  1658. return expand(str);
  1659. }
  1660. return [str];
  1661. }
  1662. var n;
  1663. if (isSequence) {
  1664. n = m.body.split(/\.\./);
  1665. } else {
  1666. n = parseCommaParts(m.body);
  1667. if (n.length === 1) {
  1668. // x{{a,b}}y ==> x{a}y x{b}y
  1669. n = expand(n[0], false).map(embrace);
  1670. if (n.length === 1) {
  1671. var post = m.post.length
  1672. ? expand(m.post, false)
  1673. : [''];
  1674. return post.map(function(p) {
  1675. return m.pre + n[0] + p;
  1676. });
  1677. }
  1678. }
  1679. }
  1680. // at this point, n is the parts, and we know it's not a comma set
  1681. // with a single entry.
  1682. // no need to expand pre, since it is guaranteed to be free of brace-sets
  1683. var pre = m.pre;
  1684. var post = m.post.length
  1685. ? expand(m.post, false)
  1686. : [''];
  1687. var N;
  1688. if (isSequence) {
  1689. var x = numeric(n[0]);
  1690. var y = numeric(n[1]);
  1691. var width = Math.max(n[0].length, n[1].length)
  1692. var incr = n.length == 3
  1693. ? Math.abs(numeric(n[2]))
  1694. : 1;
  1695. var test = lte;
  1696. var reverse = y < x;
  1697. if (reverse) {
  1698. incr *= -1;
  1699. test = gte;
  1700. }
  1701. var pad = n.some(isPadded);
  1702. N = [];
  1703. for (var i = x; test(i, y); i += incr) {
  1704. var c;
  1705. if (isAlphaSequence) {
  1706. c = String.fromCharCode(i);
  1707. if (c === '\\')
  1708. c = '';
  1709. } else {
  1710. c = String(i);
  1711. if (pad) {
  1712. var need = width - c.length;
  1713. if (need > 0) {
  1714. var z = new Array(need + 1).join('0');
  1715. if (i < 0)
  1716. c = '-' + z + c.slice(1);
  1717. else
  1718. c = z + c;
  1719. }
  1720. }
  1721. }
  1722. N.push(c);
  1723. }
  1724. } else {
  1725. N = concatMap(n, function(el) { return expand(el, false) });
  1726. }
  1727. for (var j = 0; j < N.length; j++) {
  1728. for (var k = 0; k < post.length; k++) {
  1729. var expansion = pre + N[j] + post[k];
  1730. if (!isTop || isSequence || expansion)
  1731. expansions.push(expansion);
  1732. }
  1733. }
  1734. return expansions;
  1735. }
  1736. /***/ },
  1737. /* 6 */
  1738. /***/ function(module, exports) {
  1739. module.exports = function (xs, fn) {
  1740. var res = [];
  1741. for (var i = 0; i < xs.length; i++) {
  1742. var x = fn(xs[i], i);
  1743. if (isArray(x)) res.push.apply(res, x);
  1744. else res.push(x);
  1745. }
  1746. return res;
  1747. };
  1748. var isArray = Array.isArray || function (xs) {
  1749. return Object.prototype.toString.call(xs) === '[object Array]';
  1750. };
  1751. /***/ },
  1752. /* 7 */
  1753. /***/ function(module, exports) {
  1754. module.exports = balanced;
  1755. function balanced(a, b, str) {
  1756. var r = range(a, b, str);
  1757. return r && {
  1758. start: r[0],
  1759. end: r[1],
  1760. pre: str.slice(0, r[0]),
  1761. body: str.slice(r[0] + a.length, r[1]),
  1762. post: str.slice(r[1] + b.length)
  1763. };
  1764. }
  1765. balanced.range = range;
  1766. function range(a, b, str) {
  1767. var begs, beg, left, right, result;
  1768. var ai = str.indexOf(a);
  1769. var bi = str.indexOf(b, ai + 1);
  1770. var i = ai;
  1771. if (ai >= 0 && bi > 0) {
  1772. begs = [];
  1773. left = str.length;
  1774. while (i < str.length && i >= 0 && ! result) {
  1775. if (i == ai) {
  1776. begs.push(i);
  1777. ai = str.indexOf(a, i + 1);
  1778. } else if (begs.length == 1) {
  1779. result = [ begs.pop(), bi ];
  1780. } else {
  1781. beg = begs.pop();
  1782. if (beg < left) {
  1783. left = beg;
  1784. right = bi;
  1785. }
  1786. bi = str.indexOf(b, i + 1);
  1787. }
  1788. i = ai < bi && ai >= 0 ? ai : bi;
  1789. }
  1790. if (begs.length) {
  1791. result = [ left, right ];
  1792. }
  1793. }
  1794. return result;
  1795. }
  1796. /***/ },
  1797. /* 8 */
  1798. /***/ function(module, exports, __webpack_require__) {
  1799. module.exports = __webpack_require__(9).inherits
  1800. /***/ },
  1801. /* 9 */
  1802. /***/ function(module, exports) {
  1803. module.exports = require("util");
  1804. /***/ },
  1805. /* 10 */
  1806. /***/ function(module, exports) {
  1807. module.exports = require("events");
  1808. /***/ },
  1809. /* 11 */
  1810. /***/ function(module, exports) {
  1811. module.exports = require("assert");
  1812. /***/ },
  1813. /* 12 */
  1814. /***/ function(module, exports) {
  1815. 'use strict';
  1816. function posix(path) {
  1817. return path.charAt(0) === '/';
  1818. };
  1819. function win32(path) {
  1820. // https://github.com/joyent/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  1821. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  1822. var result = splitDeviceRe.exec(path);
  1823. var device = result[1] || '';
  1824. var isUnc = !!device && device.charAt(1) !== ':';
  1825. // UNC paths are always absolute
  1826. return !!result[2] || isUnc;
  1827. };
  1828. module.exports = process.platform === 'win32' ? win32 : posix;
  1829. module.exports.posix = posix;
  1830. module.exports.win32 = win32;
  1831. /***/ },
  1832. /* 13 */
  1833. /***/ function(module, exports, __webpack_require__) {
  1834. module.exports = globSync
  1835. globSync.GlobSync = GlobSync
  1836. var fs = __webpack_require__(2)
  1837. var minimatch = __webpack_require__(3)
  1838. var Minimatch = minimatch.Minimatch
  1839. var Glob = __webpack_require__(1).Glob
  1840. var util = __webpack_require__(9)
  1841. var path = __webpack_require__(4)
  1842. var assert = __webpack_require__(11)
  1843. var isAbsolute = __webpack_require__(12)
  1844. var common = __webpack_require__(14)
  1845. var alphasort = common.alphasort
  1846. var alphasorti = common.alphasorti
  1847. var setopts = common.setopts
  1848. var ownProp = common.ownProp
  1849. var childrenIgnored = common.childrenIgnored
  1850. function globSync (pattern, options) {
  1851. if (typeof options === 'function' || arguments.length === 3)
  1852. throw new TypeError('callback provided to sync glob\n'+
  1853. 'See: https://github.com/isaacs/node-glob/issues/167')
  1854. return new GlobSync(pattern, options).found
  1855. }
  1856. function GlobSync (pattern, options) {
  1857. if (!pattern)
  1858. throw new Error('must provide pattern')
  1859. if (typeof options === 'function' || arguments.length === 3)
  1860. throw new TypeError('callback provided to sync glob\n'+
  1861. 'See: https://github.com/isaacs/node-glob/issues/167')
  1862. if (!(this instanceof GlobSync))
  1863. return new GlobSync(pattern, options)
  1864. setopts(this, pattern, options)
  1865. if (this.noprocess)
  1866. return this
  1867. var n = this.minimatch.set.length
  1868. this.matches = new Array(n)
  1869. for (var i = 0; i < n; i ++) {
  1870. this._process(this.minimatch.set[i], i, false)
  1871. }
  1872. this._finish()
  1873. }
  1874. GlobSync.prototype._finish = function () {
  1875. assert(this instanceof GlobSync)
  1876. if (this.realpath) {
  1877. var self = this
  1878. this.matches.forEach(function (matchset, index) {
  1879. var set = self.matches[index] = Object.create(null)
  1880. for (var p in matchset) {
  1881. try {
  1882. p = self._makeAbs(p)
  1883. var real = fs.realpathSync(p, self.realpathCache)
  1884. set[real] = true
  1885. } catch (er) {
  1886. if (er.syscall === 'stat')
  1887. set[self._makeAbs(p)] = true
  1888. else
  1889. throw er
  1890. }
  1891. }
  1892. })
  1893. }
  1894. common.finish(this)
  1895. }
  1896. GlobSync.prototype._process = function (pattern, index, inGlobStar) {
  1897. assert(this instanceof GlobSync)
  1898. // Get the first [n] parts of pattern that are all strings.
  1899. var n = 0
  1900. while (typeof pattern[n] === 'string') {
  1901. n ++
  1902. }
  1903. // now n is the index of the first one that is *not* a string.
  1904. // See if there's anything else
  1905. var prefix
  1906. switch (n) {
  1907. // if not, then this is rather simple
  1908. case pattern.length:
  1909. this._processSimple(pattern.join('/'), index)
  1910. return
  1911. case 0:
  1912. // pattern *starts* with some non-trivial item.
  1913. // going to readdir(cwd), but not include the prefix in matches.
  1914. prefix = null
  1915. break
  1916. default:
  1917. // pattern has some string bits in the front.
  1918. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  1919. // or 'relative' like '../baz'
  1920. prefix = pattern.slice(0, n).join('/')
  1921. break
  1922. }
  1923. var remain = pattern.slice(n)
  1924. // get the list of entries.
  1925. var read
  1926. if (prefix === null)
  1927. read = '.'
  1928. else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
  1929. if (!prefix || !isAbsolute(prefix))
  1930. prefix = '/' + prefix
  1931. read = prefix
  1932. } else
  1933. read = prefix
  1934. var abs = this._makeAbs(read)
  1935. //if ignored, skip processing
  1936. if (childrenIgnored(this, read))
  1937. return
  1938. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  1939. if (isGlobStar)
  1940. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar)
  1941. else
  1942. this._processReaddir(prefix, read, abs, remain, index, inGlobStar)
  1943. }
  1944. GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  1945. var entries = this._readdir(abs, inGlobStar)
  1946. // if the abs isn't a dir, then nothing can match!
  1947. if (!entries)
  1948. return
  1949. // It will only match dot entries if it starts with a dot, or if
  1950. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  1951. var pn = remain[0]
  1952. var negate = !!this.minimatch.negate
  1953. var rawGlob = pn._glob
  1954. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  1955. var matchedEntries = []
  1956. for (var i = 0; i < entries.length; i++) {
  1957. var e = entries[i]
  1958. if (e.charAt(0) !== '.' || dotOk) {
  1959. var m
  1960. if (negate && !prefix) {
  1961. m = !e.match(pn)
  1962. } else {
  1963. m = e.match(pn)
  1964. }
  1965. if (m)
  1966. matchedEntries.push(e)
  1967. }
  1968. }
  1969. var len = matchedEntries.length
  1970. // If there are no matched entries, then nothing matches.
  1971. if (len === 0)
  1972. return
  1973. // if this is the last remaining pattern bit, then no need for
  1974. // an additional stat *unless* the user has specified mark or
  1975. // stat explicitly. We know they exist, since readdir returned
  1976. // them.
  1977. if (remain.length === 1 && !this.mark && !this.stat) {
  1978. if (!this.matches[index])
  1979. this.matches[index] = Object.create(null)
  1980. for (var i = 0; i < len; i ++) {
  1981. var e = matchedEntries[i]
  1982. if (prefix) {
  1983. if (prefix.slice(-1) !== '/')
  1984. e = prefix + '/' + e
  1985. else
  1986. e = prefix + e
  1987. }
  1988. if (e.charAt(0) === '/' && !this.nomount) {
  1989. e = path.join(this.root, e)
  1990. }
  1991. this.matches[index][e] = true
  1992. }
  1993. // This was the last one, and no stats were needed
  1994. return
  1995. }
  1996. // now test all matched entries as stand-ins for that part
  1997. // of the pattern.
  1998. remain.shift()
  1999. for (var i = 0; i < len; i ++) {
  2000. var e = matchedEntries[i]
  2001. var newPattern
  2002. if (prefix)
  2003. newPattern = [prefix, e]
  2004. else
  2005. newPattern = [e]
  2006. this._process(newPattern.concat(remain), index, inGlobStar)
  2007. }
  2008. }
  2009. GlobSync.prototype._emitMatch = function (index, e) {
  2010. var abs = this._makeAbs(e)
  2011. if (this.mark)
  2012. e = this._mark(e)
  2013. if (this.matches[index][e])
  2014. return
  2015. if (this.nodir) {
  2016. var c = this.cache[this._makeAbs(e)]
  2017. if (c === 'DIR' || Array.isArray(c))
  2018. return
  2019. }
  2020. this.matches[index][e] = true
  2021. if (this.stat)
  2022. this._stat(e)
  2023. }
  2024. GlobSync.prototype._readdirInGlobStar = function (abs) {
  2025. // follow all symlinked directories forever
  2026. // just proceed as if this is a non-globstar situation
  2027. if (this.follow)
  2028. return this._readdir(abs, false)
  2029. var entries
  2030. var lstat
  2031. var stat
  2032. try {
  2033. lstat = fs.lstatSync(abs)
  2034. } catch (er) {
  2035. // lstat failed, doesn't exist
  2036. return null
  2037. }
  2038. var isSym = lstat.isSymbolicLink()
  2039. this.symlinks[abs] = isSym
  2040. // If it's not a symlink or a dir, then it's definitely a regular file.
  2041. // don't bother doing a readdir in that case.
  2042. if (!isSym && !lstat.isDirectory())
  2043. this.cache[abs] = 'FILE'
  2044. else
  2045. entries = this._readdir(abs, false)
  2046. return entries
  2047. }
  2048. GlobSync.prototype._readdir = function (abs, inGlobStar) {
  2049. var entries
  2050. if (inGlobStar && !ownProp(this.symlinks, abs))
  2051. return this._readdirInGlobStar(abs)
  2052. if (ownProp(this.cache, abs)) {
  2053. var c = this.cache[abs]
  2054. if (!c || c === 'FILE')
  2055. return null
  2056. if (Array.isArray(c))
  2057. return c
  2058. }
  2059. try {
  2060. return this._readdirEntries(abs, fs.readdirSync(abs))
  2061. } catch (er) {
  2062. this._readdirError(abs, er)
  2063. return null
  2064. }
  2065. }
  2066. GlobSync.prototype._readdirEntries = function (abs, entries) {
  2067. // if we haven't asked to stat everything, then just
  2068. // assume that everything in there exists, so we can avoid
  2069. // having to stat it a second time.
  2070. if (!this.mark && !this.stat) {
  2071. for (var i = 0; i < entries.length; i ++) {
  2072. var e = entries[i]
  2073. if (abs === '/')
  2074. e = abs + e
  2075. else
  2076. e = abs + '/' + e
  2077. this.cache[e] = true
  2078. }
  2079. }
  2080. this.cache[abs] = entries
  2081. // mark and cache dir-ness
  2082. return entries
  2083. }
  2084. GlobSync.prototype._readdirError = function (f, er) {
  2085. // handle errors, and cache the information
  2086. switch (er.code) {
  2087. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  2088. case 'ENOTDIR': // totally normal. means it *does* exist.
  2089. this.cache[this._makeAbs(f)] = 'FILE'
  2090. if (f === this.cwd) {
  2091. var error = new Error(er.code + ' invalid cwd ' + f)
  2092. error.path = f
  2093. error.code = er.code
  2094. throw error
  2095. }
  2096. break
  2097. case 'ENOENT': // not terribly unusual
  2098. case 'ELOOP':
  2099. case 'ENAMETOOLONG':
  2100. case 'UNKNOWN':
  2101. this.cache[this._makeAbs(f)] = false
  2102. break
  2103. default: // some unusual error. Treat as failure.
  2104. this.cache[this._makeAbs(f)] = false
  2105. if (this.strict)
  2106. throw er
  2107. if (!this.silent)
  2108. console.error('glob error', er)
  2109. break
  2110. }
  2111. }
  2112. GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  2113. var entries = this._readdir(abs, inGlobStar)
  2114. // no entries means not a dir, so it can never have matches
  2115. // foo.txt/** doesn't match foo.txt
  2116. if (!entries)
  2117. return
  2118. // test without the globstar, and with every child both below
  2119. // and replacing the globstar.
  2120. var remainWithoutGlobStar = remain.slice(1)
  2121. var gspref = prefix ? [ prefix ] : []
  2122. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  2123. // the noGlobStar pattern exits the inGlobStar state
  2124. this._process(noGlobStar, index, false)
  2125. var len = entries.length
  2126. var isSym = this.symlinks[abs]
  2127. // If it's a symlink, and we're in a globstar, then stop
  2128. if (isSym && inGlobStar)
  2129. return
  2130. for (var i = 0; i < len; i++) {
  2131. var e = entries[i]
  2132. if (e.charAt(0) === '.' && !this.dot)
  2133. continue
  2134. // these two cases enter the inGlobStar state
  2135. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  2136. this._process(instead, index, true)
  2137. var below = gspref.concat(entries[i], remain)
  2138. this._process(below, index, true)
  2139. }
  2140. }
  2141. GlobSync.prototype._processSimple = function (prefix, index) {
  2142. // XXX review this. Shouldn't it be doing the mounting etc
  2143. // before doing stat? kinda weird?
  2144. var exists = this._stat(prefix)
  2145. if (!this.matches[index])
  2146. this.matches[index] = Object.create(null)
  2147. // If it doesn't exist, then just mark the lack of results
  2148. if (!exists)
  2149. return
  2150. if (prefix && isAbsolute(prefix) && !this.nomount) {
  2151. var trail = /[\/\\]$/.test(prefix)
  2152. if (prefix.charAt(0) === '/') {
  2153. prefix = path.join(this.root, prefix)
  2154. } else {
  2155. prefix = path.resolve(this.root, prefix)
  2156. if (trail)
  2157. prefix += '/'
  2158. }
  2159. }
  2160. if (process.platform === 'win32')
  2161. prefix = prefix.replace(/\\/g, '/')
  2162. // Mark this as a match
  2163. this.matches[index][prefix] = true
  2164. }
  2165. // Returns either 'DIR', 'FILE', or false
  2166. GlobSync.prototype._stat = function (f) {
  2167. var abs = this._makeAbs(f)
  2168. var needDir = f.slice(-1) === '/'
  2169. if (f.length > this.maxLength)
  2170. return false
  2171. if (!this.stat && ownProp(this.cache, abs)) {
  2172. var c = this.cache[abs]
  2173. if (Array.isArray(c))
  2174. c = 'DIR'
  2175. // It exists, but maybe not how we need it
  2176. if (!needDir || c === 'DIR')
  2177. return c
  2178. if (needDir && c === 'FILE')
  2179. return false
  2180. // otherwise we have to stat, because maybe c=true
  2181. // if we know it exists, but not what it is.
  2182. }
  2183. var exists
  2184. var stat = this.statCache[abs]
  2185. if (!stat) {
  2186. var lstat
  2187. try {
  2188. lstat = fs.lstatSync(abs)
  2189. } catch (er) {
  2190. return false
  2191. }
  2192. if (lstat.isSymbolicLink()) {
  2193. try {
  2194. stat = fs.statSync(abs)
  2195. } catch (er) {
  2196. stat = lstat
  2197. }
  2198. } else {
  2199. stat = lstat
  2200. }
  2201. }
  2202. this.statCache[abs] = stat
  2203. var c = stat.isDirectory() ? 'DIR' : 'FILE'
  2204. this.cache[abs] = this.cache[abs] || c
  2205. if (needDir && c !== 'DIR')
  2206. return false
  2207. return c
  2208. }
  2209. GlobSync.prototype._mark = function (p) {
  2210. return common.mark(this, p)
  2211. }
  2212. GlobSync.prototype._makeAbs = function (f) {
  2213. return common.makeAbs(this, f)
  2214. }
  2215. /***/ },
  2216. /* 14 */
  2217. /***/ function(module, exports, __webpack_require__) {
  2218. exports.alphasort = alphasort
  2219. exports.alphasorti = alphasorti
  2220. exports.setopts = setopts
  2221. exports.ownProp = ownProp
  2222. exports.makeAbs = makeAbs
  2223. exports.finish = finish
  2224. exports.mark = mark
  2225. exports.isIgnored = isIgnored
  2226. exports.childrenIgnored = childrenIgnored
  2227. function ownProp (obj, field) {
  2228. return Object.prototype.hasOwnProperty.call(obj, field)
  2229. }
  2230. var path = __webpack_require__(4)
  2231. var minimatch = __webpack_require__(3)
  2232. var isAbsolute = __webpack_require__(12)
  2233. var Minimatch = minimatch.Minimatch
  2234. function alphasorti (a, b) {
  2235. return a.toLowerCase().localeCompare(b.toLowerCase())
  2236. }
  2237. function alphasort (a, b) {
  2238. return a.localeCompare(b)
  2239. }
  2240. function setupIgnores (self, options) {
  2241. self.ignore = options.ignore || []
  2242. if (!Array.isArray(self.ignore))
  2243. self.ignore = [self.ignore]
  2244. if (self.ignore.length) {
  2245. self.ignore = self.ignore.map(ignoreMap)
  2246. }
  2247. }
  2248. // ignore patterns are always in dot:true mode.
  2249. function ignoreMap (pattern) {
  2250. var gmatcher = null
  2251. if (pattern.slice(-3) === '/**') {
  2252. var gpattern = pattern.replace(/(\/\*\*)+$/, '')
  2253. gmatcher = new Minimatch(gpattern, { dot: true })
  2254. }
  2255. return {
  2256. matcher: new Minimatch(pattern, { dot: true }),
  2257. gmatcher: gmatcher
  2258. }
  2259. }
  2260. function setopts (self, pattern, options) {
  2261. if (!options)
  2262. options = {}
  2263. // base-matching: just use globstar for that.
  2264. if (options.matchBase && -1 === pattern.indexOf("/")) {
  2265. if (options.noglobstar) {
  2266. throw new Error("base matching requires globstar")
  2267. }
  2268. pattern = "**/" + pattern
  2269. }
  2270. self.silent = !!options.silent
  2271. self.pattern = pattern
  2272. self.strict = options.strict !== false
  2273. self.realpath = !!options.realpath
  2274. self.realpathCache = options.realpathCache || Object.create(null)
  2275. self.follow = !!options.follow
  2276. self.dot = !!options.dot
  2277. self.mark = !!options.mark
  2278. self.nodir = !!options.nodir
  2279. if (self.nodir)
  2280. self.mark = true
  2281. self.sync = !!options.sync
  2282. self.nounique = !!options.nounique
  2283. self.nonull = !!options.nonull
  2284. self.nosort = !!options.nosort
  2285. self.nocase = !!options.nocase
  2286. self.stat = !!options.stat
  2287. self.noprocess = !!options.noprocess
  2288. self.maxLength = options.maxLength || Infinity
  2289. self.cache = options.cache || Object.create(null)
  2290. self.statCache = options.statCache || Object.create(null)
  2291. self.symlinks = options.symlinks || Object.create(null)
  2292. setupIgnores(self, options)
  2293. self.changedCwd = false
  2294. var cwd = process.cwd()
  2295. if (!ownProp(options, "cwd"))
  2296. self.cwd = cwd
  2297. else {
  2298. self.cwd = path.resolve(options.cwd)
  2299. self.changedCwd = self.cwd !== cwd
  2300. }
  2301. self.root = options.root || path.resolve(self.cwd, "/")
  2302. self.root = path.resolve(self.root)
  2303. if (process.platform === "win32")
  2304. self.root = self.root.replace(/\\/g, "/")
  2305. self.nomount = !!options.nomount
  2306. // disable comments and negation in Minimatch.
  2307. // Note that they are not supported in Glob itself anyway.
  2308. options.nonegate = true
  2309. options.nocomment = true
  2310. self.minimatch = new Minimatch(pattern, options)
  2311. self.options = self.minimatch.options
  2312. }
  2313. function finish (self) {
  2314. var nou = self.nounique
  2315. var all = nou ? [] : Object.create(null)
  2316. for (var i = 0, l = self.matches.length; i < l; i ++) {
  2317. var matches = self.matches[i]
  2318. if (!matches || Object.keys(matches).length === 0) {
  2319. if (self.nonull) {
  2320. // do like the shell, and spit out the literal glob
  2321. var literal = self.minimatch.globSet[i]
  2322. if (nou)
  2323. all.push(literal)
  2324. else
  2325. all[literal] = true
  2326. }
  2327. } else {
  2328. // had matches
  2329. var m = Object.keys(matches)
  2330. if (nou)
  2331. all.push.apply(all, m)
  2332. else
  2333. m.forEach(function (m) {
  2334. all[m] = true
  2335. })
  2336. }
  2337. }
  2338. if (!nou)
  2339. all = Object.keys(all)
  2340. if (!self.nosort)
  2341. all = all.sort(self.nocase ? alphasorti : alphasort)
  2342. // at *some* point we statted all of these
  2343. if (self.mark) {
  2344. for (var i = 0; i < all.length; i++) {
  2345. all[i] = self._mark(all[i])
  2346. }
  2347. if (self.nodir) {
  2348. all = all.filter(function (e) {
  2349. return !(/\/$/.test(e))
  2350. })
  2351. }
  2352. }
  2353. if (self.ignore.length)
  2354. all = all.filter(function(m) {
  2355. return !isIgnored(self, m)
  2356. })
  2357. self.found = all
  2358. }
  2359. function mark (self, p) {
  2360. var abs = makeAbs(self, p)
  2361. var c = self.cache[abs]
  2362. var m = p
  2363. if (c) {
  2364. var isDir = c === 'DIR' || Array.isArray(c)
  2365. var slash = p.slice(-1) === '/'
  2366. if (isDir && !slash)
  2367. m += '/'
  2368. else if (!isDir && slash)
  2369. m = m.slice(0, -1)
  2370. if (m !== p) {
  2371. var mabs = makeAbs(self, m)
  2372. self.statCache[mabs] = self.statCache[abs]
  2373. self.cache[mabs] = self.cache[abs]
  2374. }
  2375. }
  2376. return m
  2377. }
  2378. // lotta situps...
  2379. function makeAbs (self, f) {
  2380. var abs = f
  2381. if (f.charAt(0) === '/') {
  2382. abs = path.join(self.root, f)
  2383. } else if (isAbsolute(f) || f === '') {
  2384. abs = f
  2385. } else if (self.changedCwd) {
  2386. abs = path.resolve(self.cwd, f)
  2387. } else {
  2388. abs = path.resolve(f)
  2389. }
  2390. return abs
  2391. }
  2392. // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  2393. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  2394. function isIgnored (self, path) {
  2395. if (!self.ignore.length)
  2396. return false
  2397. return self.ignore.some(function(item) {
  2398. return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path))
  2399. })
  2400. }
  2401. function childrenIgnored (self, path) {
  2402. if (!self.ignore.length)
  2403. return false
  2404. return self.ignore.some(function(item) {
  2405. return !!(item.gmatcher && item.gmatcher.match(path))
  2406. })
  2407. }
  2408. /***/ },
  2409. /* 15 */
  2410. /***/ function(module, exports, __webpack_require__) {
  2411. var wrappy = __webpack_require__(16)
  2412. var reqs = Object.create(null)
  2413. var once = __webpack_require__(17)
  2414. module.exports = wrappy(inflight)
  2415. function inflight (key, cb) {
  2416. if (reqs[key]) {
  2417. reqs[key].push(cb)
  2418. return null
  2419. } else {
  2420. reqs[key] = [cb]
  2421. return makeres(key)
  2422. }
  2423. }
  2424. function makeres (key) {
  2425. return once(function RES () {
  2426. var cbs = reqs[key]
  2427. var len = cbs.length
  2428. var args = slice(arguments)
  2429. for (var i = 0; i < len; i++) {
  2430. cbs[i].apply(null, args)
  2431. }
  2432. if (cbs.length > len) {
  2433. // added more in the interim.
  2434. // de-zalgo, just in case, but don't call again.
  2435. cbs.splice(0, len)
  2436. process.nextTick(function () {
  2437. RES.apply(null, args)
  2438. })
  2439. } else {
  2440. delete reqs[key]
  2441. }
  2442. })
  2443. }
  2444. function slice (args) {
  2445. var length = args.length
  2446. var array = []
  2447. for (var i = 0; i < length; i++) array[i] = args[i]
  2448. return array
  2449. }
  2450. /***/ },
  2451. /* 16 */
  2452. /***/ function(module, exports) {
  2453. // Returns a wrapper function that returns a wrapped callback
  2454. // The wrapper function should do some stuff, and return a
  2455. // presumably different callback function.
  2456. // This makes sure that own properties are retained, so that
  2457. // decorations and such are not lost along the way.
  2458. module.exports = wrappy
  2459. function wrappy (fn, cb) {
  2460. if (fn && cb) return wrappy(fn)(cb)
  2461. if (typeof fn !== 'function')
  2462. throw new TypeError('need wrapper function')
  2463. Object.keys(fn).forEach(function (k) {
  2464. wrapper[k] = fn[k]
  2465. })
  2466. return wrapper
  2467. function wrapper() {
  2468. var args = new Array(arguments.length)
  2469. for (var i = 0; i < args.length; i++) {
  2470. args[i] = arguments[i]
  2471. }
  2472. var ret = fn.apply(this, args)
  2473. var cb = args[args.length-1]
  2474. if (typeof ret === 'function' && ret !== cb) {
  2475. Object.keys(cb).forEach(function (k) {
  2476. ret[k] = cb[k]
  2477. })
  2478. }
  2479. return ret
  2480. }
  2481. }
  2482. /***/ },
  2483. /* 17 */
  2484. /***/ function(module, exports, __webpack_require__) {
  2485. var wrappy = __webpack_require__(16)
  2486. module.exports = wrappy(once)
  2487. once.proto = once(function () {
  2488. Object.defineProperty(Function.prototype, 'once', {
  2489. value: function () {
  2490. return once(this)
  2491. },
  2492. configurable: true
  2493. })
  2494. })
  2495. function once (fn) {
  2496. var f = function () {
  2497. if (f.called) return f.value
  2498. f.called = true
  2499. return f.value = fn.apply(this, arguments)
  2500. }
  2501. f.called = false
  2502. return f
  2503. }
  2504. /***/ },
  2505. /* 18 */
  2506. /***/ function(module, exports, __webpack_require__) {
  2507. var assign = __webpack_require__(19)
  2508. var fse = {}
  2509. var gfs = __webpack_require__(20)
  2510. // attach fs methods to fse
  2511. Object.keys(gfs).forEach(function (key) {
  2512. fse[key] = gfs[key]
  2513. })
  2514. var fs = fse
  2515. assign(fs, __webpack_require__(26))
  2516. assign(fs, __webpack_require__(34))
  2517. assign(fs, __webpack_require__(31))
  2518. assign(fs, __webpack_require__(37))
  2519. assign(fs, __webpack_require__(44))
  2520. assign(fs, __webpack_require__(49))
  2521. assign(fs, __webpack_require__(50))
  2522. assign(fs, __webpack_require__(52))
  2523. assign(fs, __webpack_require__(53))
  2524. assign(fs, __webpack_require__(59))
  2525. assign(fs, __webpack_require__(60))
  2526. module.exports = fs
  2527. // maintain backwards compatibility for awhile
  2528. var jsonfile = {}
  2529. Object.defineProperty(jsonfile, 'spaces', {
  2530. get: function () {
  2531. return fs.spaces // found in ./json
  2532. },
  2533. set: function (val) {
  2534. fs.spaces = val
  2535. }
  2536. })
  2537. module.exports.jsonfile = jsonfile // so users of fs-extra can modify jsonFile.spaces
  2538. /***/ },
  2539. /* 19 */
  2540. /***/ function(module, exports) {
  2541. // simple mutable assign
  2542. function assign () {
  2543. var args = [].slice.call(arguments).filter(function (i) { return i })
  2544. var dest = args.shift()
  2545. args.forEach(function (src) {
  2546. Object.keys(src).forEach(function (key) {
  2547. dest[key] = src[key]
  2548. })
  2549. })
  2550. return dest
  2551. }
  2552. module.exports = assign
  2553. /***/ },
  2554. /* 20 */
  2555. /***/ function(module, exports, __webpack_require__) {
  2556. var fs = __webpack_require__(2)
  2557. var polyfills = __webpack_require__(21)
  2558. var legacy = __webpack_require__(24)
  2559. var queue = []
  2560. var util = __webpack_require__(9)
  2561. function noop () {}
  2562. var debug = noop
  2563. if (util.debuglog)
  2564. debug = util.debuglog('gfs4')
  2565. else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
  2566. debug = function() {
  2567. var m = util.format.apply(util, arguments)
  2568. m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ')
  2569. console.error(m)
  2570. }
  2571. if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
  2572. process.on('exit', function() {
  2573. debug(queue)
  2574. __webpack_require__(11).equal(queue.length, 0)
  2575. })
  2576. }
  2577. module.exports = patch(__webpack_require__(22))
  2578. if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH) {
  2579. module.exports = patch(fs)
  2580. }
  2581. // Always patch fs.close/closeSync, because we want to
  2582. // retry() whenever a close happens *anywhere* in the program.
  2583. // This is essential when multiple graceful-fs instances are
  2584. // in play at the same time.
  2585. module.exports.close =
  2586. fs.close = (function (fs$close) { return function (fd, cb) {
  2587. return fs$close.call(fs, fd, function (err) {
  2588. if (!err)
  2589. retry()
  2590. if (typeof cb === 'function')
  2591. cb.apply(this, arguments)
  2592. })
  2593. }})(fs.close)
  2594. module.exports.closeSync =
  2595. fs.closeSync = (function (fs$closeSync) { return function (fd) {
  2596. // Note that graceful-fs also retries when fs.closeSync() fails.
  2597. // Looks like a bug to me, although it's probably a harmless one.
  2598. var rval = fs$closeSync.apply(fs, arguments)
  2599. retry()
  2600. return rval
  2601. }})(fs.closeSync)
  2602. function patch (fs) {
  2603. // Everything that references the open() function needs to be in here
  2604. polyfills(fs)
  2605. fs.gracefulify = patch
  2606. fs.FileReadStream = ReadStream; // Legacy name.
  2607. fs.FileWriteStream = WriteStream; // Legacy name.
  2608. fs.createReadStream = createReadStream
  2609. fs.createWriteStream = createWriteStream
  2610. var fs$readFile = fs.readFile
  2611. fs.readFile = readFile
  2612. function readFile (path, options, cb) {
  2613. if (typeof options === 'function')
  2614. cb = options, options = null
  2615. return go$readFile(path, options, cb)
  2616. function go$readFile (path, options, cb) {
  2617. return fs$readFile(path, options, function (err) {
  2618. if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
  2619. enqueue([go$readFile, [path, options, cb]])
  2620. else {
  2621. if (typeof cb === 'function')
  2622. cb.apply(this, arguments)
  2623. retry()
  2624. }
  2625. })
  2626. }
  2627. }
  2628. var fs$writeFile = fs.writeFile
  2629. fs.writeFile = writeFile
  2630. function writeFile (path, data, options, cb) {
  2631. if (typeof options === 'function')
  2632. cb = options, options = null
  2633. return go$writeFile(path, data, options, cb)
  2634. function go$writeFile (path, data, options, cb) {
  2635. return fs$writeFile(path, data, options, function (err) {
  2636. if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
  2637. enqueue([go$writeFile, [path, data, options, cb]])
  2638. else {
  2639. if (typeof cb === 'function')
  2640. cb.apply(this, arguments)
  2641. retry()
  2642. }
  2643. })
  2644. }
  2645. }
  2646. var fs$appendFile = fs.appendFile
  2647. if (fs$appendFile)
  2648. fs.appendFile = appendFile
  2649. function appendFile (path, data, options, cb) {
  2650. if (typeof options === 'function')
  2651. cb = options, options = null
  2652. return go$appendFile(path, data, options, cb)
  2653. function go$appendFile (path, data, options, cb) {
  2654. return fs$appendFile(path, data, options, function (err) {
  2655. if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
  2656. enqueue([go$appendFile, [path, data, options, cb]])
  2657. else {
  2658. if (typeof cb === 'function')
  2659. cb.apply(this, arguments)
  2660. retry()
  2661. }
  2662. })
  2663. }
  2664. }
  2665. var fs$readdir = fs.readdir
  2666. fs.readdir = readdir
  2667. function readdir (path, cb) {
  2668. return go$readdir(path, cb)
  2669. function go$readdir () {
  2670. return fs$readdir(path, function (err, files) {
  2671. if (files && files.sort)
  2672. files.sort(); // Backwards compatibility with graceful-fs.
  2673. if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
  2674. enqueue([go$readdir, [path, cb]])
  2675. else {
  2676. if (typeof cb === 'function')
  2677. cb.apply(this, arguments)
  2678. retry()
  2679. }
  2680. })
  2681. }
  2682. }
  2683. if (process.version.substr(0, 4) === 'v0.8') {
  2684. var legStreams = legacy(fs)
  2685. ReadStream = legStreams.ReadStream
  2686. WriteStream = legStreams.WriteStream
  2687. }
  2688. var fs$ReadStream = fs.ReadStream
  2689. ReadStream.prototype = Object.create(fs$ReadStream.prototype)
  2690. ReadStream.prototype.open = ReadStream$open
  2691. var fs$WriteStream = fs.WriteStream
  2692. WriteStream.prototype = Object.create(fs$WriteStream.prototype)
  2693. WriteStream.prototype.open = WriteStream$open
  2694. fs.ReadStream = ReadStream
  2695. fs.WriteStream = WriteStream
  2696. function ReadStream (path, options) {
  2697. if (this instanceof ReadStream)
  2698. return fs$ReadStream.apply(this, arguments), this
  2699. else
  2700. return ReadStream.apply(Object.create(ReadStream.prototype), arguments)
  2701. }
  2702. function ReadStream$open () {
  2703. var that = this
  2704. open(that.path, that.flags, that.mode, function (err, fd) {
  2705. if (err) {
  2706. if (that.autoClose)
  2707. that.destroy()
  2708. that.emit('error', err)
  2709. } else {
  2710. that.fd = fd
  2711. that.emit('open', fd)
  2712. that.read()
  2713. }
  2714. })
  2715. }
  2716. function WriteStream (path, options) {
  2717. if (this instanceof WriteStream)
  2718. return fs$WriteStream.apply(this, arguments), this
  2719. else
  2720. return WriteStream.apply(Object.create(WriteStream.prototype), arguments)
  2721. }
  2722. function WriteStream$open () {
  2723. var that = this
  2724. open(that.path, that.flags, that.mode, function (err, fd) {
  2725. if (err) {
  2726. that.destroy()
  2727. that.emit('error', err)
  2728. } else {
  2729. that.fd = fd
  2730. that.emit('open', fd)
  2731. }
  2732. })
  2733. }
  2734. function createReadStream (path, options) {
  2735. return new ReadStream(path, options)
  2736. }
  2737. function createWriteStream (path, options) {
  2738. return new WriteStream(path, options)
  2739. }
  2740. var fs$open = fs.open
  2741. fs.open = open
  2742. function open (path, flags, mode, cb) {
  2743. if (typeof mode === 'function')
  2744. cb = mode, mode = null
  2745. return go$open(path, flags, mode, cb)
  2746. function go$open (path, flags, mode, cb) {
  2747. return fs$open(path, flags, mode, function (err, fd) {
  2748. if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
  2749. enqueue([go$open, [path, flags, mode, cb]])
  2750. else {
  2751. if (typeof cb === 'function')
  2752. cb.apply(this, arguments)
  2753. retry()
  2754. }
  2755. })
  2756. }
  2757. }
  2758. return fs
  2759. }
  2760. function enqueue (elem) {
  2761. debug('ENQUEUE', elem[0].name, elem[1])
  2762. queue.push(elem)
  2763. }
  2764. function retry () {
  2765. var elem = queue.shift()
  2766. if (elem) {
  2767. debug('RETRY', elem[0].name, elem[1])
  2768. elem[0].apply(null, elem[1])
  2769. }
  2770. }
  2771. /***/ },
  2772. /* 21 */
  2773. /***/ function(module, exports, __webpack_require__) {
  2774. var fs = __webpack_require__(22)
  2775. var constants = __webpack_require__(23)
  2776. var origCwd = process.cwd
  2777. var cwd = null
  2778. process.cwd = function() {
  2779. if (!cwd)
  2780. cwd = origCwd.call(process)
  2781. return cwd
  2782. }
  2783. try {
  2784. process.cwd()
  2785. } catch (er) {}
  2786. var chdir = process.chdir
  2787. process.chdir = function(d) {
  2788. cwd = null
  2789. chdir.call(process, d)
  2790. }
  2791. module.exports = patch
  2792. function patch (fs) {
  2793. // (re-)implement some things that are known busted or missing.
  2794. // lchmod, broken prior to 0.6.2
  2795. // back-port the fix here.
  2796. if (constants.hasOwnProperty('O_SYMLINK') &&
  2797. process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
  2798. patchLchmod(fs)
  2799. }
  2800. // lutimes implementation, or no-op
  2801. if (!fs.lutimes) {
  2802. patchLutimes(fs)
  2803. }
  2804. // https://github.com/isaacs/node-graceful-fs/issues/4
  2805. // Chown should not fail on einval or eperm if non-root.
  2806. // It should not fail on enosys ever, as this just indicates
  2807. // that a fs doesn't support the intended operation.
  2808. fs.chown = chownFix(fs.chown)
  2809. fs.fchown = chownFix(fs.fchown)
  2810. fs.lchown = chownFix(fs.lchown)
  2811. fs.chmod = chownFix(fs.chmod)
  2812. fs.fchmod = chownFix(fs.fchmod)
  2813. fs.lchmod = chownFix(fs.lchmod)
  2814. fs.chownSync = chownFixSync(fs.chownSync)
  2815. fs.fchownSync = chownFixSync(fs.fchownSync)
  2816. fs.lchownSync = chownFixSync(fs.lchownSync)
  2817. fs.chmodSync = chownFix(fs.chmodSync)
  2818. fs.fchmodSync = chownFix(fs.fchmodSync)
  2819. fs.lchmodSync = chownFix(fs.lchmodSync)
  2820. // if lchmod/lchown do not exist, then make them no-ops
  2821. if (!fs.lchmod) {
  2822. fs.lchmod = function (path, mode, cb) {
  2823. process.nextTick(cb)
  2824. }
  2825. fs.lchmodSync = function () {}
  2826. }
  2827. if (!fs.lchown) {
  2828. fs.lchown = function (path, uid, gid, cb) {
  2829. process.nextTick(cb)
  2830. }
  2831. fs.lchownSync = function () {}
  2832. }
  2833. // on Windows, A/V software can lock the directory, causing this
  2834. // to fail with an EACCES or EPERM if the directory contains newly
  2835. // created files. Try again on failure, for up to 1 second.
  2836. if (process.platform === "win32") {
  2837. fs.rename = (function (fs$rename) { return function (from, to, cb) {
  2838. var start = Date.now()
  2839. fs$rename(from, to, function CB (er) {
  2840. if (er
  2841. && (er.code === "EACCES" || er.code === "EPERM")
  2842. && Date.now() - start < 1000) {
  2843. return fs$rename(from, to, CB)
  2844. }
  2845. if (cb) cb(er)
  2846. })
  2847. }})(fs.rename)
  2848. }
  2849. // if read() returns EAGAIN, then just try it again.
  2850. fs.read = (function (fs$read) { return function (fd, buffer, offset, length, position, callback_) {
  2851. var callback
  2852. if (callback_ && typeof callback_ === 'function') {
  2853. var eagCounter = 0
  2854. callback = function (er, _, __) {
  2855. if (er && er.code === 'EAGAIN' && eagCounter < 10) {
  2856. eagCounter ++
  2857. return fs$read.call(fs, fd, buffer, offset, length, position, callback)
  2858. }
  2859. callback_.apply(this, arguments)
  2860. }
  2861. }
  2862. return fs$read.call(fs, fd, buffer, offset, length, position, callback)
  2863. }})(fs.read)
  2864. fs.readSync = (function (fs$readSync) { return function (fd, buffer, offset, length, position) {
  2865. var eagCounter = 0
  2866. while (true) {
  2867. try {
  2868. return fs$readSync.call(fs, fd, buffer, offset, length, position)
  2869. } catch (er) {
  2870. if (er.code === 'EAGAIN' && eagCounter < 10) {
  2871. eagCounter ++
  2872. continue
  2873. }
  2874. throw er
  2875. }
  2876. }
  2877. }})(fs.readSync)
  2878. }
  2879. function patchLchmod (fs) {
  2880. fs.lchmod = function (path, mode, callback) {
  2881. callback = callback || noop
  2882. fs.open( path
  2883. , constants.O_WRONLY | constants.O_SYMLINK
  2884. , mode
  2885. , function (err, fd) {
  2886. if (err) {
  2887. callback(err)
  2888. return
  2889. }
  2890. // prefer to return the chmod error, if one occurs,
  2891. // but still try to close, and report closing errors if they occur.
  2892. fs.fchmod(fd, mode, function (err) {
  2893. fs.close(fd, function(err2) {
  2894. callback(err || err2)
  2895. })
  2896. })
  2897. })
  2898. }
  2899. fs.lchmodSync = function (path, mode) {
  2900. var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode)
  2901. // prefer to return the chmod error, if one occurs,
  2902. // but still try to close, and report closing errors if they occur.
  2903. var threw = true
  2904. var ret
  2905. try {
  2906. ret = fs.fchmodSync(fd, mode)
  2907. threw = false
  2908. } finally {
  2909. if (threw) {
  2910. try {
  2911. fs.closeSync(fd)
  2912. } catch (er) {}
  2913. } else {
  2914. fs.closeSync(fd)
  2915. }
  2916. }
  2917. return ret
  2918. }
  2919. }
  2920. function patchLutimes (fs) {
  2921. if (constants.hasOwnProperty("O_SYMLINK")) {
  2922. fs.lutimes = function (path, at, mt, cb) {
  2923. fs.open(path, constants.O_SYMLINK, function (er, fd) {
  2924. cb = cb || noop
  2925. if (er) return cb(er)
  2926. fs.futimes(fd, at, mt, function (er) {
  2927. fs.close(fd, function (er2) {
  2928. return cb(er || er2)
  2929. })
  2930. })
  2931. })
  2932. }
  2933. fs.lutimesSync = function (path, at, mt) {
  2934. var fd = fs.openSync(path, constants.O_SYMLINK)
  2935. var ret
  2936. var threw = true
  2937. try {
  2938. ret = fs.futimesSync(fd, at, mt)
  2939. threw = false
  2940. } finally {
  2941. if (threw) {
  2942. try {
  2943. fs.closeSync(fd)
  2944. } catch (er) {}
  2945. } else {
  2946. fs.closeSync(fd)
  2947. }
  2948. }
  2949. return ret
  2950. }
  2951. } else {
  2952. fs.lutimes = function (_a, _b, _c, cb) { process.nextTick(cb) }
  2953. fs.lutimesSync = function () {}
  2954. }
  2955. }
  2956. function chownFix (orig) {
  2957. if (!orig) return orig
  2958. return function (target, uid, gid, cb) {
  2959. return orig.call(fs, target, uid, gid, function (er, res) {
  2960. if (chownErOk(er)) er = null
  2961. cb(er, res)
  2962. })
  2963. }
  2964. }
  2965. function chownFixSync (orig) {
  2966. if (!orig) return orig
  2967. return function (target, uid, gid) {
  2968. try {
  2969. return orig.call(fs, target, uid, gid)
  2970. } catch (er) {
  2971. if (!chownErOk(er)) throw er
  2972. }
  2973. }
  2974. }
  2975. // ENOSYS means that the fs doesn't support the op. Just ignore
  2976. // that, because it doesn't matter.
  2977. //
  2978. // if there's no getuid, or if getuid() is something other
  2979. // than 0, and the error is EINVAL or EPERM, then just ignore
  2980. // it.
  2981. //
  2982. // This specific case is a silent failure in cp, install, tar,
  2983. // and most other unix tools that manage permissions.
  2984. //
  2985. // When running as root, or if other types of errors are
  2986. // encountered, then it's strict.
  2987. function chownErOk (er) {
  2988. if (!er)
  2989. return true
  2990. if (er.code === "ENOSYS")
  2991. return true
  2992. var nonroot = !process.getuid || process.getuid() !== 0
  2993. if (nonroot) {
  2994. if (er.code === "EINVAL" || er.code === "EPERM")
  2995. return true
  2996. }
  2997. return false
  2998. }
  2999. /***/ },
  3000. /* 22 */
  3001. /***/ function(module, exports, __webpack_require__) {
  3002. 'use strict'
  3003. var fs = __webpack_require__(2)
  3004. module.exports = clone(fs)
  3005. function clone (obj) {
  3006. if (obj === null || typeof obj !== 'object')
  3007. return obj
  3008. if (obj instanceof Object)
  3009. var copy = { __proto__: obj.__proto__ }
  3010. else
  3011. var copy = Object.create(null)
  3012. Object.getOwnPropertyNames(obj).forEach(function (key) {
  3013. Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
  3014. })
  3015. return copy
  3016. }
  3017. /***/ },
  3018. /* 23 */
  3019. /***/ function(module, exports) {
  3020. module.exports = require("constants");
  3021. /***/ },
  3022. /* 24 */
  3023. /***/ function(module, exports, __webpack_require__) {
  3024. var Stream = __webpack_require__(25).Stream
  3025. module.exports = legacy
  3026. function legacy (fs) {
  3027. return {
  3028. ReadStream: ReadStream,
  3029. WriteStream: WriteStream
  3030. }
  3031. function ReadStream (path, options) {
  3032. if (!(this instanceof ReadStream)) return new ReadStream(path, options);
  3033. Stream.call(this);
  3034. var self = this;
  3035. this.path = path;
  3036. this.fd = null;
  3037. this.readable = true;
  3038. this.paused = false;
  3039. this.flags = 'r';
  3040. this.mode = 438; /*=0666*/
  3041. this.bufferSize = 64 * 1024;
  3042. options = options || {};
  3043. // Mixin options into this
  3044. var keys = Object.keys(options);
  3045. for (var index = 0, length = keys.length; index < length; index++) {
  3046. var key = keys[index];
  3047. this[key] = options[key];
  3048. }
  3049. if (this.encoding) this.setEncoding(this.encoding);
  3050. if (this.start !== undefined) {
  3051. if ('number' !== typeof this.start) {
  3052. throw TypeError('start must be a Number');
  3053. }
  3054. if (this.end === undefined) {
  3055. this.end = Infinity;
  3056. } else if ('number' !== typeof this.end) {
  3057. throw TypeError('end must be a Number');
  3058. }
  3059. if (this.start > this.end) {
  3060. throw new Error('start must be <= end');
  3061. }
  3062. this.pos = this.start;
  3063. }
  3064. if (this.fd !== null) {
  3065. process.nextTick(function() {
  3066. self._read();
  3067. });
  3068. return;
  3069. }
  3070. fs.open(this.path, this.flags, this.mode, function (err, fd) {
  3071. if (err) {
  3072. self.emit('error', err);
  3073. self.readable = false;
  3074. return;
  3075. }
  3076. self.fd = fd;
  3077. self.emit('open', fd);
  3078. self._read();
  3079. })
  3080. }
  3081. function WriteStream (path, options) {
  3082. if (!(this instanceof WriteStream)) return new WriteStream(path, options);
  3083. Stream.call(this);
  3084. this.path = path;
  3085. this.fd = null;
  3086. this.writable = true;
  3087. this.flags = 'w';
  3088. this.encoding = 'binary';
  3089. this.mode = 438; /*=0666*/
  3090. this.bytesWritten = 0;
  3091. options = options || {};
  3092. // Mixin options into this
  3093. var keys = Object.keys(options);
  3094. for (var index = 0, length = keys.length; index < length; index++) {
  3095. var key = keys[index];
  3096. this[key] = options[key];
  3097. }
  3098. if (this.start !== undefined) {
  3099. if ('number' !== typeof this.start) {
  3100. throw TypeError('start must be a Number');
  3101. }
  3102. if (this.start < 0) {
  3103. throw new Error('start must be >= zero');
  3104. }
  3105. this.pos = this.start;
  3106. }
  3107. this.busy = false;
  3108. this._queue = [];
  3109. if (this.fd === null) {
  3110. this._open = fs.open;
  3111. this._queue.push([this._open, this.path, this.flags, this.mode, undefined]);
  3112. this.flush();
  3113. }
  3114. }
  3115. }
  3116. /***/ },
  3117. /* 25 */
  3118. /***/ function(module, exports) {
  3119. module.exports = require("stream");
  3120. /***/ },
  3121. /* 26 */
  3122. /***/ function(module, exports, __webpack_require__) {
  3123. module.exports = {
  3124. copy: __webpack_require__(27)
  3125. }
  3126. /***/ },
  3127. /* 27 */
  3128. /***/ function(module, exports, __webpack_require__) {
  3129. var fs = __webpack_require__(20)
  3130. var path = __webpack_require__(4)
  3131. var ncp = __webpack_require__(28)
  3132. var mkdir = __webpack_require__(31)
  3133. function copy (src, dest, options, callback) {
  3134. if (typeof options === 'function' && !callback) {
  3135. callback = options
  3136. options = {}
  3137. } else if (typeof options === 'function' || options instanceof RegExp) {
  3138. options = {filter: options}
  3139. }
  3140. callback = callback || function () {}
  3141. options = options || {}
  3142. fs.lstat(src, function (err, stats) {
  3143. if (err) return callback(err)
  3144. var dir = null
  3145. if (stats.isDirectory()) {
  3146. var parts = dest.split(path.sep)
  3147. parts.pop()
  3148. dir = parts.join(path.sep)
  3149. } else {
  3150. dir = path.dirname(dest)
  3151. }
  3152. fs.exists(dir, function (dirExists) {
  3153. if (dirExists) return ncp(src, dest, options, callback)
  3154. mkdir.mkdirs(dir, function (err) {
  3155. if (err) return callback(err)
  3156. ncp(src, dest, options, callback)
  3157. })
  3158. })
  3159. })
  3160. }
  3161. module.exports = copy
  3162. /***/ },
  3163. /* 28 */
  3164. /***/ function(module, exports, __webpack_require__) {
  3165. // imported from ncp (this is temporary, will rewrite)
  3166. var fs = __webpack_require__(20)
  3167. var path = __webpack_require__(4)
  3168. var utimes = __webpack_require__(29)
  3169. function ncp (source, dest, options, callback) {
  3170. if (!callback) {
  3171. callback = options
  3172. options = {}
  3173. }
  3174. var basePath = process.cwd()
  3175. var currentPath = path.resolve(basePath, source)
  3176. var targetPath = path.resolve(basePath, dest)
  3177. var filter = options.filter
  3178. var transform = options.transform
  3179. var clobber = options.clobber !== false
  3180. var dereference = options.dereference
  3181. var preserveTimestamps = options.preserveTimestamps === true
  3182. var errs = null
  3183. var started = 0
  3184. var finished = 0
  3185. var running = 0
  3186. // this is pretty useless now that we're using graceful-fs
  3187. // consider removing
  3188. var limit = options.limit || 512
  3189. startCopy(currentPath)
  3190. function startCopy (source) {
  3191. started++
  3192. if (filter) {
  3193. if (filter instanceof RegExp) {
  3194. if (!filter.test(source)) {
  3195. return doneOne(true)
  3196. }
  3197. } else if (typeof filter === 'function') {
  3198. if (!filter(source)) {
  3199. return doneOne(true)
  3200. }
  3201. }
  3202. }
  3203. return getStats(source)
  3204. }
  3205. function getStats (source) {
  3206. var stat = dereference ? fs.stat : fs.lstat
  3207. if (running >= limit) {
  3208. return setImmediate(function () {
  3209. getStats(source)
  3210. })
  3211. }
  3212. running++
  3213. stat(source, function (err, stats) {
  3214. if (err) return onError(err)
  3215. // We need to get the mode from the stats object and preserve it.
  3216. var item = {
  3217. name: source,
  3218. mode: stats.mode,
  3219. mtime: stats.mtime, // modified time
  3220. atime: stats.atime, // access time
  3221. stats: stats // temporary
  3222. }
  3223. if (stats.isDirectory()) {
  3224. return onDir(item)
  3225. } else if (stats.isFile() || stats.isCharacterDevice() || stats.isBlockDevice()) {
  3226. return onFile(item)
  3227. } else if (stats.isSymbolicLink()) {
  3228. // Symlinks don't really need to know about the mode.
  3229. return onLink(source)
  3230. }
  3231. })
  3232. }
  3233. function onFile (file) {
  3234. var target = file.name.replace(currentPath, targetPath)
  3235. isWritable(target, function (writable) {
  3236. if (writable) {
  3237. copyFile(file, target)
  3238. } else {
  3239. if (clobber) {
  3240. rmFile(target, function () {
  3241. copyFile(file, target)
  3242. })
  3243. } else {
  3244. doneOne()
  3245. }
  3246. }
  3247. })
  3248. }
  3249. function copyFile (file, target) {
  3250. var readStream = fs.createReadStream(file.name)
  3251. var writeStream = fs.createWriteStream(target, { mode: file.mode })
  3252. readStream.on('error', onError)
  3253. writeStream.on('error', onError)
  3254. if (transform) {
  3255. transform(readStream, writeStream, file)
  3256. } else {
  3257. writeStream.on('open', function () {
  3258. readStream.pipe(writeStream)
  3259. })
  3260. }
  3261. writeStream.once('finish', function () {
  3262. fs.chmod(target, file.mode, function (err) {
  3263. if (err) return onError(err)
  3264. if (preserveTimestamps) {
  3265. utimes.utimesMillis(target, file.atime, file.mtime, function (err) {
  3266. if (err) return onError(err)
  3267. return doneOne()
  3268. })
  3269. } else {
  3270. doneOne()
  3271. }
  3272. })
  3273. })
  3274. }
  3275. function rmFile (file, done) {
  3276. fs.unlink(file, function (err) {
  3277. if (err) return onError(err)
  3278. return done()
  3279. })
  3280. }
  3281. function onDir (dir) {
  3282. var target = dir.name.replace(currentPath, targetPath)
  3283. isWritable(target, function (writable) {
  3284. if (writable) {
  3285. return mkDir(dir, target)
  3286. }
  3287. copyDir(dir.name)
  3288. })
  3289. }
  3290. function mkDir (dir, target) {
  3291. fs.mkdir(target, dir.mode, function (err) {
  3292. if (err) return onError(err)
  3293. // despite setting mode in fs.mkdir, doesn't seem to work
  3294. // so we set it here.
  3295. fs.chmod(target, dir.mode, function (err) {
  3296. if (err) return onError(err)
  3297. copyDir(dir.name)
  3298. })
  3299. })
  3300. }
  3301. function copyDir (dir) {
  3302. fs.readdir(dir, function (err, items) {
  3303. if (err) return onError(err)
  3304. items.forEach(function (item) {
  3305. startCopy(path.join(dir, item))
  3306. })
  3307. return doneOne()
  3308. })
  3309. }
  3310. function onLink (link) {
  3311. var target = link.replace(currentPath, targetPath)
  3312. fs.readlink(link, function (err, resolvedPath) {
  3313. if (err) return onError(err)
  3314. checkLink(resolvedPath, target)
  3315. })
  3316. }
  3317. function checkLink (resolvedPath, target) {
  3318. if (dereference) {
  3319. resolvedPath = path.resolve(basePath, resolvedPath)
  3320. }
  3321. isWritable(target, function (writable) {
  3322. if (writable) {
  3323. return makeLink(resolvedPath, target)
  3324. }
  3325. fs.readlink(target, function (err, targetDest) {
  3326. if (err) return onError(err)
  3327. if (dereference) {
  3328. targetDest = path.resolve(basePath, targetDest)
  3329. }
  3330. if (targetDest === resolvedPath) {
  3331. return doneOne()
  3332. }
  3333. return rmFile(target, function () {
  3334. makeLink(resolvedPath, target)
  3335. })
  3336. })
  3337. })
  3338. }
  3339. function makeLink (linkPath, target) {
  3340. fs.symlink(linkPath, target, function (err) {
  3341. if (err) return onError(err)
  3342. return doneOne()
  3343. })
  3344. }
  3345. function isWritable (path, done) {
  3346. fs.lstat(path, function (err) {
  3347. if (err) {
  3348. if (err.code === 'ENOENT') return done(true)
  3349. return done(false)
  3350. }
  3351. return done(false)
  3352. })
  3353. }
  3354. function onError (err) {
  3355. if (options.stopOnError) {
  3356. return callback(err)
  3357. } else if (!errs && options.errs) {
  3358. errs = fs.createWriteStream(options.errs)
  3359. } else if (!errs) {
  3360. errs = []
  3361. }
  3362. if (typeof errs.write === 'undefined') {
  3363. errs.push(err)
  3364. } else {
  3365. errs.write(err.stack + '\n\n')
  3366. }
  3367. return doneOne()
  3368. }
  3369. function doneOne (skipped) {
  3370. if (!skipped) running--
  3371. finished++
  3372. if ((started === finished) && (running === 0)) {
  3373. if (callback !== undefined) {
  3374. return errs ? callback(errs) : callback(null)
  3375. }
  3376. }
  3377. }
  3378. }
  3379. module.exports = ncp
  3380. /***/ },
  3381. /* 29 */
  3382. /***/ function(module, exports, __webpack_require__) {
  3383. var fs = __webpack_require__(20)
  3384. var path = __webpack_require__(4)
  3385. var os = __webpack_require__(30)
  3386. // HFS, ext{2,3}, FAT do not, Node.js v0.10 does not
  3387. function hasMillisResSync () {
  3388. var tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2))
  3389. tmpfile = path.join(os.tmpdir(), tmpfile)
  3390. // 550 millis past UNIX epoch
  3391. var d = new Date(1435410243862)
  3392. fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
  3393. var fd = fs.openSync(tmpfile, 'r+')
  3394. fs.futimesSync(fd, d, d)
  3395. fs.closeSync(fd)
  3396. return fs.statSync(tmpfile).mtime > 1435410243000
  3397. }
  3398. function hasMillisRes (callback) {
  3399. var tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2))
  3400. tmpfile = path.join(os.tmpdir(), tmpfile)
  3401. // 550 millis past UNIX epoch
  3402. var d = new Date(1435410243862)
  3403. fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', function (err) {
  3404. if (err) return callback(err)
  3405. fs.open(tmpfile, 'r+', function (err, fd) {
  3406. if (err) return callback(err)
  3407. fs.futimes(fd, d, d, function (err) {
  3408. if (err) return callback(err)
  3409. fs.close(fd, function (err) {
  3410. if (err) return callback(err)
  3411. fs.stat(tmpfile, function (err, stats) {
  3412. if (err) return callback(err)
  3413. callback(null, stats.mtime > 1435410243000)
  3414. })
  3415. })
  3416. })
  3417. })
  3418. })
  3419. }
  3420. function timeRemoveMillis (timestamp) {
  3421. if (typeof timestamp === 'number') {
  3422. return Math.floor(timestamp / 1000) * 1000
  3423. } else if (timestamp instanceof Date) {
  3424. return new Date(Math.floor(timestamp.getTime() / 1000) * 1000)
  3425. } else {
  3426. throw new Error('fs-extra: timeRemoveMillis() unknown parameter type')
  3427. }
  3428. }
  3429. function utimesMillis (path, atime, mtime, callback) {
  3430. // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
  3431. fs.open(path, 'r+', function (err, fd) {
  3432. if (err) return callback(err)
  3433. fs.futimes(fd, atime, mtime, function (err) {
  3434. if (err) return callback(err)
  3435. fs.close(fd, callback)
  3436. })
  3437. })
  3438. }
  3439. module.exports = {
  3440. hasMillisRes: hasMillisRes,
  3441. hasMillisResSync: hasMillisResSync,
  3442. timeRemoveMillis: timeRemoveMillis,
  3443. utimesMillis: utimesMillis
  3444. }
  3445. /***/ },
  3446. /* 30 */
  3447. /***/ function(module, exports) {
  3448. module.exports = require("os");
  3449. /***/ },
  3450. /* 31 */
  3451. /***/ function(module, exports, __webpack_require__) {
  3452. module.exports = {
  3453. mkdirs: __webpack_require__(32),
  3454. mkdirsSync: __webpack_require__(33),
  3455. // alias
  3456. mkdirp: __webpack_require__(32),
  3457. mkdirpSync: __webpack_require__(33),
  3458. ensureDir: __webpack_require__(32),
  3459. ensureDirSync: __webpack_require__(33)
  3460. }
  3461. /***/ },
  3462. /* 32 */
  3463. /***/ function(module, exports, __webpack_require__) {
  3464. var fs = __webpack_require__(20)
  3465. var path = __webpack_require__(4)
  3466. var o777 = parseInt('0777', 8)
  3467. function mkdirs (p, opts, callback, made) {
  3468. if (typeof opts === 'function') {
  3469. callback = opts
  3470. opts = {}
  3471. } else if (!opts || typeof opts !== 'object') {
  3472. opts = { mode: opts }
  3473. }
  3474. var mode = opts.mode
  3475. var xfs = opts.fs || fs
  3476. if (mode === undefined) {
  3477. mode = o777 & (~process.umask())
  3478. }
  3479. if (!made) made = null
  3480. callback = callback || function () {}
  3481. p = path.resolve(p)
  3482. xfs.mkdir(p, mode, function (er) {
  3483. if (!er) {
  3484. made = made || p
  3485. return callback(null, made)
  3486. }
  3487. switch (er.code) {
  3488. case 'ENOENT':
  3489. if (path.dirname(p) === p) return callback(er)
  3490. mkdirs(path.dirname(p), opts, function (er, made) {
  3491. if (er) callback(er, made)
  3492. else mkdirs(p, opts, callback, made)
  3493. })
  3494. break
  3495. // In the case of any other error, just see if there's a dir
  3496. // there already. If so, then hooray! If not, then something
  3497. // is borked.
  3498. default:
  3499. xfs.stat(p, function (er2, stat) {
  3500. // if the stat fails, then that's super weird.
  3501. // let the original error be the failure reason.
  3502. if (er2 || !stat.isDirectory()) callback(er, made)
  3503. else callback(null, made)
  3504. })
  3505. break
  3506. }
  3507. })
  3508. }
  3509. module.exports = mkdirs
  3510. /***/ },
  3511. /* 33 */
  3512. /***/ function(module, exports, __webpack_require__) {
  3513. var fs = __webpack_require__(20)
  3514. var path = __webpack_require__(4)
  3515. var o777 = parseInt('0777', 8)
  3516. function mkdirsSync (p, opts, made) {
  3517. if (!opts || typeof opts !== 'object') {
  3518. opts = { mode: opts }
  3519. }
  3520. var mode = opts.mode
  3521. var xfs = opts.fs || fs
  3522. if (mode === undefined) {
  3523. mode = o777 & (~process.umask())
  3524. }
  3525. if (!made) made = null
  3526. p = path.resolve(p)
  3527. try {
  3528. xfs.mkdirSync(p, mode)
  3529. made = made || p
  3530. } catch (err0) {
  3531. switch (err0.code) {
  3532. case 'ENOENT' :
  3533. made = mkdirsSync(path.dirname(p), opts, made)
  3534. mkdirsSync(p, opts, made)
  3535. break
  3536. // In the case of any other error, just see if there's a dir
  3537. // there already. If so, then hooray! If not, then something
  3538. // is borked.
  3539. default:
  3540. var stat
  3541. try {
  3542. stat = xfs.statSync(p)
  3543. } catch (err1) {
  3544. throw err0
  3545. }
  3546. if (!stat.isDirectory()) throw err0
  3547. break
  3548. }
  3549. }
  3550. return made
  3551. }
  3552. module.exports = mkdirsSync
  3553. /***/ },
  3554. /* 34 */
  3555. /***/ function(module, exports, __webpack_require__) {
  3556. module.exports = {
  3557. copySync: __webpack_require__(35)
  3558. }
  3559. /***/ },
  3560. /* 35 */
  3561. /***/ function(module, exports, __webpack_require__) {
  3562. var fs = __webpack_require__(20)
  3563. var path = __webpack_require__(4)
  3564. var copyFileSync = __webpack_require__(36)
  3565. var mkdir = __webpack_require__(31)
  3566. function copySync (src, dest, options) {
  3567. if (typeof options === 'function' || options instanceof RegExp) {
  3568. options = {filter: options}
  3569. }
  3570. options = options || {}
  3571. options.recursive = !!options.recursive
  3572. // default to true for now
  3573. options.clobber = 'clobber' in options ? !!options.clobber : true
  3574. options.preserveTimestamps = 'preserveTimestamps' in options ? !!options.preserveTimestamps : false
  3575. options.filter = options.filter || function () { return true }
  3576. var stats = options.recursive ? fs.lstatSync(src) : fs.statSync(src)
  3577. var destFolder = path.dirname(dest)
  3578. var destFolderExists = fs.existsSync(destFolder)
  3579. var performCopy = false
  3580. if (stats.isFile()) {
  3581. if (options.filter instanceof RegExp) performCopy = options.filter.test(src)
  3582. else if (typeof options.filter === 'function') performCopy = options.filter(src)
  3583. if (performCopy) {
  3584. if (!destFolderExists) mkdir.mkdirsSync(destFolder)
  3585. copyFileSync(src, dest, {clobber: options.clobber, preserveTimestamps: options.preserveTimestamps})
  3586. }
  3587. } else if (stats.isDirectory()) {
  3588. if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest)
  3589. var contents = fs.readdirSync(src)
  3590. contents.forEach(function (content) {
  3591. var opts = options
  3592. opts.recursive = true
  3593. copySync(path.join(src, content), path.join(dest, content), opts)
  3594. })
  3595. } else if (options.recursive && stats.isSymbolicLink()) {
  3596. var srcPath = fs.readlinkSync(src)
  3597. fs.symlinkSync(srcPath, dest)
  3598. }
  3599. }
  3600. module.exports = copySync
  3601. /***/ },
  3602. /* 36 */
  3603. /***/ function(module, exports, __webpack_require__) {
  3604. var fs = __webpack_require__(20)
  3605. var BUF_LENGTH = 64 * 1024
  3606. var _buff = new Buffer(BUF_LENGTH)
  3607. function copyFileSync (srcFile, destFile, options) {
  3608. var clobber = options.clobber
  3609. var preserveTimestamps = options.preserveTimestamps
  3610. if (fs.existsSync(destFile)) {
  3611. if (clobber) {
  3612. fs.chmodSync(destFile, parseInt('777', 8))
  3613. fs.unlinkSync(destFile)
  3614. } else {
  3615. throw Error('EEXIST')
  3616. }
  3617. }
  3618. var fdr = fs.openSync(srcFile, 'r')
  3619. var stat = fs.fstatSync(fdr)
  3620. var fdw = fs.openSync(destFile, 'w', stat.mode)
  3621. var bytesRead = 1
  3622. var pos = 0
  3623. while (bytesRead > 0) {
  3624. bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
  3625. fs.writeSync(fdw, _buff, 0, bytesRead)
  3626. pos += bytesRead
  3627. }
  3628. if (preserveTimestamps) {
  3629. fs.futimesSync(fdw, stat.atime, stat.mtime)
  3630. }
  3631. fs.closeSync(fdr)
  3632. fs.closeSync(fdw)
  3633. }
  3634. module.exports = copyFileSync
  3635. /***/ },
  3636. /* 37 */
  3637. /***/ function(module, exports, __webpack_require__) {
  3638. var rimraf = __webpack_require__(38)
  3639. function removeSync (dir) {
  3640. return rimraf.sync(dir)
  3641. }
  3642. function remove (dir, callback) {
  3643. return callback ? rimraf(dir, callback) : rimraf(dir, function () {})
  3644. }
  3645. module.exports = {
  3646. remove: remove,
  3647. removeSync: removeSync
  3648. }
  3649. /***/ },
  3650. /* 38 */
  3651. /***/ function(module, exports, __webpack_require__) {
  3652. module.exports = rimraf
  3653. rimraf.sync = rimrafSync
  3654. var assert = __webpack_require__(11)
  3655. var path = __webpack_require__(4)
  3656. var fs = __webpack_require__(2)
  3657. var glob = __webpack_require__(39)
  3658. var defaultGlobOpts = {
  3659. nosort: true,
  3660. silent: true
  3661. }
  3662. // for EMFILE handling
  3663. var timeout = 0
  3664. var isWindows = (process.platform === "win32")
  3665. function defaults (options) {
  3666. var methods = [
  3667. 'unlink',
  3668. 'chmod',
  3669. 'stat',
  3670. 'lstat',
  3671. 'rmdir',
  3672. 'readdir'
  3673. ]
  3674. methods.forEach(function(m) {
  3675. options[m] = options[m] || fs[m]
  3676. m = m + 'Sync'
  3677. options[m] = options[m] || fs[m]
  3678. })
  3679. options.maxBusyTries = options.maxBusyTries || 3
  3680. options.emfileWait = options.emfileWait || 1000
  3681. if (options.glob === false) {
  3682. options.disableGlob = true
  3683. }
  3684. options.disableGlob = options.disableGlob || false
  3685. options.glob = options.glob || defaultGlobOpts
  3686. }
  3687. function rimraf (p, options, cb) {
  3688. if (typeof options === 'function') {
  3689. cb = options
  3690. options = {}
  3691. }
  3692. assert(p, 'rimraf: missing path')
  3693. assert.equal(typeof p, 'string', 'rimraf: path should be a string')
  3694. assert(options, 'rimraf: missing options')
  3695. assert.equal(typeof options, 'object', 'rimraf: options should be object')
  3696. assert.equal(typeof cb, 'function', 'rimraf: callback function required')
  3697. defaults(options)
  3698. var busyTries = 0
  3699. var errState = null
  3700. var n = 0
  3701. if (options.disableGlob || !glob.hasMagic(p))
  3702. return afterGlob(null, [p])
  3703. fs.lstat(p, function (er, stat) {
  3704. if (!er)
  3705. return afterGlob(null, [p])
  3706. glob(p, options.glob, afterGlob)
  3707. })
  3708. function next (er) {
  3709. errState = errState || er
  3710. if (--n === 0)
  3711. cb(errState)
  3712. }
  3713. function afterGlob (er, results) {
  3714. if (er)
  3715. return cb(er)
  3716. n = results.length
  3717. if (n === 0)
  3718. return cb()
  3719. results.forEach(function (p) {
  3720. rimraf_(p, options, function CB (er) {
  3721. if (er) {
  3722. if (isWindows && (er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") &&
  3723. busyTries < options.maxBusyTries) {
  3724. busyTries ++
  3725. var time = busyTries * 100
  3726. // try again, with the same exact callback as this one.
  3727. return setTimeout(function () {
  3728. rimraf_(p, options, CB)
  3729. }, time)
  3730. }
  3731. // this one won't happen if graceful-fs is used.
  3732. if (er.code === "EMFILE" && timeout < options.emfileWait) {
  3733. return setTimeout(function () {
  3734. rimraf_(p, options, CB)
  3735. }, timeout ++)
  3736. }
  3737. // already gone
  3738. if (er.code === "ENOENT") er = null
  3739. }
  3740. timeout = 0
  3741. next(er)
  3742. })
  3743. })
  3744. }
  3745. }
  3746. // Two possible strategies.
  3747. // 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
  3748. // 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
  3749. //
  3750. // Both result in an extra syscall when you guess wrong. However, there
  3751. // are likely far more normal files in the world than directories. This
  3752. // is based on the assumption that a the average number of files per
  3753. // directory is >= 1.
  3754. //
  3755. // If anyone ever complains about this, then I guess the strategy could
  3756. // be made configurable somehow. But until then, YAGNI.
  3757. function rimraf_ (p, options, cb) {
  3758. assert(p)
  3759. assert(options)
  3760. assert(typeof cb === 'function')
  3761. // sunos lets the root user unlink directories, which is... weird.
  3762. // so we have to lstat here and make sure it's not a dir.
  3763. options.lstat(p, function (er, st) {
  3764. if (er && er.code === "ENOENT")
  3765. return cb(null)
  3766. if (st && st.isDirectory())
  3767. return rmdir(p, options, er, cb)
  3768. options.unlink(p, function (er) {
  3769. if (er) {
  3770. if (er.code === "ENOENT")
  3771. return cb(null)
  3772. if (er.code === "EPERM")
  3773. return (isWindows)
  3774. ? fixWinEPERM(p, options, er, cb)
  3775. : rmdir(p, options, er, cb)
  3776. if (er.code === "EISDIR")
  3777. return rmdir(p, options, er, cb)
  3778. }
  3779. return cb(er)
  3780. })
  3781. })
  3782. }
  3783. function fixWinEPERM (p, options, er, cb) {
  3784. assert(p)
  3785. assert(options)
  3786. assert(typeof cb === 'function')
  3787. if (er)
  3788. assert(er instanceof Error)
  3789. options.chmod(p, 666, function (er2) {
  3790. if (er2)
  3791. cb(er2.code === "ENOENT" ? null : er)
  3792. else
  3793. options.stat(p, function(er3, stats) {
  3794. if (er3)
  3795. cb(er3.code === "ENOENT" ? null : er)
  3796. else if (stats.isDirectory())
  3797. rmdir(p, options, er, cb)
  3798. else
  3799. options.unlink(p, cb)
  3800. })
  3801. })
  3802. }
  3803. function fixWinEPERMSync (p, options, er) {
  3804. assert(p)
  3805. assert(options)
  3806. if (er)
  3807. assert(er instanceof Error)
  3808. try {
  3809. options.chmodSync(p, 666)
  3810. } catch (er2) {
  3811. if (er2.code === "ENOENT")
  3812. return
  3813. else
  3814. throw er
  3815. }
  3816. try {
  3817. var stats = options.statSync(p)
  3818. } catch (er3) {
  3819. if (er3.code === "ENOENT")
  3820. return
  3821. else
  3822. throw er
  3823. }
  3824. if (stats.isDirectory())
  3825. rmdirSync(p, options, er)
  3826. else
  3827. options.unlinkSync(p)
  3828. }
  3829. function rmdir (p, options, originalEr, cb) {
  3830. assert(p)
  3831. assert(options)
  3832. if (originalEr)
  3833. assert(originalEr instanceof Error)
  3834. assert(typeof cb === 'function')
  3835. // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
  3836. // if we guessed wrong, and it's not a directory, then
  3837. // raise the original error.
  3838. options.rmdir(p, function (er) {
  3839. if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM"))
  3840. rmkids(p, options, cb)
  3841. else if (er && er.code === "ENOTDIR")
  3842. cb(originalEr)
  3843. else
  3844. cb(er)
  3845. })
  3846. }
  3847. function rmkids(p, options, cb) {
  3848. assert(p)
  3849. assert(options)
  3850. assert(typeof cb === 'function')
  3851. options.readdir(p, function (er, files) {
  3852. if (er)
  3853. return cb(er)
  3854. var n = files.length
  3855. if (n === 0)
  3856. return options.rmdir(p, cb)
  3857. var errState
  3858. files.forEach(function (f) {
  3859. rimraf(path.join(p, f), options, function (er) {
  3860. if (errState)
  3861. return
  3862. if (er)
  3863. return cb(errState = er)
  3864. if (--n === 0)
  3865. options.rmdir(p, cb)
  3866. })
  3867. })
  3868. })
  3869. }
  3870. // this looks simpler, and is strictly *faster*, but will
  3871. // tie up the JavaScript thread and fail on excessively
  3872. // deep directory trees.
  3873. function rimrafSync (p, options) {
  3874. options = options || {}
  3875. defaults(options)
  3876. assert(p, 'rimraf: missing path')
  3877. assert.equal(typeof p, 'string', 'rimraf: path should be a string')
  3878. assert(options, 'rimraf: missing options')
  3879. assert.equal(typeof options, 'object', 'rimraf: options should be object')
  3880. var results
  3881. if (options.disableGlob || !glob.hasMagic(p)) {
  3882. results = [p]
  3883. } else {
  3884. try {
  3885. fs.lstatSync(p)
  3886. results = [p]
  3887. } catch (er) {
  3888. results = glob.sync(p, options.glob)
  3889. }
  3890. }
  3891. if (!results.length)
  3892. return
  3893. for (var i = 0; i < results.length; i++) {
  3894. var p = results[i]
  3895. try {
  3896. var st = options.lstatSync(p)
  3897. } catch (er) {
  3898. if (er.code === "ENOENT")
  3899. return
  3900. }
  3901. try {
  3902. // sunos lets the root user unlink directories, which is... weird.
  3903. if (st && st.isDirectory())
  3904. rmdirSync(p, options, null)
  3905. else
  3906. options.unlinkSync(p)
  3907. } catch (er) {
  3908. if (er.code === "ENOENT")
  3909. return
  3910. if (er.code === "EPERM")
  3911. return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
  3912. if (er.code !== "EISDIR")
  3913. throw er
  3914. rmdirSync(p, options, er)
  3915. }
  3916. }
  3917. }
  3918. function rmdirSync (p, options, originalEr) {
  3919. assert(p)
  3920. assert(options)
  3921. if (originalEr)
  3922. assert(originalEr instanceof Error)
  3923. try {
  3924. options.rmdirSync(p)
  3925. } catch (er) {
  3926. if (er.code === "ENOENT")
  3927. return
  3928. if (er.code === "ENOTDIR")
  3929. throw originalEr
  3930. if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")
  3931. rmkidsSync(p, options)
  3932. }
  3933. }
  3934. function rmkidsSync (p, options) {
  3935. assert(p)
  3936. assert(options)
  3937. options.readdirSync(p).forEach(function (f) {
  3938. rimrafSync(path.join(p, f), options)
  3939. })
  3940. options.rmdirSync(p, options)
  3941. }
  3942. /***/ },
  3943. /* 39 */
  3944. /***/ function(module, exports, __webpack_require__) {
  3945. // Approach:
  3946. //
  3947. // 1. Get the minimatch set
  3948. // 2. For each pattern in the set, PROCESS(pattern, false)
  3949. // 3. Store matches per-set, then uniq them
  3950. //
  3951. // PROCESS(pattern, inGlobStar)
  3952. // Get the first [n] items from pattern that are all strings
  3953. // Join these together. This is PREFIX.
  3954. // If there is no more remaining, then stat(PREFIX) and
  3955. // add to matches if it succeeds. END.
  3956. //
  3957. // If inGlobStar and PREFIX is symlink and points to dir
  3958. // set ENTRIES = []
  3959. // else readdir(PREFIX) as ENTRIES
  3960. // If fail, END
  3961. //
  3962. // with ENTRIES
  3963. // If pattern[n] is GLOBSTAR
  3964. // // handle the case where the globstar match is empty
  3965. // // by pruning it out, and testing the resulting pattern
  3966. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  3967. // // handle other cases.
  3968. // for ENTRY in ENTRIES (not dotfiles)
  3969. // // attach globstar + tail onto the entry
  3970. // // Mark that this entry is a globstar match
  3971. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  3972. //
  3973. // else // not globstar
  3974. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  3975. // Test ENTRY against pattern[n]
  3976. // If fails, continue
  3977. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  3978. //
  3979. // Caveat:
  3980. // Cache all stats and readdirs results to minimize syscall. Since all
  3981. // we ever care about is existence and directory-ness, we can just keep
  3982. // `true` for files, and [children,...] for directories, or `false` for
  3983. // things that don't exist.
  3984. module.exports = glob
  3985. var fs = __webpack_require__(2)
  3986. var minimatch = __webpack_require__(40)
  3987. var Minimatch = minimatch.Minimatch
  3988. var inherits = __webpack_require__(41)
  3989. var EE = __webpack_require__(10).EventEmitter
  3990. var path = __webpack_require__(4)
  3991. var assert = __webpack_require__(11)
  3992. var isAbsolute = __webpack_require__(12)
  3993. var globSync = __webpack_require__(42)
  3994. var common = __webpack_require__(43)
  3995. var alphasort = common.alphasort
  3996. var alphasorti = common.alphasorti
  3997. var setopts = common.setopts
  3998. var ownProp = common.ownProp
  3999. var inflight = __webpack_require__(15)
  4000. var util = __webpack_require__(9)
  4001. var childrenIgnored = common.childrenIgnored
  4002. var isIgnored = common.isIgnored
  4003. var once = __webpack_require__(17)
  4004. function glob (pattern, options, cb) {
  4005. if (typeof options === 'function') cb = options, options = {}
  4006. if (!options) options = {}
  4007. if (options.sync) {
  4008. if (cb)
  4009. throw new TypeError('callback provided to sync glob')
  4010. return globSync(pattern, options)
  4011. }
  4012. return new Glob(pattern, options, cb)
  4013. }
  4014. glob.sync = globSync
  4015. var GlobSync = glob.GlobSync = globSync.GlobSync
  4016. // old api surface
  4017. glob.glob = glob
  4018. function extend (origin, add) {
  4019. if (add === null || typeof add !== 'object') {
  4020. return origin
  4021. }
  4022. var keys = Object.keys(add)
  4023. var i = keys.length
  4024. while (i--) {
  4025. origin[keys[i]] = add[keys[i]]
  4026. }
  4027. return origin
  4028. }
  4029. glob.hasMagic = function (pattern, options_) {
  4030. var options = extend({}, options_)
  4031. options.noprocess = true
  4032. var g = new Glob(pattern, options)
  4033. var set = g.minimatch.set
  4034. if (set.length > 1)
  4035. return true
  4036. for (var j = 0; j < set[0].length; j++) {
  4037. if (typeof set[0][j] !== 'string')
  4038. return true
  4039. }
  4040. return false
  4041. }
  4042. glob.Glob = Glob
  4043. inherits(Glob, EE)
  4044. function Glob (pattern, options, cb) {
  4045. if (typeof options === 'function') {
  4046. cb = options
  4047. options = null
  4048. }
  4049. if (options && options.sync) {
  4050. if (cb)
  4051. throw new TypeError('callback provided to sync glob')
  4052. return new GlobSync(pattern, options)
  4053. }
  4054. if (!(this instanceof Glob))
  4055. return new Glob(pattern, options, cb)
  4056. setopts(this, pattern, options)
  4057. this._didRealPath = false
  4058. // process each pattern in the minimatch set
  4059. var n = this.minimatch.set.length
  4060. // The matches are stored as {<filename>: true,...} so that
  4061. // duplicates are automagically pruned.
  4062. // Later, we do an Object.keys() on these.
  4063. // Keep them as a list so we can fill in when nonull is set.
  4064. this.matches = new Array(n)
  4065. if (typeof cb === 'function') {
  4066. cb = once(cb)
  4067. this.on('error', cb)
  4068. this.on('end', function (matches) {
  4069. cb(null, matches)
  4070. })
  4071. }
  4072. var self = this
  4073. var n = this.minimatch.set.length
  4074. this._processing = 0
  4075. this.matches = new Array(n)
  4076. this._emitQueue = []
  4077. this._processQueue = []
  4078. this.paused = false
  4079. if (this.noprocess)
  4080. return this
  4081. if (n === 0)
  4082. return done()
  4083. for (var i = 0; i < n; i ++) {
  4084. this._process(this.minimatch.set[i], i, false, done)
  4085. }
  4086. function done () {
  4087. --self._processing
  4088. if (self._processing <= 0)
  4089. self._finish()
  4090. }
  4091. }
  4092. Glob.prototype._finish = function () {
  4093. assert(this instanceof Glob)
  4094. if (this.aborted)
  4095. return
  4096. if (this.realpath && !this._didRealpath)
  4097. return this._realpath()
  4098. common.finish(this)
  4099. this.emit('end', this.found)
  4100. }
  4101. Glob.prototype._realpath = function () {
  4102. if (this._didRealpath)
  4103. return
  4104. this._didRealpath = true
  4105. var n = this.matches.length
  4106. if (n === 0)
  4107. return this._finish()
  4108. var self = this
  4109. for (var i = 0; i < this.matches.length; i++)
  4110. this._realpathSet(i, next)
  4111. function next () {
  4112. if (--n === 0)
  4113. self._finish()
  4114. }
  4115. }
  4116. Glob.prototype._realpathSet = function (index, cb) {
  4117. var matchset = this.matches[index]
  4118. if (!matchset)
  4119. return cb()
  4120. var found = Object.keys(matchset)
  4121. var self = this
  4122. var n = found.length
  4123. if (n === 0)
  4124. return cb()
  4125. var set = this.matches[index] = Object.create(null)
  4126. found.forEach(function (p, i) {
  4127. // If there's a problem with the stat, then it means that
  4128. // one or more of the links in the realpath couldn't be
  4129. // resolved. just return the abs value in that case.
  4130. p = self._makeAbs(p)
  4131. fs.realpath(p, self.realpathCache, function (er, real) {
  4132. if (!er)
  4133. set[real] = true
  4134. else if (er.syscall === 'stat')
  4135. set[p] = true
  4136. else
  4137. self.emit('error', er) // srsly wtf right here
  4138. if (--n === 0) {
  4139. self.matches[index] = set
  4140. cb()
  4141. }
  4142. })
  4143. })
  4144. }
  4145. Glob.prototype._mark = function (p) {
  4146. return common.mark(this, p)
  4147. }
  4148. Glob.prototype._makeAbs = function (f) {
  4149. return common.makeAbs(this, f)
  4150. }
  4151. Glob.prototype.abort = function () {
  4152. this.aborted = true
  4153. this.emit('abort')
  4154. }
  4155. Glob.prototype.pause = function () {
  4156. if (!this.paused) {
  4157. this.paused = true
  4158. this.emit('pause')
  4159. }
  4160. }
  4161. Glob.prototype.resume = function () {
  4162. if (this.paused) {
  4163. this.emit('resume')
  4164. this.paused = false
  4165. if (this._emitQueue.length) {
  4166. var eq = this._emitQueue.slice(0)
  4167. this._emitQueue.length = 0
  4168. for (var i = 0; i < eq.length; i ++) {
  4169. var e = eq[i]
  4170. this._emitMatch(e[0], e[1])
  4171. }
  4172. }
  4173. if (this._processQueue.length) {
  4174. var pq = this._processQueue.slice(0)
  4175. this._processQueue.length = 0
  4176. for (var i = 0; i < pq.length; i ++) {
  4177. var p = pq[i]
  4178. this._processing--
  4179. this._process(p[0], p[1], p[2], p[3])
  4180. }
  4181. }
  4182. }
  4183. }
  4184. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  4185. assert(this instanceof Glob)
  4186. assert(typeof cb === 'function')
  4187. if (this.aborted)
  4188. return
  4189. this._processing++
  4190. if (this.paused) {
  4191. this._processQueue.push([pattern, index, inGlobStar, cb])
  4192. return
  4193. }
  4194. //console.error('PROCESS %d', this._processing, pattern)
  4195. // Get the first [n] parts of pattern that are all strings.
  4196. var n = 0
  4197. while (typeof pattern[n] === 'string') {
  4198. n ++
  4199. }
  4200. // now n is the index of the first one that is *not* a string.
  4201. // see if there's anything else
  4202. var prefix
  4203. switch (n) {
  4204. // if not, then this is rather simple
  4205. case pattern.length:
  4206. this._processSimple(pattern.join('/'), index, cb)
  4207. return
  4208. case 0:
  4209. // pattern *starts* with some non-trivial item.
  4210. // going to readdir(cwd), but not include the prefix in matches.
  4211. prefix = null
  4212. break
  4213. default:
  4214. // pattern has some string bits in the front.
  4215. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  4216. // or 'relative' like '../baz'
  4217. prefix = pattern.slice(0, n).join('/')
  4218. break
  4219. }
  4220. var remain = pattern.slice(n)
  4221. // get the list of entries.
  4222. var read
  4223. if (prefix === null)
  4224. read = '.'
  4225. else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
  4226. if (!prefix || !isAbsolute(prefix))
  4227. prefix = '/' + prefix
  4228. read = prefix
  4229. } else
  4230. read = prefix
  4231. var abs = this._makeAbs(read)
  4232. //if ignored, skip _processing
  4233. if (childrenIgnored(this, read))
  4234. return cb()
  4235. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  4236. if (isGlobStar)
  4237. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb)
  4238. else
  4239. this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb)
  4240. }
  4241. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  4242. var self = this
  4243. this._readdir(abs, inGlobStar, function (er, entries) {
  4244. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  4245. })
  4246. }
  4247. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  4248. // if the abs isn't a dir, then nothing can match!
  4249. if (!entries)
  4250. return cb()
  4251. // It will only match dot entries if it starts with a dot, or if
  4252. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  4253. var pn = remain[0]
  4254. var negate = !!this.minimatch.negate
  4255. var rawGlob = pn._glob
  4256. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  4257. var matchedEntries = []
  4258. for (var i = 0; i < entries.length; i++) {
  4259. var e = entries[i]
  4260. if (e.charAt(0) !== '.' || dotOk) {
  4261. var m
  4262. if (negate && !prefix) {
  4263. m = !e.match(pn)
  4264. } else {
  4265. m = e.match(pn)
  4266. }
  4267. if (m)
  4268. matchedEntries.push(e)
  4269. }
  4270. }
  4271. //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  4272. var len = matchedEntries.length
  4273. // If there are no matched entries, then nothing matches.
  4274. if (len === 0)
  4275. return cb()
  4276. // if this is the last remaining pattern bit, then no need for
  4277. // an additional stat *unless* the user has specified mark or
  4278. // stat explicitly. We know they exist, since readdir returned
  4279. // them.
  4280. if (remain.length === 1 && !this.mark && !this.stat) {
  4281. if (!this.matches[index])
  4282. this.matches[index] = Object.create(null)
  4283. for (var i = 0; i < len; i ++) {
  4284. var e = matchedEntries[i]
  4285. if (prefix) {
  4286. if (prefix !== '/')
  4287. e = prefix + '/' + e
  4288. else
  4289. e = prefix + e
  4290. }
  4291. if (e.charAt(0) === '/' && !this.nomount) {
  4292. e = path.join(this.root, e)
  4293. }
  4294. this._emitMatch(index, e)
  4295. }
  4296. // This was the last one, and no stats were needed
  4297. return cb()
  4298. }
  4299. // now test all matched entries as stand-ins for that part
  4300. // of the pattern.
  4301. remain.shift()
  4302. for (var i = 0; i < len; i ++) {
  4303. var e = matchedEntries[i]
  4304. var newPattern
  4305. if (prefix) {
  4306. if (prefix !== '/')
  4307. e = prefix + '/' + e
  4308. else
  4309. e = prefix + e
  4310. }
  4311. this._process([e].concat(remain), index, inGlobStar, cb)
  4312. }
  4313. cb()
  4314. }
  4315. Glob.prototype._emitMatch = function (index, e) {
  4316. if (this.aborted)
  4317. return
  4318. if (this.matches[index][e])
  4319. return
  4320. if (isIgnored(this, e))
  4321. return
  4322. if (this.paused) {
  4323. this._emitQueue.push([index, e])
  4324. return
  4325. }
  4326. var abs = this._makeAbs(e)
  4327. if (this.nodir) {
  4328. var c = this.cache[abs]
  4329. if (c === 'DIR' || Array.isArray(c))
  4330. return
  4331. }
  4332. if (this.mark)
  4333. e = this._mark(e)
  4334. this.matches[index][e] = true
  4335. var st = this.statCache[abs]
  4336. if (st)
  4337. this.emit('stat', e, st)
  4338. this.emit('match', e)
  4339. }
  4340. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  4341. if (this.aborted)
  4342. return
  4343. // follow all symlinked directories forever
  4344. // just proceed as if this is a non-globstar situation
  4345. if (this.follow)
  4346. return this._readdir(abs, false, cb)
  4347. var lstatkey = 'lstat\0' + abs
  4348. var self = this
  4349. var lstatcb = inflight(lstatkey, lstatcb_)
  4350. if (lstatcb)
  4351. fs.lstat(abs, lstatcb)
  4352. function lstatcb_ (er, lstat) {
  4353. if (er)
  4354. return cb()
  4355. var isSym = lstat.isSymbolicLink()
  4356. self.symlinks[abs] = isSym
  4357. // If it's not a symlink or a dir, then it's definitely a regular file.
  4358. // don't bother doing a readdir in that case.
  4359. if (!isSym && !lstat.isDirectory()) {
  4360. self.cache[abs] = 'FILE'
  4361. cb()
  4362. } else
  4363. self._readdir(abs, false, cb)
  4364. }
  4365. }
  4366. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  4367. if (this.aborted)
  4368. return
  4369. cb = inflight('readdir\0'+abs+'\0'+inGlobStar, cb)
  4370. if (!cb)
  4371. return
  4372. //console.error('RD %j %j', +inGlobStar, abs)
  4373. if (inGlobStar && !ownProp(this.symlinks, abs))
  4374. return this._readdirInGlobStar(abs, cb)
  4375. if (ownProp(this.cache, abs)) {
  4376. var c = this.cache[abs]
  4377. if (!c || c === 'FILE')
  4378. return cb()
  4379. if (Array.isArray(c))
  4380. return cb(null, c)
  4381. }
  4382. var self = this
  4383. fs.readdir(abs, readdirCb(this, abs, cb))
  4384. }
  4385. function readdirCb (self, abs, cb) {
  4386. return function (er, entries) {
  4387. if (er)
  4388. self._readdirError(abs, er, cb)
  4389. else
  4390. self._readdirEntries(abs, entries, cb)
  4391. }
  4392. }
  4393. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  4394. if (this.aborted)
  4395. return
  4396. // if we haven't asked to stat everything, then just
  4397. // assume that everything in there exists, so we can avoid
  4398. // having to stat it a second time.
  4399. if (!this.mark && !this.stat) {
  4400. for (var i = 0; i < entries.length; i ++) {
  4401. var e = entries[i]
  4402. if (abs === '/')
  4403. e = abs + e
  4404. else
  4405. e = abs + '/' + e
  4406. this.cache[e] = true
  4407. }
  4408. }
  4409. this.cache[abs] = entries
  4410. return cb(null, entries)
  4411. }
  4412. Glob.prototype._readdirError = function (f, er, cb) {
  4413. if (this.aborted)
  4414. return
  4415. // handle errors, and cache the information
  4416. switch (er.code) {
  4417. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  4418. case 'ENOTDIR': // totally normal. means it *does* exist.
  4419. this.cache[this._makeAbs(f)] = 'FILE'
  4420. if (f === this.cwd) {
  4421. var error = new Error(er.code + ' invalid cwd ' + f)
  4422. error.path = f
  4423. error.code = er.code
  4424. this.emit('error', error)
  4425. this.abort()
  4426. }
  4427. break
  4428. case 'ENOENT': // not terribly unusual
  4429. case 'ELOOP':
  4430. case 'ENAMETOOLONG':
  4431. case 'UNKNOWN':
  4432. this.cache[this._makeAbs(f)] = false
  4433. break
  4434. default: // some unusual error. Treat as failure.
  4435. this.cache[this._makeAbs(f)] = false
  4436. if (this.strict) {
  4437. this.emit('error', er)
  4438. // If the error is handled, then we abort
  4439. // if not, we threw out of here
  4440. this.abort()
  4441. }
  4442. if (!this.silent)
  4443. console.error('glob error', er)
  4444. break
  4445. }
  4446. return cb()
  4447. }
  4448. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  4449. var self = this
  4450. this._readdir(abs, inGlobStar, function (er, entries) {
  4451. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  4452. })
  4453. }
  4454. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  4455. //console.error('pgs2', prefix, remain[0], entries)
  4456. // no entries means not a dir, so it can never have matches
  4457. // foo.txt/** doesn't match foo.txt
  4458. if (!entries)
  4459. return cb()
  4460. // test without the globstar, and with every child both below
  4461. // and replacing the globstar.
  4462. var remainWithoutGlobStar = remain.slice(1)
  4463. var gspref = prefix ? [ prefix ] : []
  4464. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  4465. // the noGlobStar pattern exits the inGlobStar state
  4466. this._process(noGlobStar, index, false, cb)
  4467. var isSym = this.symlinks[abs]
  4468. var len = entries.length
  4469. // If it's a symlink, and we're in a globstar, then stop
  4470. if (isSym && inGlobStar)
  4471. return cb()
  4472. for (var i = 0; i < len; i++) {
  4473. var e = entries[i]
  4474. if (e.charAt(0) === '.' && !this.dot)
  4475. continue
  4476. // these two cases enter the inGlobStar state
  4477. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  4478. this._process(instead, index, true, cb)
  4479. var below = gspref.concat(entries[i], remain)
  4480. this._process(below, index, true, cb)
  4481. }
  4482. cb()
  4483. }
  4484. Glob.prototype._processSimple = function (prefix, index, cb) {
  4485. // XXX review this. Shouldn't it be doing the mounting etc
  4486. // before doing stat? kinda weird?
  4487. var self = this
  4488. this._stat(prefix, function (er, exists) {
  4489. self._processSimple2(prefix, index, er, exists, cb)
  4490. })
  4491. }
  4492. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  4493. //console.error('ps2', prefix, exists)
  4494. if (!this.matches[index])
  4495. this.matches[index] = Object.create(null)
  4496. // If it doesn't exist, then just mark the lack of results
  4497. if (!exists)
  4498. return cb()
  4499. if (prefix && isAbsolute(prefix) && !this.nomount) {
  4500. var trail = /[\/\\]$/.test(prefix)
  4501. if (prefix.charAt(0) === '/') {
  4502. prefix = path.join(this.root, prefix)
  4503. } else {
  4504. prefix = path.resolve(this.root, prefix)
  4505. if (trail)
  4506. prefix += '/'
  4507. }
  4508. }
  4509. if (process.platform === 'win32')
  4510. prefix = prefix.replace(/\\/g, '/')
  4511. // Mark this as a match
  4512. this._emitMatch(index, prefix)
  4513. cb()
  4514. }
  4515. // Returns either 'DIR', 'FILE', or false
  4516. Glob.prototype._stat = function (f, cb) {
  4517. var abs = this._makeAbs(f)
  4518. var needDir = f.slice(-1) === '/'
  4519. if (f.length > this.maxLength)
  4520. return cb()
  4521. if (!this.stat && ownProp(this.cache, abs)) {
  4522. var c = this.cache[abs]
  4523. if (Array.isArray(c))
  4524. c = 'DIR'
  4525. // It exists, but maybe not how we need it
  4526. if (!needDir || c === 'DIR')
  4527. return cb(null, c)
  4528. if (needDir && c === 'FILE')
  4529. return cb()
  4530. // otherwise we have to stat, because maybe c=true
  4531. // if we know it exists, but not what it is.
  4532. }
  4533. var exists
  4534. var stat = this.statCache[abs]
  4535. if (stat !== undefined) {
  4536. if (stat === false)
  4537. return cb(null, stat)
  4538. else {
  4539. var type = stat.isDirectory() ? 'DIR' : 'FILE'
  4540. if (needDir && type === 'FILE')
  4541. return cb()
  4542. else
  4543. return cb(null, type, stat)
  4544. }
  4545. }
  4546. var self = this
  4547. var statcb = inflight('stat\0' + abs, lstatcb_)
  4548. if (statcb)
  4549. fs.lstat(abs, statcb)
  4550. function lstatcb_ (er, lstat) {
  4551. if (lstat && lstat.isSymbolicLink()) {
  4552. // If it's a symlink, then treat it as the target, unless
  4553. // the target does not exist, then treat it as a file.
  4554. return fs.stat(abs, function (er, stat) {
  4555. if (er)
  4556. self._stat2(f, abs, null, lstat, cb)
  4557. else
  4558. self._stat2(f, abs, er, stat, cb)
  4559. })
  4560. } else {
  4561. self._stat2(f, abs, er, lstat, cb)
  4562. }
  4563. }
  4564. }
  4565. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  4566. if (er) {
  4567. this.statCache[abs] = false
  4568. return cb()
  4569. }
  4570. var needDir = f.slice(-1) === '/'
  4571. this.statCache[abs] = stat
  4572. if (abs.slice(-1) === '/' && !stat.isDirectory())
  4573. return cb(null, false, stat)
  4574. var c = stat.isDirectory() ? 'DIR' : 'FILE'
  4575. this.cache[abs] = this.cache[abs] || c
  4576. if (needDir && c !== 'DIR')
  4577. return cb()
  4578. return cb(null, c, stat)
  4579. }
  4580. /***/ },
  4581. /* 40 */
  4582. /***/ function(module, exports, __webpack_require__) {
  4583. module.exports = minimatch
  4584. minimatch.Minimatch = Minimatch
  4585. var path = { sep: '/' }
  4586. try {
  4587. path = __webpack_require__(4)
  4588. } catch (er) {}
  4589. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
  4590. var expand = __webpack_require__(5)
  4591. // any single thing other than /
  4592. // don't need to escape / when using new RegExp()
  4593. var qmark = '[^/]'
  4594. // * => any number of characters
  4595. var star = qmark + '*?'
  4596. // ** when dots are allowed. Anything goes, except .. and .
  4597. // not (^ or / followed by one or two dots followed by $ or /),
  4598. // followed by anything, any number of times.
  4599. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
  4600. // not a ^ or / followed by a dot,
  4601. // followed by anything, any number of times.
  4602. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
  4603. // characters that need to be escaped in RegExp.
  4604. var reSpecials = charSet('().*{}+?[]^$\\!')
  4605. // "abc" -> { a:true, b:true, c:true }
  4606. function charSet (s) {
  4607. return s.split('').reduce(function (set, c) {
  4608. set[c] = true
  4609. return set
  4610. }, {})
  4611. }
  4612. // normalizes slashes.
  4613. var slashSplit = /\/+/
  4614. minimatch.filter = filter
  4615. function filter (pattern, options) {
  4616. options = options || {}
  4617. return function (p, i, list) {
  4618. return minimatch(p, pattern, options)
  4619. }
  4620. }
  4621. function ext (a, b) {
  4622. a = a || {}
  4623. b = b || {}
  4624. var t = {}
  4625. Object.keys(b).forEach(function (k) {
  4626. t[k] = b[k]
  4627. })
  4628. Object.keys(a).forEach(function (k) {
  4629. t[k] = a[k]
  4630. })
  4631. return t
  4632. }
  4633. minimatch.defaults = function (def) {
  4634. if (!def || !Object.keys(def).length) return minimatch
  4635. var orig = minimatch
  4636. var m = function minimatch (p, pattern, options) {
  4637. return orig.minimatch(p, pattern, ext(def, options))
  4638. }
  4639. m.Minimatch = function Minimatch (pattern, options) {
  4640. return new orig.Minimatch(pattern, ext(def, options))
  4641. }
  4642. return m
  4643. }
  4644. Minimatch.defaults = function (def) {
  4645. if (!def || !Object.keys(def).length) return Minimatch
  4646. return minimatch.defaults(def).Minimatch
  4647. }
  4648. function minimatch (p, pattern, options) {
  4649. if (typeof pattern !== 'string') {
  4650. throw new TypeError('glob pattern string required')
  4651. }
  4652. if (!options) options = {}
  4653. // shortcut: comments match nothing.
  4654. if (!options.nocomment && pattern.charAt(0) === '#') {
  4655. return false
  4656. }
  4657. // "" only matches ""
  4658. if (pattern.trim() === '') return p === ''
  4659. return new Minimatch(pattern, options).match(p)
  4660. }
  4661. function Minimatch (pattern, options) {
  4662. if (!(this instanceof Minimatch)) {
  4663. return new Minimatch(pattern, options)
  4664. }
  4665. if (typeof pattern !== 'string') {
  4666. throw new TypeError('glob pattern string required')
  4667. }
  4668. if (!options) options = {}
  4669. pattern = pattern.trim()
  4670. // windows support: need to use /, not \
  4671. if (path.sep !== '/') {
  4672. pattern = pattern.split(path.sep).join('/')
  4673. }
  4674. this.options = options
  4675. this.set = []
  4676. this.pattern = pattern
  4677. this.regexp = null
  4678. this.negate = false
  4679. this.comment = false
  4680. this.empty = false
  4681. // make the set of regexps etc.
  4682. this.make()
  4683. }
  4684. Minimatch.prototype.debug = function () {}
  4685. Minimatch.prototype.make = make
  4686. function make () {
  4687. // don't do it more than once.
  4688. if (this._made) return
  4689. var pattern = this.pattern
  4690. var options = this.options
  4691. // empty patterns and comments match nothing.
  4692. if (!options.nocomment && pattern.charAt(0) === '#') {
  4693. this.comment = true
  4694. return
  4695. }
  4696. if (!pattern) {
  4697. this.empty = true
  4698. return
  4699. }
  4700. // step 1: figure out negation, etc.
  4701. this.parseNegate()
  4702. // step 2: expand braces
  4703. var set = this.globSet = this.braceExpand()
  4704. if (options.debug) this.debug = console.error
  4705. this.debug(this.pattern, set)
  4706. // step 3: now we have a set, so turn each one into a series of path-portion
  4707. // matching patterns.
  4708. // These will be regexps, except in the case of "**", which is
  4709. // set to the GLOBSTAR object for globstar behavior,
  4710. // and will not contain any / characters
  4711. set = this.globParts = set.map(function (s) {
  4712. return s.split(slashSplit)
  4713. })
  4714. this.debug(this.pattern, set)
  4715. // glob --> regexps
  4716. set = set.map(function (s, si, set) {
  4717. return s.map(this.parse, this)
  4718. }, this)
  4719. this.debug(this.pattern, set)
  4720. // filter out everything that didn't compile properly.
  4721. set = set.filter(function (s) {
  4722. return s.indexOf(false) === -1
  4723. })
  4724. this.debug(this.pattern, set)
  4725. this.set = set
  4726. }
  4727. Minimatch.prototype.parseNegate = parseNegate
  4728. function parseNegate () {
  4729. var pattern = this.pattern
  4730. var negate = false
  4731. var options = this.options
  4732. var negateOffset = 0
  4733. if (options.nonegate) return
  4734. for (var i = 0, l = pattern.length
  4735. ; i < l && pattern.charAt(i) === '!'
  4736. ; i++) {
  4737. negate = !negate
  4738. negateOffset++
  4739. }
  4740. if (negateOffset) this.pattern = pattern.substr(negateOffset)
  4741. this.negate = negate
  4742. }
  4743. // Brace expansion:
  4744. // a{b,c}d -> abd acd
  4745. // a{b,}c -> abc ac
  4746. // a{0..3}d -> a0d a1d a2d a3d
  4747. // a{b,c{d,e}f}g -> abg acdfg acefg
  4748. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  4749. //
  4750. // Invalid sets are not expanded.
  4751. // a{2..}b -> a{2..}b
  4752. // a{b}c -> a{b}c
  4753. minimatch.braceExpand = function (pattern, options) {
  4754. return braceExpand(pattern, options)
  4755. }
  4756. Minimatch.prototype.braceExpand = braceExpand
  4757. function braceExpand (pattern, options) {
  4758. if (!options) {
  4759. if (this instanceof Minimatch) {
  4760. options = this.options
  4761. } else {
  4762. options = {}
  4763. }
  4764. }
  4765. pattern = typeof pattern === 'undefined'
  4766. ? this.pattern : pattern
  4767. if (typeof pattern === 'undefined') {
  4768. throw new Error('undefined pattern')
  4769. }
  4770. if (options.nobrace ||
  4771. !pattern.match(/\{.*\}/)) {
  4772. // shortcut. no need to expand.
  4773. return [pattern]
  4774. }
  4775. return expand(pattern)
  4776. }
  4777. // parse a component of the expanded set.
  4778. // At this point, no pattern may contain "/" in it
  4779. // so we're going to return a 2d array, where each entry is the full
  4780. // pattern, split on '/', and then turned into a regular expression.
  4781. // A regexp is made at the end which joins each array with an
  4782. // escaped /, and another full one which joins each regexp with |.
  4783. //
  4784. // Following the lead of Bash 4.1, note that "**" only has special meaning
  4785. // when it is the *only* thing in a path portion. Otherwise, any series
  4786. // of * is equivalent to a single *. Globstar behavior is enabled by
  4787. // default, and can be disabled by setting options.noglobstar.
  4788. Minimatch.prototype.parse = parse
  4789. var SUBPARSE = {}
  4790. function parse (pattern, isSub) {
  4791. var options = this.options
  4792. // shortcuts
  4793. if (!options.noglobstar && pattern === '**') return GLOBSTAR
  4794. if (pattern === '') return ''
  4795. var re = ''
  4796. var hasMagic = !!options.nocase
  4797. var escaping = false
  4798. // ? => one single character
  4799. var patternListStack = []
  4800. var negativeLists = []
  4801. var plType
  4802. var stateChar
  4803. var inClass = false
  4804. var reClassStart = -1
  4805. var classStart = -1
  4806. // . and .. never match anything that doesn't start with .,
  4807. // even when options.dot is set.
  4808. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  4809. // not (start or / followed by . or .. followed by / or end)
  4810. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
  4811. : '(?!\\.)'
  4812. var self = this
  4813. function clearStateChar () {
  4814. if (stateChar) {
  4815. // we had some state-tracking character
  4816. // that wasn't consumed by this pass.
  4817. switch (stateChar) {
  4818. case '*':
  4819. re += star
  4820. hasMagic = true
  4821. break
  4822. case '?':
  4823. re += qmark
  4824. hasMagic = true
  4825. break
  4826. default:
  4827. re += '\\' + stateChar
  4828. break
  4829. }
  4830. self.debug('clearStateChar %j %j', stateChar, re)
  4831. stateChar = false
  4832. }
  4833. }
  4834. for (var i = 0, len = pattern.length, c
  4835. ; (i < len) && (c = pattern.charAt(i))
  4836. ; i++) {
  4837. this.debug('%s\t%s %s %j', pattern, i, re, c)
  4838. // skip over any that are escaped.
  4839. if (escaping && reSpecials[c]) {
  4840. re += '\\' + c
  4841. escaping = false
  4842. continue
  4843. }
  4844. switch (c) {
  4845. case '/':
  4846. // completely not allowed, even escaped.
  4847. // Should already be path-split by now.
  4848. return false
  4849. case '\\':
  4850. clearStateChar()
  4851. escaping = true
  4852. continue
  4853. // the various stateChar values
  4854. // for the "extglob" stuff.
  4855. case '?':
  4856. case '*':
  4857. case '+':
  4858. case '@':
  4859. case '!':
  4860. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)
  4861. // all of those are literals inside a class, except that
  4862. // the glob [!a] means [^a] in regexp
  4863. if (inClass) {
  4864. this.debug(' in class')
  4865. if (c === '!' && i === classStart + 1) c = '^'
  4866. re += c
  4867. continue
  4868. }
  4869. // if we already have a stateChar, then it means
  4870. // that there was something like ** or +? in there.
  4871. // Handle the stateChar, then proceed with this one.
  4872. self.debug('call clearStateChar %j', stateChar)
  4873. clearStateChar()
  4874. stateChar = c
  4875. // if extglob is disabled, then +(asdf|foo) isn't a thing.
  4876. // just clear the statechar *now*, rather than even diving into
  4877. // the patternList stuff.
  4878. if (options.noext) clearStateChar()
  4879. continue
  4880. case '(':
  4881. if (inClass) {
  4882. re += '('
  4883. continue
  4884. }
  4885. if (!stateChar) {
  4886. re += '\\('
  4887. continue
  4888. }
  4889. plType = stateChar
  4890. patternListStack.push({
  4891. type: plType,
  4892. start: i - 1,
  4893. reStart: re.length
  4894. })
  4895. // negation is (?:(?!js)[^/]*)
  4896. re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
  4897. this.debug('plType %j %j', stateChar, re)
  4898. stateChar = false
  4899. continue
  4900. case ')':
  4901. if (inClass || !patternListStack.length) {
  4902. re += '\\)'
  4903. continue
  4904. }
  4905. clearStateChar()
  4906. hasMagic = true
  4907. re += ')'
  4908. var pl = patternListStack.pop()
  4909. plType = pl.type
  4910. // negation is (?:(?!js)[^/]*)
  4911. // The others are (?:<pattern>)<type>
  4912. switch (plType) {
  4913. case '!':
  4914. negativeLists.push(pl)
  4915. re += ')[^/]*?)'
  4916. pl.reEnd = re.length
  4917. break
  4918. case '?':
  4919. case '+':
  4920. case '*':
  4921. re += plType
  4922. break
  4923. case '@': break // the default anyway
  4924. }
  4925. continue
  4926. case '|':
  4927. if (inClass || !patternListStack.length || escaping) {
  4928. re += '\\|'
  4929. escaping = false
  4930. continue
  4931. }
  4932. clearStateChar()
  4933. re += '|'
  4934. continue
  4935. // these are mostly the same in regexp and glob
  4936. case '[':
  4937. // swallow any state-tracking char before the [
  4938. clearStateChar()
  4939. if (inClass) {
  4940. re += '\\' + c
  4941. continue
  4942. }
  4943. inClass = true
  4944. classStart = i
  4945. reClassStart = re.length
  4946. re += c
  4947. continue
  4948. case ']':
  4949. // a right bracket shall lose its special
  4950. // meaning and represent itself in
  4951. // a bracket expression if it occurs
  4952. // first in the list. -- POSIX.2 2.8.3.2
  4953. if (i === classStart + 1 || !inClass) {
  4954. re += '\\' + c
  4955. escaping = false
  4956. continue
  4957. }
  4958. // handle the case where we left a class open.
  4959. // "[z-a]" is valid, equivalent to "\[z-a\]"
  4960. if (inClass) {
  4961. // split where the last [ was, make sure we don't have
  4962. // an invalid re. if so, re-walk the contents of the
  4963. // would-be class to re-translate any characters that
  4964. // were passed through as-is
  4965. // TODO: It would probably be faster to determine this
  4966. // without a try/catch and a new RegExp, but it's tricky
  4967. // to do safely. For now, this is safe and works.
  4968. var cs = pattern.substring(classStart + 1, i)
  4969. try {
  4970. RegExp('[' + cs + ']')
  4971. } catch (er) {
  4972. // not a valid class!
  4973. var sp = this.parse(cs, SUBPARSE)
  4974. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
  4975. hasMagic = hasMagic || sp[1]
  4976. inClass = false
  4977. continue
  4978. }
  4979. }
  4980. // finish up the class.
  4981. hasMagic = true
  4982. inClass = false
  4983. re += c
  4984. continue
  4985. default:
  4986. // swallow any state char that wasn't consumed
  4987. clearStateChar()
  4988. if (escaping) {
  4989. // no need
  4990. escaping = false
  4991. } else if (reSpecials[c]
  4992. && !(c === '^' && inClass)) {
  4993. re += '\\'
  4994. }
  4995. re += c
  4996. } // switch
  4997. } // for
  4998. // handle the case where we left a class open.
  4999. // "[abc" is valid, equivalent to "\[abc"
  5000. if (inClass) {
  5001. // split where the last [ was, and escape it
  5002. // this is a huge pita. We now have to re-walk
  5003. // the contents of the would-be class to re-translate
  5004. // any characters that were passed through as-is
  5005. cs = pattern.substr(classStart + 1)
  5006. sp = this.parse(cs, SUBPARSE)
  5007. re = re.substr(0, reClassStart) + '\\[' + sp[0]
  5008. hasMagic = hasMagic || sp[1]
  5009. }
  5010. // handle the case where we had a +( thing at the *end*
  5011. // of the pattern.
  5012. // each pattern list stack adds 3 chars, and we need to go through
  5013. // and escape any | chars that were passed through as-is for the regexp.
  5014. // Go through and escape them, taking care not to double-escape any
  5015. // | chars that were already escaped.
  5016. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  5017. var tail = re.slice(pl.reStart + 3)
  5018. // maybe some even number of \, then maybe 1 \, followed by a |
  5019. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  5020. if (!$2) {
  5021. // the | isn't already escaped, so escape it.
  5022. $2 = '\\'
  5023. }
  5024. // need to escape all those slashes *again*, without escaping the
  5025. // one that we need for escaping the | character. As it works out,
  5026. // escaping an even number of slashes can be done by simply repeating
  5027. // it exactly after itself. That's why this trick works.
  5028. //
  5029. // I am sorry that you have to see this.
  5030. return $1 + $1 + $2 + '|'
  5031. })
  5032. this.debug('tail=%j\n %s', tail, tail)
  5033. var t = pl.type === '*' ? star
  5034. : pl.type === '?' ? qmark
  5035. : '\\' + pl.type
  5036. hasMagic = true
  5037. re = re.slice(0, pl.reStart) + t + '\\(' + tail
  5038. }
  5039. // handle trailing things that only matter at the very end.
  5040. clearStateChar()
  5041. if (escaping) {
  5042. // trailing \\
  5043. re += '\\\\'
  5044. }
  5045. // only need to apply the nodot start if the re starts with
  5046. // something that could conceivably capture a dot
  5047. var addPatternStart = false
  5048. switch (re.charAt(0)) {
  5049. case '.':
  5050. case '[':
  5051. case '(': addPatternStart = true
  5052. }
  5053. // Hack to work around lack of negative lookbehind in JS
  5054. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  5055. // like 'a.xyz.yz' doesn't match. So, the first negative
  5056. // lookahead, has to look ALL the way ahead, to the end of
  5057. // the pattern.
  5058. for (var n = negativeLists.length - 1; n > -1; n--) {
  5059. var nl = negativeLists[n]
  5060. var nlBefore = re.slice(0, nl.reStart)
  5061. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8)
  5062. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd)
  5063. var nlAfter = re.slice(nl.reEnd)
  5064. nlLast += nlAfter
  5065. // Handle nested stuff like *(*.js|!(*.json)), where open parens
  5066. // mean that we should *not* include the ) in the bit that is considered
  5067. // "after" the negated section.
  5068. var openParensBefore = nlBefore.split('(').length - 1
  5069. var cleanAfter = nlAfter
  5070. for (i = 0; i < openParensBefore; i++) {
  5071. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '')
  5072. }
  5073. nlAfter = cleanAfter
  5074. var dollar = ''
  5075. if (nlAfter === '' && isSub !== SUBPARSE) {
  5076. dollar = '$'
  5077. }
  5078. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast
  5079. re = newRe
  5080. }
  5081. // if the re is not "" at this point, then we need to make sure
  5082. // it doesn't match against an empty path part.
  5083. // Otherwise a/* will match a/, which it should not.
  5084. if (re !== '' && hasMagic) {
  5085. re = '(?=.)' + re
  5086. }
  5087. if (addPatternStart) {
  5088. re = patternStart + re
  5089. }
  5090. // parsing just a piece of a larger pattern.
  5091. if (isSub === SUBPARSE) {
  5092. return [re, hasMagic]
  5093. }
  5094. // skip the regexp for non-magical patterns
  5095. // unescape anything in it, though, so that it'll be
  5096. // an exact match against a file etc.
  5097. if (!hasMagic) {
  5098. return globUnescape(pattern)
  5099. }
  5100. var flags = options.nocase ? 'i' : ''
  5101. var regExp = new RegExp('^' + re + '$', flags)
  5102. regExp._glob = pattern
  5103. regExp._src = re
  5104. return regExp
  5105. }
  5106. minimatch.makeRe = function (pattern, options) {
  5107. return new Minimatch(pattern, options || {}).makeRe()
  5108. }
  5109. Minimatch.prototype.makeRe = makeRe
  5110. function makeRe () {
  5111. if (this.regexp || this.regexp === false) return this.regexp
  5112. // at this point, this.set is a 2d array of partial
  5113. // pattern strings, or "**".
  5114. //
  5115. // It's better to use .match(). This function shouldn't
  5116. // be used, really, but it's pretty convenient sometimes,
  5117. // when you just want to work with a regex.
  5118. var set = this.set
  5119. if (!set.length) {
  5120. this.regexp = false
  5121. return this.regexp
  5122. }
  5123. var options = this.options
  5124. var twoStar = options.noglobstar ? star
  5125. : options.dot ? twoStarDot
  5126. : twoStarNoDot
  5127. var flags = options.nocase ? 'i' : ''
  5128. var re = set.map(function (pattern) {
  5129. return pattern.map(function (p) {
  5130. return (p === GLOBSTAR) ? twoStar
  5131. : (typeof p === 'string') ? regExpEscape(p)
  5132. : p._src
  5133. }).join('\\\/')
  5134. }).join('|')
  5135. // must match entire pattern
  5136. // ending in a * or ** will make it less strict.
  5137. re = '^(?:' + re + ')$'
  5138. // can match anything, as long as it's not this.
  5139. if (this.negate) re = '^(?!' + re + ').*$'
  5140. try {
  5141. this.regexp = new RegExp(re, flags)
  5142. } catch (ex) {
  5143. this.regexp = false
  5144. }
  5145. return this.regexp
  5146. }
  5147. minimatch.match = function (list, pattern, options) {
  5148. options = options || {}
  5149. var mm = new Minimatch(pattern, options)
  5150. list = list.filter(function (f) {
  5151. return mm.match(f)
  5152. })
  5153. if (mm.options.nonull && !list.length) {
  5154. list.push(pattern)
  5155. }
  5156. return list
  5157. }
  5158. Minimatch.prototype.match = match
  5159. function match (f, partial) {
  5160. this.debug('match', f, this.pattern)
  5161. // short-circuit in the case of busted things.
  5162. // comments, etc.
  5163. if (this.comment) return false
  5164. if (this.empty) return f === ''
  5165. if (f === '/' && partial) return true
  5166. var options = this.options
  5167. // windows: need to use /, not \
  5168. if (path.sep !== '/') {
  5169. f = f.split(path.sep).join('/')
  5170. }
  5171. // treat the test path as a set of pathparts.
  5172. f = f.split(slashSplit)
  5173. this.debug(this.pattern, 'split', f)
  5174. // just ONE of the pattern sets in this.set needs to match
  5175. // in order for it to be valid. If negating, then just one
  5176. // match means that we have failed.
  5177. // Either way, return on the first hit.
  5178. var set = this.set
  5179. this.debug(this.pattern, 'set', set)
  5180. // Find the basename of the path by looking for the last non-empty segment
  5181. var filename
  5182. var i
  5183. for (i = f.length - 1; i >= 0; i--) {
  5184. filename = f[i]
  5185. if (filename) break
  5186. }
  5187. for (i = 0; i < set.length; i++) {
  5188. var pattern = set[i]
  5189. var file = f
  5190. if (options.matchBase && pattern.length === 1) {
  5191. file = [filename]
  5192. }
  5193. var hit = this.matchOne(file, pattern, partial)
  5194. if (hit) {
  5195. if (options.flipNegate) return true
  5196. return !this.negate
  5197. }
  5198. }
  5199. // didn't get any hits. this is success if it's a negative
  5200. // pattern, failure otherwise.
  5201. if (options.flipNegate) return false
  5202. return this.negate
  5203. }
  5204. // set partial to true to test if, for example,
  5205. // "/a/b" matches the start of "/*/b/*/d"
  5206. // Partial means, if you run out of file before you run
  5207. // out of pattern, then that's fine, as long as all
  5208. // the parts match.
  5209. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  5210. var options = this.options
  5211. this.debug('matchOne',
  5212. { 'this': this, file: file, pattern: pattern })
  5213. this.debug('matchOne', file.length, pattern.length)
  5214. for (var fi = 0,
  5215. pi = 0,
  5216. fl = file.length,
  5217. pl = pattern.length
  5218. ; (fi < fl) && (pi < pl)
  5219. ; fi++, pi++) {
  5220. this.debug('matchOne loop')
  5221. var p = pattern[pi]
  5222. var f = file[fi]
  5223. this.debug(pattern, p, f)
  5224. // should be impossible.
  5225. // some invalid regexp stuff in the set.
  5226. if (p === false) return false
  5227. if (p === GLOBSTAR) {
  5228. this.debug('GLOBSTAR', [pattern, p, f])
  5229. // "**"
  5230. // a/**/b/**/c would match the following:
  5231. // a/b/x/y/z/c
  5232. // a/x/y/z/b/c
  5233. // a/b/x/b/x/c
  5234. // a/b/c
  5235. // To do this, take the rest of the pattern after
  5236. // the **, and see if it would match the file remainder.
  5237. // If so, return success.
  5238. // If not, the ** "swallows" a segment, and try again.
  5239. // This is recursively awful.
  5240. //
  5241. // a/**/b/**/c matching a/b/x/y/z/c
  5242. // - a matches a
  5243. // - doublestar
  5244. // - matchOne(b/x/y/z/c, b/**/c)
  5245. // - b matches b
  5246. // - doublestar
  5247. // - matchOne(x/y/z/c, c) -> no
  5248. // - matchOne(y/z/c, c) -> no
  5249. // - matchOne(z/c, c) -> no
  5250. // - matchOne(c, c) yes, hit
  5251. var fr = fi
  5252. var pr = pi + 1
  5253. if (pr === pl) {
  5254. this.debug('** at the end')
  5255. // a ** at the end will just swallow the rest.
  5256. // We have found a match.
  5257. // however, it will not swallow /.x, unless
  5258. // options.dot is set.
  5259. // . and .. are *never* matched by **, for explosively
  5260. // exponential reasons.
  5261. for (; fi < fl; fi++) {
  5262. if (file[fi] === '.' || file[fi] === '..' ||
  5263. (!options.dot && file[fi].charAt(0) === '.')) return false
  5264. }
  5265. return true
  5266. }
  5267. // ok, let's see if we can swallow whatever we can.
  5268. while (fr < fl) {
  5269. var swallowee = file[fr]
  5270. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee)
  5271. // XXX remove this slice. Just pass the start index.
  5272. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  5273. this.debug('globstar found match!', fr, fl, swallowee)
  5274. // found a match.
  5275. return true
  5276. } else {
  5277. // can't swallow "." or ".." ever.
  5278. // can only swallow ".foo" when explicitly asked.
  5279. if (swallowee === '.' || swallowee === '..' ||
  5280. (!options.dot && swallowee.charAt(0) === '.')) {
  5281. this.debug('dot detected!', file, fr, pattern, pr)
  5282. break
  5283. }
  5284. // ** swallows a segment, and continue.
  5285. this.debug('globstar swallow a segment, and continue')
  5286. fr++
  5287. }
  5288. }
  5289. // no match was found.
  5290. // However, in partial mode, we can't say this is necessarily over.
  5291. // If there's more *pattern* left, then
  5292. if (partial) {
  5293. // ran out of file
  5294. this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
  5295. if (fr === fl) return true
  5296. }
  5297. return false
  5298. }
  5299. // something other than **
  5300. // non-magic patterns just have to match exactly
  5301. // patterns with magic have been turned into regexps.
  5302. var hit
  5303. if (typeof p === 'string') {
  5304. if (options.nocase) {
  5305. hit = f.toLowerCase() === p.toLowerCase()
  5306. } else {
  5307. hit = f === p
  5308. }
  5309. this.debug('string match', p, f, hit)
  5310. } else {
  5311. hit = f.match(p)
  5312. this.debug('pattern match', p, f, hit)
  5313. }
  5314. if (!hit) return false
  5315. }
  5316. // Note: ending in / means that we'll get a final ""
  5317. // at the end of the pattern. This can only match a
  5318. // corresponding "" at the end of the file.
  5319. // If the file ends in /, then it can only match a
  5320. // a pattern that ends in /, unless the pattern just
  5321. // doesn't have any more for it. But, a/b/ should *not*
  5322. // match "a/b/*", even though "" matches against the
  5323. // [^/]*? pattern, except in partial mode, where it might
  5324. // simply not be reached yet.
  5325. // However, a/b/ should still satisfy a/*
  5326. // now either we fell off the end of the pattern, or we're done.
  5327. if (fi === fl && pi === pl) {
  5328. // ran out of pattern and filename at the same time.
  5329. // an exact hit!
  5330. return true
  5331. } else if (fi === fl) {
  5332. // ran out of file, but still had pattern left.
  5333. // this is ok if we're doing the match as part of
  5334. // a glob fs traversal.
  5335. return partial
  5336. } else if (pi === pl) {
  5337. // ran out of pattern, still have file left.
  5338. // this is only acceptable if we're on the very last
  5339. // empty segment of a file with a trailing slash.
  5340. // a/* should match a/b/
  5341. var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
  5342. return emptyFileEnd
  5343. }
  5344. // should be unreachable.
  5345. throw new Error('wtf?')
  5346. }
  5347. // replace stuff like \* with *
  5348. function globUnescape (s) {
  5349. return s.replace(/\\(.)/g, '$1')
  5350. }
  5351. function regExpEscape (s) {
  5352. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
  5353. }
  5354. /***/ },
  5355. /* 41 */
  5356. /***/ function(module, exports, __webpack_require__) {
  5357. module.exports = __webpack_require__(9).inherits
  5358. /***/ },
  5359. /* 42 */
  5360. /***/ function(module, exports, __webpack_require__) {
  5361. module.exports = globSync
  5362. globSync.GlobSync = GlobSync
  5363. var fs = __webpack_require__(2)
  5364. var minimatch = __webpack_require__(40)
  5365. var Minimatch = minimatch.Minimatch
  5366. var Glob = __webpack_require__(39).Glob
  5367. var util = __webpack_require__(9)
  5368. var path = __webpack_require__(4)
  5369. var assert = __webpack_require__(11)
  5370. var isAbsolute = __webpack_require__(12)
  5371. var common = __webpack_require__(43)
  5372. var alphasort = common.alphasort
  5373. var alphasorti = common.alphasorti
  5374. var setopts = common.setopts
  5375. var ownProp = common.ownProp
  5376. var childrenIgnored = common.childrenIgnored
  5377. function globSync (pattern, options) {
  5378. if (typeof options === 'function' || arguments.length === 3)
  5379. throw new TypeError('callback provided to sync glob\n'+
  5380. 'See: https://github.com/isaacs/node-glob/issues/167')
  5381. return new GlobSync(pattern, options).found
  5382. }
  5383. function GlobSync (pattern, options) {
  5384. if (!pattern)
  5385. throw new Error('must provide pattern')
  5386. if (typeof options === 'function' || arguments.length === 3)
  5387. throw new TypeError('callback provided to sync glob\n'+
  5388. 'See: https://github.com/isaacs/node-glob/issues/167')
  5389. if (!(this instanceof GlobSync))
  5390. return new GlobSync(pattern, options)
  5391. setopts(this, pattern, options)
  5392. if (this.noprocess)
  5393. return this
  5394. var n = this.minimatch.set.length
  5395. this.matches = new Array(n)
  5396. for (var i = 0; i < n; i ++) {
  5397. this._process(this.minimatch.set[i], i, false)
  5398. }
  5399. this._finish()
  5400. }
  5401. GlobSync.prototype._finish = function () {
  5402. assert(this instanceof GlobSync)
  5403. if (this.realpath) {
  5404. var self = this
  5405. this.matches.forEach(function (matchset, index) {
  5406. var set = self.matches[index] = Object.create(null)
  5407. for (var p in matchset) {
  5408. try {
  5409. p = self._makeAbs(p)
  5410. var real = fs.realpathSync(p, self.realpathCache)
  5411. set[real] = true
  5412. } catch (er) {
  5413. if (er.syscall === 'stat')
  5414. set[self._makeAbs(p)] = true
  5415. else
  5416. throw er
  5417. }
  5418. }
  5419. })
  5420. }
  5421. common.finish(this)
  5422. }
  5423. GlobSync.prototype._process = function (pattern, index, inGlobStar) {
  5424. assert(this instanceof GlobSync)
  5425. // Get the first [n] parts of pattern that are all strings.
  5426. var n = 0
  5427. while (typeof pattern[n] === 'string') {
  5428. n ++
  5429. }
  5430. // now n is the index of the first one that is *not* a string.
  5431. // See if there's anything else
  5432. var prefix
  5433. switch (n) {
  5434. // if not, then this is rather simple
  5435. case pattern.length:
  5436. this._processSimple(pattern.join('/'), index)
  5437. return
  5438. case 0:
  5439. // pattern *starts* with some non-trivial item.
  5440. // going to readdir(cwd), but not include the prefix in matches.
  5441. prefix = null
  5442. break
  5443. default:
  5444. // pattern has some string bits in the front.
  5445. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  5446. // or 'relative' like '../baz'
  5447. prefix = pattern.slice(0, n).join('/')
  5448. break
  5449. }
  5450. var remain = pattern.slice(n)
  5451. // get the list of entries.
  5452. var read
  5453. if (prefix === null)
  5454. read = '.'
  5455. else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
  5456. if (!prefix || !isAbsolute(prefix))
  5457. prefix = '/' + prefix
  5458. read = prefix
  5459. } else
  5460. read = prefix
  5461. var abs = this._makeAbs(read)
  5462. //if ignored, skip processing
  5463. if (childrenIgnored(this, read))
  5464. return
  5465. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  5466. if (isGlobStar)
  5467. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar)
  5468. else
  5469. this._processReaddir(prefix, read, abs, remain, index, inGlobStar)
  5470. }
  5471. GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  5472. var entries = this._readdir(abs, inGlobStar)
  5473. // if the abs isn't a dir, then nothing can match!
  5474. if (!entries)
  5475. return
  5476. // It will only match dot entries if it starts with a dot, or if
  5477. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  5478. var pn = remain[0]
  5479. var negate = !!this.minimatch.negate
  5480. var rawGlob = pn._glob
  5481. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  5482. var matchedEntries = []
  5483. for (var i = 0; i < entries.length; i++) {
  5484. var e = entries[i]
  5485. if (e.charAt(0) !== '.' || dotOk) {
  5486. var m
  5487. if (negate && !prefix) {
  5488. m = !e.match(pn)
  5489. } else {
  5490. m = e.match(pn)
  5491. }
  5492. if (m)
  5493. matchedEntries.push(e)
  5494. }
  5495. }
  5496. var len = matchedEntries.length
  5497. // If there are no matched entries, then nothing matches.
  5498. if (len === 0)
  5499. return
  5500. // if this is the last remaining pattern bit, then no need for
  5501. // an additional stat *unless* the user has specified mark or
  5502. // stat explicitly. We know they exist, since readdir returned
  5503. // them.
  5504. if (remain.length === 1 && !this.mark && !this.stat) {
  5505. if (!this.matches[index])
  5506. this.matches[index] = Object.create(null)
  5507. for (var i = 0; i < len; i ++) {
  5508. var e = matchedEntries[i]
  5509. if (prefix) {
  5510. if (prefix.slice(-1) !== '/')
  5511. e = prefix + '/' + e
  5512. else
  5513. e = prefix + e
  5514. }
  5515. if (e.charAt(0) === '/' && !this.nomount) {
  5516. e = path.join(this.root, e)
  5517. }
  5518. this.matches[index][e] = true
  5519. }
  5520. // This was the last one, and no stats were needed
  5521. return
  5522. }
  5523. // now test all matched entries as stand-ins for that part
  5524. // of the pattern.
  5525. remain.shift()
  5526. for (var i = 0; i < len; i ++) {
  5527. var e = matchedEntries[i]
  5528. var newPattern
  5529. if (prefix)
  5530. newPattern = [prefix, e]
  5531. else
  5532. newPattern = [e]
  5533. this._process(newPattern.concat(remain), index, inGlobStar)
  5534. }
  5535. }
  5536. GlobSync.prototype._emitMatch = function (index, e) {
  5537. var abs = this._makeAbs(e)
  5538. if (this.mark)
  5539. e = this._mark(e)
  5540. if (this.matches[index][e])
  5541. return
  5542. if (this.nodir) {
  5543. var c = this.cache[this._makeAbs(e)]
  5544. if (c === 'DIR' || Array.isArray(c))
  5545. return
  5546. }
  5547. this.matches[index][e] = true
  5548. if (this.stat)
  5549. this._stat(e)
  5550. }
  5551. GlobSync.prototype._readdirInGlobStar = function (abs) {
  5552. // follow all symlinked directories forever
  5553. // just proceed as if this is a non-globstar situation
  5554. if (this.follow)
  5555. return this._readdir(abs, false)
  5556. var entries
  5557. var lstat
  5558. var stat
  5559. try {
  5560. lstat = fs.lstatSync(abs)
  5561. } catch (er) {
  5562. // lstat failed, doesn't exist
  5563. return null
  5564. }
  5565. var isSym = lstat.isSymbolicLink()
  5566. this.symlinks[abs] = isSym
  5567. // If it's not a symlink or a dir, then it's definitely a regular file.
  5568. // don't bother doing a readdir in that case.
  5569. if (!isSym && !lstat.isDirectory())
  5570. this.cache[abs] = 'FILE'
  5571. else
  5572. entries = this._readdir(abs, false)
  5573. return entries
  5574. }
  5575. GlobSync.prototype._readdir = function (abs, inGlobStar) {
  5576. var entries
  5577. if (inGlobStar && !ownProp(this.symlinks, abs))
  5578. return this._readdirInGlobStar(abs)
  5579. if (ownProp(this.cache, abs)) {
  5580. var c = this.cache[abs]
  5581. if (!c || c === 'FILE')
  5582. return null
  5583. if (Array.isArray(c))
  5584. return c
  5585. }
  5586. try {
  5587. return this._readdirEntries(abs, fs.readdirSync(abs))
  5588. } catch (er) {
  5589. this._readdirError(abs, er)
  5590. return null
  5591. }
  5592. }
  5593. GlobSync.prototype._readdirEntries = function (abs, entries) {
  5594. // if we haven't asked to stat everything, then just
  5595. // assume that everything in there exists, so we can avoid
  5596. // having to stat it a second time.
  5597. if (!this.mark && !this.stat) {
  5598. for (var i = 0; i < entries.length; i ++) {
  5599. var e = entries[i]
  5600. if (abs === '/')
  5601. e = abs + e
  5602. else
  5603. e = abs + '/' + e
  5604. this.cache[e] = true
  5605. }
  5606. }
  5607. this.cache[abs] = entries
  5608. // mark and cache dir-ness
  5609. return entries
  5610. }
  5611. GlobSync.prototype._readdirError = function (f, er) {
  5612. // handle errors, and cache the information
  5613. switch (er.code) {
  5614. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  5615. case 'ENOTDIR': // totally normal. means it *does* exist.
  5616. this.cache[this._makeAbs(f)] = 'FILE'
  5617. if (f === this.cwd) {
  5618. var error = new Error(er.code + ' invalid cwd ' + f)
  5619. error.path = f
  5620. error.code = er.code
  5621. throw error
  5622. }
  5623. break
  5624. case 'ENOENT': // not terribly unusual
  5625. case 'ELOOP':
  5626. case 'ENAMETOOLONG':
  5627. case 'UNKNOWN':
  5628. this.cache[this._makeAbs(f)] = false
  5629. break
  5630. default: // some unusual error. Treat as failure.
  5631. this.cache[this._makeAbs(f)] = false
  5632. if (this.strict)
  5633. throw er
  5634. if (!this.silent)
  5635. console.error('glob error', er)
  5636. break
  5637. }
  5638. }
  5639. GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  5640. var entries = this._readdir(abs, inGlobStar)
  5641. // no entries means not a dir, so it can never have matches
  5642. // foo.txt/** doesn't match foo.txt
  5643. if (!entries)
  5644. return
  5645. // test without the globstar, and with every child both below
  5646. // and replacing the globstar.
  5647. var remainWithoutGlobStar = remain.slice(1)
  5648. var gspref = prefix ? [ prefix ] : []
  5649. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  5650. // the noGlobStar pattern exits the inGlobStar state
  5651. this._process(noGlobStar, index, false)
  5652. var len = entries.length
  5653. var isSym = this.symlinks[abs]
  5654. // If it's a symlink, and we're in a globstar, then stop
  5655. if (isSym && inGlobStar)
  5656. return
  5657. for (var i = 0; i < len; i++) {
  5658. var e = entries[i]
  5659. if (e.charAt(0) === '.' && !this.dot)
  5660. continue
  5661. // these two cases enter the inGlobStar state
  5662. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  5663. this._process(instead, index, true)
  5664. var below = gspref.concat(entries[i], remain)
  5665. this._process(below, index, true)
  5666. }
  5667. }
  5668. GlobSync.prototype._processSimple = function (prefix, index) {
  5669. // XXX review this. Shouldn't it be doing the mounting etc
  5670. // before doing stat? kinda weird?
  5671. var exists = this._stat(prefix)
  5672. if (!this.matches[index])
  5673. this.matches[index] = Object.create(null)
  5674. // If it doesn't exist, then just mark the lack of results
  5675. if (!exists)
  5676. return
  5677. if (prefix && isAbsolute(prefix) && !this.nomount) {
  5678. var trail = /[\/\\]$/.test(prefix)
  5679. if (prefix.charAt(0) === '/') {
  5680. prefix = path.join(this.root, prefix)
  5681. } else {
  5682. prefix = path.resolve(this.root, prefix)
  5683. if (trail)
  5684. prefix += '/'
  5685. }
  5686. }
  5687. if (process.platform === 'win32')
  5688. prefix = prefix.replace(/\\/g, '/')
  5689. // Mark this as a match
  5690. this.matches[index][prefix] = true
  5691. }
  5692. // Returns either 'DIR', 'FILE', or false
  5693. GlobSync.prototype._stat = function (f) {
  5694. var abs = this._makeAbs(f)
  5695. var needDir = f.slice(-1) === '/'
  5696. if (f.length > this.maxLength)
  5697. return false
  5698. if (!this.stat && ownProp(this.cache, abs)) {
  5699. var c = this.cache[abs]
  5700. if (Array.isArray(c))
  5701. c = 'DIR'
  5702. // It exists, but maybe not how we need it
  5703. if (!needDir || c === 'DIR')
  5704. return c
  5705. if (needDir && c === 'FILE')
  5706. return false
  5707. // otherwise we have to stat, because maybe c=true
  5708. // if we know it exists, but not what it is.
  5709. }
  5710. var exists
  5711. var stat = this.statCache[abs]
  5712. if (!stat) {
  5713. var lstat
  5714. try {
  5715. lstat = fs.lstatSync(abs)
  5716. } catch (er) {
  5717. return false
  5718. }
  5719. if (lstat.isSymbolicLink()) {
  5720. try {
  5721. stat = fs.statSync(abs)
  5722. } catch (er) {
  5723. stat = lstat
  5724. }
  5725. } else {
  5726. stat = lstat
  5727. }
  5728. }
  5729. this.statCache[abs] = stat
  5730. var c = stat.isDirectory() ? 'DIR' : 'FILE'
  5731. this.cache[abs] = this.cache[abs] || c
  5732. if (needDir && c !== 'DIR')
  5733. return false
  5734. return c
  5735. }
  5736. GlobSync.prototype._mark = function (p) {
  5737. return common.mark(this, p)
  5738. }
  5739. GlobSync.prototype._makeAbs = function (f) {
  5740. return common.makeAbs(this, f)
  5741. }
  5742. /***/ },
  5743. /* 43 */
  5744. /***/ function(module, exports, __webpack_require__) {
  5745. exports.alphasort = alphasort
  5746. exports.alphasorti = alphasorti
  5747. exports.setopts = setopts
  5748. exports.ownProp = ownProp
  5749. exports.makeAbs = makeAbs
  5750. exports.finish = finish
  5751. exports.mark = mark
  5752. exports.isIgnored = isIgnored
  5753. exports.childrenIgnored = childrenIgnored
  5754. function ownProp (obj, field) {
  5755. return Object.prototype.hasOwnProperty.call(obj, field)
  5756. }
  5757. var path = __webpack_require__(4)
  5758. var minimatch = __webpack_require__(40)
  5759. var isAbsolute = __webpack_require__(12)
  5760. var Minimatch = minimatch.Minimatch
  5761. function alphasorti (a, b) {
  5762. return a.toLowerCase().localeCompare(b.toLowerCase())
  5763. }
  5764. function alphasort (a, b) {
  5765. return a.localeCompare(b)
  5766. }
  5767. function setupIgnores (self, options) {
  5768. self.ignore = options.ignore || []
  5769. if (!Array.isArray(self.ignore))
  5770. self.ignore = [self.ignore]
  5771. if (self.ignore.length) {
  5772. self.ignore = self.ignore.map(ignoreMap)
  5773. }
  5774. }
  5775. // ignore patterns are always in dot:true mode.
  5776. function ignoreMap (pattern) {
  5777. var gmatcher = null
  5778. if (pattern.slice(-3) === '/**') {
  5779. var gpattern = pattern.replace(/(\/\*\*)+$/, '')
  5780. gmatcher = new Minimatch(gpattern, { dot: true })
  5781. }
  5782. return {
  5783. matcher: new Minimatch(pattern, { dot: true }),
  5784. gmatcher: gmatcher
  5785. }
  5786. }
  5787. function setopts (self, pattern, options) {
  5788. if (!options)
  5789. options = {}
  5790. // base-matching: just use globstar for that.
  5791. if (options.matchBase && -1 === pattern.indexOf("/")) {
  5792. if (options.noglobstar) {
  5793. throw new Error("base matching requires globstar")
  5794. }
  5795. pattern = "**/" + pattern
  5796. }
  5797. self.silent = !!options.silent
  5798. self.pattern = pattern
  5799. self.strict = options.strict !== false
  5800. self.realpath = !!options.realpath
  5801. self.realpathCache = options.realpathCache || Object.create(null)
  5802. self.follow = !!options.follow
  5803. self.dot = !!options.dot
  5804. self.mark = !!options.mark
  5805. self.nodir = !!options.nodir
  5806. if (self.nodir)
  5807. self.mark = true
  5808. self.sync = !!options.sync
  5809. self.nounique = !!options.nounique
  5810. self.nonull = !!options.nonull
  5811. self.nosort = !!options.nosort
  5812. self.nocase = !!options.nocase
  5813. self.stat = !!options.stat
  5814. self.noprocess = !!options.noprocess
  5815. self.maxLength = options.maxLength || Infinity
  5816. self.cache = options.cache || Object.create(null)
  5817. self.statCache = options.statCache || Object.create(null)
  5818. self.symlinks = options.symlinks || Object.create(null)
  5819. setupIgnores(self, options)
  5820. self.changedCwd = false
  5821. var cwd = process.cwd()
  5822. if (!ownProp(options, "cwd"))
  5823. self.cwd = cwd
  5824. else {
  5825. self.cwd = path.resolve(options.cwd)
  5826. self.changedCwd = self.cwd !== cwd
  5827. }
  5828. self.root = options.root || path.resolve(self.cwd, "/")
  5829. self.root = path.resolve(self.root)
  5830. if (process.platform === "win32")
  5831. self.root = self.root.replace(/\\/g, "/")
  5832. self.nomount = !!options.nomount
  5833. // disable comments and negation in Minimatch.
  5834. // Note that they are not supported in Glob itself anyway.
  5835. options.nonegate = true
  5836. options.nocomment = true
  5837. self.minimatch = new Minimatch(pattern, options)
  5838. self.options = self.minimatch.options
  5839. }
  5840. function finish (self) {
  5841. var nou = self.nounique
  5842. var all = nou ? [] : Object.create(null)
  5843. for (var i = 0, l = self.matches.length; i < l; i ++) {
  5844. var matches = self.matches[i]
  5845. if (!matches || Object.keys(matches).length === 0) {
  5846. if (self.nonull) {
  5847. // do like the shell, and spit out the literal glob
  5848. var literal = self.minimatch.globSet[i]
  5849. if (nou)
  5850. all.push(literal)
  5851. else
  5852. all[literal] = true
  5853. }
  5854. } else {
  5855. // had matches
  5856. var m = Object.keys(matches)
  5857. if (nou)
  5858. all.push.apply(all, m)
  5859. else
  5860. m.forEach(function (m) {
  5861. all[m] = true
  5862. })
  5863. }
  5864. }
  5865. if (!nou)
  5866. all = Object.keys(all)
  5867. if (!self.nosort)
  5868. all = all.sort(self.nocase ? alphasorti : alphasort)
  5869. // at *some* point we statted all of these
  5870. if (self.mark) {
  5871. for (var i = 0; i < all.length; i++) {
  5872. all[i] = self._mark(all[i])
  5873. }
  5874. if (self.nodir) {
  5875. all = all.filter(function (e) {
  5876. return !(/\/$/.test(e))
  5877. })
  5878. }
  5879. }
  5880. if (self.ignore.length)
  5881. all = all.filter(function(m) {
  5882. return !isIgnored(self, m)
  5883. })
  5884. self.found = all
  5885. }
  5886. function mark (self, p) {
  5887. var abs = makeAbs(self, p)
  5888. var c = self.cache[abs]
  5889. var m = p
  5890. if (c) {
  5891. var isDir = c === 'DIR' || Array.isArray(c)
  5892. var slash = p.slice(-1) === '/'
  5893. if (isDir && !slash)
  5894. m += '/'
  5895. else if (!isDir && slash)
  5896. m = m.slice(0, -1)
  5897. if (m !== p) {
  5898. var mabs = makeAbs(self, m)
  5899. self.statCache[mabs] = self.statCache[abs]
  5900. self.cache[mabs] = self.cache[abs]
  5901. }
  5902. }
  5903. return m
  5904. }
  5905. // lotta situps...
  5906. function makeAbs (self, f) {
  5907. var abs = f
  5908. if (f.charAt(0) === '/') {
  5909. abs = path.join(self.root, f)
  5910. } else if (isAbsolute(f) || f === '') {
  5911. abs = f
  5912. } else if (self.changedCwd) {
  5913. abs = path.resolve(self.cwd, f)
  5914. } else {
  5915. abs = path.resolve(f)
  5916. }
  5917. return abs
  5918. }
  5919. // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  5920. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  5921. function isIgnored (self, path) {
  5922. if (!self.ignore.length)
  5923. return false
  5924. return self.ignore.some(function(item) {
  5925. return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path))
  5926. })
  5927. }
  5928. function childrenIgnored (self, path) {
  5929. if (!self.ignore.length)
  5930. return false
  5931. return self.ignore.some(function(item) {
  5932. return !!(item.gmatcher && item.gmatcher.match(path))
  5933. })
  5934. }
  5935. /***/ },
  5936. /* 44 */
  5937. /***/ function(module, exports, __webpack_require__) {
  5938. var jsonFile = __webpack_require__(45)
  5939. jsonFile.outputJsonSync = __webpack_require__(47)
  5940. jsonFile.outputJson = __webpack_require__(48)
  5941. // aliases
  5942. jsonFile.outputJSONSync = __webpack_require__(47)
  5943. jsonFile.outputJSON = __webpack_require__(48)
  5944. module.exports = jsonFile
  5945. /***/ },
  5946. /* 45 */
  5947. /***/ function(module, exports, __webpack_require__) {
  5948. var jsonFile = __webpack_require__(46)
  5949. module.exports = {
  5950. // jsonfile exports
  5951. readJson: jsonFile.readFile,
  5952. readJSON: jsonFile.readFile,
  5953. readJsonSync: jsonFile.readFileSync,
  5954. readJSONSync: jsonFile.readFileSync,
  5955. writeJson: jsonFile.writeFile,
  5956. writeJSON: jsonFile.writeFile,
  5957. writeJsonSync: jsonFile.writeFileSync,
  5958. writeJSONSync: jsonFile.writeFileSync,
  5959. spaces: 2 // default in fs-extra
  5960. }
  5961. /***/ },
  5962. /* 46 */
  5963. /***/ function(module, exports, __webpack_require__) {
  5964. var fs = __webpack_require__(2)
  5965. function readFile (file, options, callback) {
  5966. if (callback == null) {
  5967. callback = options
  5968. options = {}
  5969. }
  5970. fs.readFile(file, options, function (err, data) {
  5971. if (err) return callback(err)
  5972. var obj
  5973. try {
  5974. obj = JSON.parse(data, options ? options.reviver : null)
  5975. } catch (err2) {
  5976. err2.message = file + ': ' + err2.message
  5977. return callback(err2)
  5978. }
  5979. callback(null, obj)
  5980. })
  5981. }
  5982. function readFileSync (file, options) {
  5983. options = options || {}
  5984. if (typeof options === 'string') {
  5985. options = {encoding: options}
  5986. }
  5987. var shouldThrow = 'throws' in options ? options.throws : true
  5988. var content = fs.readFileSync(file, options)
  5989. try {
  5990. return JSON.parse(content, options.reviver)
  5991. } catch (err) {
  5992. if (shouldThrow) {
  5993. err.message = file + ': ' + err.message
  5994. throw err
  5995. } else {
  5996. return null
  5997. }
  5998. }
  5999. }
  6000. function writeFile (file, obj, options, callback) {
  6001. if (callback == null) {
  6002. callback = options
  6003. options = {}
  6004. }
  6005. var spaces = typeof options === 'object' && options !== null
  6006. ? 'spaces' in options
  6007. ? options.spaces : this.spaces
  6008. : this.spaces
  6009. var str = ''
  6010. try {
  6011. str = JSON.stringify(obj, options ? options.replacer : null, spaces) + '\n'
  6012. } catch (err) {
  6013. if (callback) return callback(err, null)
  6014. }
  6015. fs.writeFile(file, str, options, callback)
  6016. }
  6017. function writeFileSync (file, obj, options) {
  6018. options = options || {}
  6019. var spaces = typeof options === 'object' && options !== null
  6020. ? 'spaces' in options
  6021. ? options.spaces : this.spaces
  6022. : this.spaces
  6023. var str = JSON.stringify(obj, options.replacer, spaces) + '\n'
  6024. // not sure if fs.writeFileSync returns anything, but just in case
  6025. return fs.writeFileSync(file, str, options)
  6026. }
  6027. var jsonfile = {
  6028. spaces: null,
  6029. readFile: readFile,
  6030. readFileSync: readFileSync,
  6031. writeFile: writeFile,
  6032. writeFileSync: writeFileSync
  6033. }
  6034. module.exports = jsonfile
  6035. /***/ },
  6036. /* 47 */
  6037. /***/ function(module, exports, __webpack_require__) {
  6038. var fs = __webpack_require__(20)
  6039. var path = __webpack_require__(4)
  6040. var jsonFile = __webpack_require__(45)
  6041. var mkdir = __webpack_require__(31)
  6042. function outputJsonSync (file, data, options) {
  6043. var dir = path.dirname(file)
  6044. if (!fs.existsSync(dir)) {
  6045. mkdir.mkdirsSync(dir)
  6046. }
  6047. jsonFile.writeJsonSync(file, data, options)
  6048. }
  6049. module.exports = outputJsonSync
  6050. /***/ },
  6051. /* 48 */
  6052. /***/ function(module, exports, __webpack_require__) {
  6053. var fs = __webpack_require__(20)
  6054. var path = __webpack_require__(4)
  6055. var jsonFile = __webpack_require__(45)
  6056. var mkdir = __webpack_require__(31)
  6057. function outputJson (file, data, options, callback) {
  6058. if (typeof options === 'function') {
  6059. callback = options
  6060. options = {}
  6061. }
  6062. var dir = path.dirname(file)
  6063. fs.exists(dir, function (itDoes) {
  6064. if (itDoes) return jsonFile.writeJson(file, data, options, callback)
  6065. mkdir.mkdirs(dir, function (err) {
  6066. if (err) return callback(err)
  6067. jsonFile.writeJson(file, data, options, callback)
  6068. })
  6069. })
  6070. }
  6071. module.exports = outputJson
  6072. /***/ },
  6073. /* 49 */
  6074. /***/ function(module, exports, __webpack_require__) {
  6075. // most of this code was written by Andrew Kelley
  6076. // licensed under the BSD license: see
  6077. // https://github.com/andrewrk/node-mv/blob/master/package.json
  6078. // this needs a cleanup
  6079. var fs = __webpack_require__(20)
  6080. var ncp = __webpack_require__(28)
  6081. var path = __webpack_require__(4)
  6082. var rimraf = __webpack_require__(38)
  6083. var mkdirp = __webpack_require__(31).mkdirs
  6084. function mv (source, dest, options, callback) {
  6085. if (typeof options === 'function') {
  6086. callback = options
  6087. options = {}
  6088. }
  6089. var shouldMkdirp = ('mkdirp' in options) ? options.mkdirp : true
  6090. var clobber = ('clobber' in options) ? options.clobber : false
  6091. var limit = options.limit || 16
  6092. if (shouldMkdirp) {
  6093. mkdirs()
  6094. } else {
  6095. doRename()
  6096. }
  6097. function mkdirs () {
  6098. mkdirp(path.dirname(dest), function (err) {
  6099. if (err) return callback(err)
  6100. doRename()
  6101. })
  6102. }
  6103. function doRename () {
  6104. if (clobber) {
  6105. fs.rename(source, dest, function (err) {
  6106. if (!err) return callback()
  6107. if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST') {
  6108. rimraf(dest, function (err) {
  6109. if (err) return callback(err)
  6110. options.clobber = false // just clobbered it, no need to do it again
  6111. mv(source, dest, options, callback)
  6112. })
  6113. return
  6114. }
  6115. // weird Windows shit
  6116. if (err.code === 'EPERM') {
  6117. setTimeout(function () {
  6118. rimraf(dest, function (err) {
  6119. if (err) return callback(err)
  6120. options.clobber = false
  6121. mv(source, dest, options, callback)
  6122. })
  6123. }, 200)
  6124. return
  6125. }
  6126. if (err.code !== 'EXDEV') return callback(err)
  6127. moveAcrossDevice(source, dest, clobber, limit, callback)
  6128. })
  6129. } else {
  6130. fs.link(source, dest, function (err) {
  6131. if (err) {
  6132. if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM') {
  6133. moveAcrossDevice(source, dest, clobber, limit, callback)
  6134. return
  6135. }
  6136. callback(err)
  6137. return
  6138. }
  6139. fs.unlink(source, callback)
  6140. })
  6141. }
  6142. }
  6143. }
  6144. function moveAcrossDevice (source, dest, clobber, limit, callback) {
  6145. fs.stat(source, function (err, stat) {
  6146. if (err) {
  6147. callback(err)
  6148. return
  6149. }
  6150. if (stat.isDirectory()) {
  6151. moveDirAcrossDevice(source, dest, clobber, limit, callback)
  6152. } else {
  6153. moveFileAcrossDevice(source, dest, clobber, limit, callback)
  6154. }
  6155. })
  6156. }
  6157. function moveFileAcrossDevice (source, dest, clobber, limit, callback) {
  6158. var outFlags = clobber ? 'w' : 'wx'
  6159. var ins = fs.createReadStream(source)
  6160. var outs = fs.createWriteStream(dest, {flags: outFlags})
  6161. ins.on('error', function (err) {
  6162. ins.destroy()
  6163. outs.destroy()
  6164. outs.removeListener('close', onClose)
  6165. // may want to create a directory but `out` line above
  6166. // creates an empty file for us: See #108
  6167. // don't care about error here
  6168. fs.unlink(dest, function () {
  6169. // note: `err` here is from the input stream errror
  6170. if (err.code === 'EISDIR' || err.code === 'EPERM') {
  6171. moveDirAcrossDevice(source, dest, clobber, limit, callback)
  6172. } else {
  6173. callback(err)
  6174. }
  6175. })
  6176. })
  6177. outs.on('error', function (err) {
  6178. ins.destroy()
  6179. outs.destroy()
  6180. outs.removeListener('close', onClose)
  6181. callback(err)
  6182. })
  6183. outs.once('close', onClose)
  6184. ins.pipe(outs)
  6185. function onClose () {
  6186. fs.unlink(source, callback)
  6187. }
  6188. }
  6189. function moveDirAcrossDevice (source, dest, clobber, limit, callback) {
  6190. var options = {
  6191. stopOnErr: true,
  6192. clobber: false,
  6193. limit: limit
  6194. }
  6195. function startNcp () {
  6196. ncp(source, dest, options, function (errList) {
  6197. if (errList) return callback(errList[0])
  6198. rimraf(source, callback)
  6199. })
  6200. }
  6201. if (clobber) {
  6202. rimraf(dest, function (err) {
  6203. if (err) return callback(err)
  6204. startNcp()
  6205. })
  6206. } else {
  6207. startNcp()
  6208. }
  6209. }
  6210. module.exports = {
  6211. move: mv
  6212. }
  6213. /***/ },
  6214. /* 50 */
  6215. /***/ function(module, exports, __webpack_require__) {
  6216. module.exports = {
  6217. createOutputStream: __webpack_require__(51)
  6218. }
  6219. /***/ },
  6220. /* 51 */
  6221. /***/ function(module, exports, __webpack_require__) {
  6222. var path = __webpack_require__(4)
  6223. var fs = __webpack_require__(2)
  6224. var mkdir = __webpack_require__(31)
  6225. var WriteStream = fs.WriteStream
  6226. function createOutputStream (file, options) {
  6227. var dirExists = false
  6228. var dir = path.dirname(file)
  6229. options = options || {}
  6230. // if fd is set with an actual number, file is created, hence directory is too
  6231. if (options.fd) {
  6232. return fs.createWriteStream(file, options)
  6233. } else {
  6234. // this hacks the WriteStream constructor from calling open()
  6235. options.fd = -1
  6236. }
  6237. var ws = new WriteStream(file, options)
  6238. var oldOpen = ws.open
  6239. ws.open = function () {
  6240. ws.fd = null // set actual fd
  6241. if (dirExists) return oldOpen.call(ws)
  6242. // this only runs once on first write
  6243. mkdir.mkdirs(dir, function (err) {
  6244. if (err) {
  6245. ws.destroy()
  6246. ws.emit('error', err)
  6247. return
  6248. }
  6249. dirExists = true
  6250. oldOpen.call(ws)
  6251. })
  6252. }
  6253. ws.open()
  6254. return ws
  6255. }
  6256. module.exports = createOutputStream
  6257. /***/ },
  6258. /* 52 */
  6259. /***/ function(module, exports, __webpack_require__) {
  6260. var fs = __webpack_require__(2)
  6261. var path = __webpack_require__(4)
  6262. var mkdir = __webpack_require__(31)
  6263. var remove = __webpack_require__(37)
  6264. function emptyDir (dir, callback) {
  6265. fs.readdir(dir, function (err, items) {
  6266. if (err) return mkdir.mkdirs(dir, callback)
  6267. items = items.map(function (item) {
  6268. return path.join(dir, item)
  6269. })
  6270. deleteItem()
  6271. function deleteItem () {
  6272. var item = items.pop()
  6273. if (!item) return callback()
  6274. remove.remove(item, function (err) {
  6275. if (err) return callback(err)
  6276. deleteItem()
  6277. })
  6278. }
  6279. })
  6280. }
  6281. function emptyDirSync (dir) {
  6282. var items
  6283. try {
  6284. items = fs.readdirSync(dir)
  6285. } catch (err) {
  6286. return mkdir.mkdirsSync(dir)
  6287. }
  6288. items.forEach(function (item) {
  6289. item = path.join(dir, item)
  6290. remove.removeSync(item)
  6291. })
  6292. }
  6293. module.exports = {
  6294. emptyDirSync: emptyDirSync,
  6295. emptydirSync: emptyDirSync,
  6296. emptyDir: emptyDir,
  6297. emptydir: emptyDir
  6298. }
  6299. /***/ },
  6300. /* 53 */
  6301. /***/ function(module, exports, __webpack_require__) {
  6302. var file = __webpack_require__(54)
  6303. var link = __webpack_require__(55)
  6304. var symlink = __webpack_require__(56)
  6305. module.exports = {
  6306. // file
  6307. createFile: file.createFile,
  6308. createFileSync: file.createFileSync,
  6309. ensureFile: file.createFile,
  6310. ensureFileSync: file.createFileSync,
  6311. // link
  6312. createLink: link.createLink,
  6313. createLinkSync: link.createLinkSync,
  6314. ensureLink: link.createLink,
  6315. ensureLinkSync: link.createLinkSync,
  6316. // symlink
  6317. createSymlink: symlink.createSymlink,
  6318. createSymlinkSync: symlink.createSymlinkSync,
  6319. ensureSymlink: symlink.createSymlink,
  6320. ensureSymlinkSync: symlink.createSymlinkSync
  6321. }
  6322. /***/ },
  6323. /* 54 */
  6324. /***/ function(module, exports, __webpack_require__) {
  6325. var path = __webpack_require__(4)
  6326. var fs = __webpack_require__(20)
  6327. var mkdir = __webpack_require__(31)
  6328. function createFile (file, callback) {
  6329. function makeFile () {
  6330. fs.writeFile(file, '', function (err) {
  6331. if (err) return callback(err)
  6332. callback()
  6333. })
  6334. }
  6335. fs.exists(file, function (fileExists) {
  6336. if (fileExists) return callback()
  6337. var dir = path.dirname(file)
  6338. fs.exists(dir, function (dirExists) {
  6339. if (dirExists) return makeFile()
  6340. mkdir.mkdirs(dir, function (err) {
  6341. if (err) return callback(err)
  6342. makeFile()
  6343. })
  6344. })
  6345. })
  6346. }
  6347. function createFileSync (file) {
  6348. if (fs.existsSync(file)) return
  6349. var dir = path.dirname(file)
  6350. if (!fs.existsSync(dir)) {
  6351. mkdir.mkdirsSync(dir)
  6352. }
  6353. fs.writeFileSync(file, '')
  6354. }
  6355. module.exports = {
  6356. createFile: createFile,
  6357. createFileSync: createFileSync,
  6358. // alias
  6359. ensureFile: createFile,
  6360. ensureFileSync: createFileSync
  6361. }
  6362. /***/ },
  6363. /* 55 */
  6364. /***/ function(module, exports, __webpack_require__) {
  6365. var path = __webpack_require__(4)
  6366. var fs = __webpack_require__(20)
  6367. var mkdir = __webpack_require__(31)
  6368. function createLink (srcpath, dstpath, callback) {
  6369. function makeLink (srcpath, dstpath) {
  6370. fs.link(srcpath, dstpath, function (err) {
  6371. if (err) return callback(err)
  6372. callback(null)
  6373. })
  6374. }
  6375. fs.exists(dstpath, function (destinationExists) {
  6376. if (destinationExists) return callback(null)
  6377. fs.lstat(srcpath, function (err, stat) {
  6378. if (err) {
  6379. err.message = err.message.replace('lstat', 'ensureLink')
  6380. return callback(err)
  6381. }
  6382. var dir = path.dirname(dstpath)
  6383. fs.exists(dir, function (dirExists) {
  6384. if (dirExists) return makeLink(srcpath, dstpath)
  6385. mkdir.mkdirs(dir, function (err) {
  6386. if (err) return callback(err)
  6387. makeLink(srcpath, dstpath)
  6388. })
  6389. })
  6390. })
  6391. })
  6392. }
  6393. function createLinkSync (srcpath, dstpath, callback) {
  6394. var destinationExists = fs.existsSync(dstpath)
  6395. if (destinationExists) return undefined
  6396. try {
  6397. fs.lstatSync(srcpath)
  6398. } catch (err) {
  6399. err.message = err.message.replace('lstat', 'ensureLink')
  6400. throw err
  6401. }
  6402. var dir = path.dirname(dstpath)
  6403. var dirExists = fs.existsSync(dir)
  6404. if (dirExists) return fs.linkSync(srcpath, dstpath)
  6405. mkdir.mkdirsSync(dir)
  6406. return fs.linkSync(srcpath, dstpath)
  6407. }
  6408. module.exports = {
  6409. createLink: createLink,
  6410. createLinkSync: createLinkSync,
  6411. // alias
  6412. ensureLink: createLink,
  6413. ensureLinkSync: createLinkSync
  6414. }
  6415. /***/ },
  6416. /* 56 */
  6417. /***/ function(module, exports, __webpack_require__) {
  6418. var path = __webpack_require__(4)
  6419. var fs = __webpack_require__(20)
  6420. var _mkdirs = __webpack_require__(31)
  6421. var mkdirs = _mkdirs.mkdirs
  6422. var mkdirsSync = _mkdirs.mkdirsSync
  6423. var _symlinkPaths = __webpack_require__(57)
  6424. var symlinkPaths = _symlinkPaths.symlinkPaths
  6425. var symlinkPathsSync = _symlinkPaths.symlinkPathsSync
  6426. var _symlinkType = __webpack_require__(58)
  6427. var symlinkType = _symlinkType.symlinkType
  6428. var symlinkTypeSync = _symlinkType.symlinkTypeSync
  6429. function createSymlink (srcpath, dstpath, type, callback) {
  6430. callback = (typeof type === 'function') ? type : callback
  6431. type = (typeof type === 'function') ? false : type
  6432. fs.exists(dstpath, function (destinationExists) {
  6433. if (destinationExists) return callback(null)
  6434. symlinkPaths(srcpath, dstpath, function (err, relative) {
  6435. if (err) return callback(err)
  6436. srcpath = relative.toDst
  6437. symlinkType(relative.toCwd, type, function (err, type) {
  6438. if (err) return callback(err)
  6439. var dir = path.dirname(dstpath)
  6440. fs.exists(dir, function (dirExists) {
  6441. if (dirExists) return fs.symlink(srcpath, dstpath, type, callback)
  6442. mkdirs(dir, function (err) {
  6443. if (err) return callback(err)
  6444. fs.symlink(srcpath, dstpath, type, callback)
  6445. })
  6446. })
  6447. })
  6448. })
  6449. })
  6450. }
  6451. function createSymlinkSync (srcpath, dstpath, type, callback) {
  6452. callback = (typeof type === 'function') ? type : callback
  6453. type = (typeof type === 'function') ? false : type
  6454. var destinationExists = fs.existsSync(dstpath)
  6455. if (destinationExists) return undefined
  6456. var relative = symlinkPathsSync(srcpath, dstpath)
  6457. srcpath = relative.toDst
  6458. type = symlinkTypeSync(relative.toCwd, type)
  6459. var dir = path.dirname(dstpath)
  6460. var exists = fs.existsSync(dir)
  6461. if (exists) return fs.symlinkSync(srcpath, dstpath, type)
  6462. mkdirsSync(dir)
  6463. return fs.symlinkSync(srcpath, dstpath, type)
  6464. }
  6465. module.exports = {
  6466. createSymlink: createSymlink,
  6467. createSymlinkSync: createSymlinkSync,
  6468. // alias
  6469. ensureSymlink: createSymlink,
  6470. ensureSymlinkSync: createSymlinkSync
  6471. }
  6472. /***/ },
  6473. /* 57 */
  6474. /***/ function(module, exports, __webpack_require__) {
  6475. var path = __webpack_require__(4)
  6476. // path.isAbsolute shim for Node.js 0.10 support
  6477. path.isAbsolute = (path.isAbsolute) ? path.isAbsolute : __webpack_require__(12)
  6478. var fs = __webpack_require__(20)
  6479. /**
  6480. * Function that returns two types of paths, one relative to symlink, and one
  6481. * relative to the current working directory. Checks if path is absolute or
  6482. * relative. If the path is relative, this function checks if the path is
  6483. * relative to symlink or relative to current working directory. This is an
  6484. * initiative to find a smarter `srcpath` to supply when building symlinks.
  6485. * This allows you to determine which path to use out of one of three possible
  6486. * types of source paths. The first is an absolute path. This is detected by
  6487. * `path.isAbsolute()`. When an absolute path is provided, it is checked to
  6488. * see if it exists. If it does it's used, if not an error is returned
  6489. * (callback)/ thrown (sync). The other two options for `srcpath` are a
  6490. * relative url. By default Node's `fs.symlink` works by creating a symlink
  6491. * using `dstpath` and expects the `srcpath` to be relative to the newly
  6492. * created symlink. If you provide a `srcpath` that does not exist on the file
  6493. * system it results in a broken symlink. To minimize this, the function
  6494. * checks to see if the 'relative to symlink' source file exists, and if it
  6495. * does it will use it. If it does not, it checks if there's a file that
  6496. * exists that is relative to the current working directory, if does its used.
  6497. * This preserves the expectations of the original fs.symlink spec and adds
  6498. * the ability to pass in `relative to current working direcotry` paths.
  6499. */
  6500. function symlinkPaths (srcpath, dstpath, callback) {
  6501. if (path.isAbsolute(srcpath)) {
  6502. return fs.lstat(srcpath, function (err, stat) {
  6503. if (err) {
  6504. err.message = err.message.replace('lstat', 'ensureSymlink')
  6505. return callback(err)
  6506. }
  6507. return callback(null, {
  6508. 'toCwd': srcpath,
  6509. 'toDst': srcpath
  6510. })
  6511. })
  6512. } else {
  6513. var dstdir = path.dirname(dstpath)
  6514. var relativeToDst = path.join(dstdir, srcpath)
  6515. return fs.exists(relativeToDst, function (exists) {
  6516. if (exists) {
  6517. return callback(null, {
  6518. 'toCwd': relativeToDst,
  6519. 'toDst': srcpath
  6520. })
  6521. } else {
  6522. return fs.lstat(srcpath, function (err, stat) {
  6523. if (err) {
  6524. err.message = err.message.replace('lstat', 'ensureSymlink')
  6525. return callback(err)
  6526. }
  6527. return callback(null, {
  6528. 'toCwd': srcpath,
  6529. 'toDst': path.relative(dstdir, srcpath)
  6530. })
  6531. })
  6532. }
  6533. })
  6534. }
  6535. }
  6536. function symlinkPathsSync (srcpath, dstpath) {
  6537. var exists
  6538. if (path.isAbsolute(srcpath)) {
  6539. exists = fs.existsSync(srcpath)
  6540. if (!exists) throw new Error('absolute srcpath does not exist')
  6541. return {
  6542. 'toCwd': srcpath,
  6543. 'toDst': srcpath
  6544. }
  6545. } else {
  6546. var dstdir = path.dirname(dstpath)
  6547. var relativeToDst = path.join(dstdir, srcpath)
  6548. exists = fs.existsSync(relativeToDst)
  6549. if (exists) {
  6550. return {
  6551. 'toCwd': relativeToDst,
  6552. 'toDst': srcpath
  6553. }
  6554. } else {
  6555. exists = fs.existsSync(srcpath)
  6556. if (!exists) throw new Error('relative srcpath does not exist')
  6557. return {
  6558. 'toCwd': srcpath,
  6559. 'toDst': path.relative(dstdir, srcpath)
  6560. }
  6561. }
  6562. }
  6563. }
  6564. module.exports = {
  6565. 'symlinkPaths': symlinkPaths,
  6566. 'symlinkPathsSync': symlinkPathsSync
  6567. }
  6568. /***/ },
  6569. /* 58 */
  6570. /***/ function(module, exports, __webpack_require__) {
  6571. var fs = __webpack_require__(20)
  6572. function symlinkType (srcpath, type, callback) {
  6573. callback = (typeof type === 'function') ? type : callback
  6574. type = (typeof type === 'function') ? false : type
  6575. if (type) return callback(null, type)
  6576. fs.lstat(srcpath, function (err, stats) {
  6577. if (err) return callback(null, 'file')
  6578. type = (stats && stats.isDirectory()) ? 'dir' : 'file'
  6579. callback(null, type)
  6580. })
  6581. }
  6582. function symlinkTypeSync (srcpath, type) {
  6583. if (type) return type
  6584. try {
  6585. var stats = fs.lstatSync(srcpath)
  6586. } catch (e) {
  6587. return 'file'
  6588. }
  6589. return (stats && stats.isDirectory()) ? 'dir' : 'file'
  6590. }
  6591. module.exports = {
  6592. symlinkType: symlinkType,
  6593. symlinkTypeSync: symlinkTypeSync
  6594. }
  6595. /***/ },
  6596. /* 59 */
  6597. /***/ function(module, exports, __webpack_require__) {
  6598. var path = __webpack_require__(4)
  6599. var fs = __webpack_require__(20)
  6600. var mkdir = __webpack_require__(31)
  6601. function outputFile (file, data, encoding, callback) {
  6602. if (typeof encoding === 'function') {
  6603. callback = encoding
  6604. encoding = 'utf8'
  6605. }
  6606. var dir = path.dirname(file)
  6607. fs.exists(dir, function (itDoes) {
  6608. if (itDoes) return fs.writeFile(file, data, encoding, callback)
  6609. mkdir.mkdirs(dir, function (err) {
  6610. if (err) return callback(err)
  6611. fs.writeFile(file, data, encoding, callback)
  6612. })
  6613. })
  6614. }
  6615. function outputFileSync (file, data, encoding) {
  6616. var dir = path.dirname(file)
  6617. if (fs.existsSync(dir)) {
  6618. return fs.writeFileSync.apply(fs, arguments)
  6619. }
  6620. mkdir.mkdirsSync(dir)
  6621. fs.writeFileSync.apply(fs, arguments)
  6622. }
  6623. module.exports = {
  6624. outputFile: outputFile,
  6625. outputFileSync: outputFileSync
  6626. }
  6627. /***/ },
  6628. /* 60 */
  6629. /***/ function(module, exports, __webpack_require__) {
  6630. var klaw = __webpack_require__(61)
  6631. module.exports = {
  6632. walk: klaw
  6633. }
  6634. /***/ },
  6635. /* 61 */
  6636. /***/ function(module, exports, __webpack_require__) {
  6637. var assert = __webpack_require__(11)
  6638. var fs = __webpack_require__(2)
  6639. var path = __webpack_require__(4)
  6640. var Readable = __webpack_require__(25).Readable
  6641. var util = __webpack_require__(9)
  6642. var assign = __webpack_require__(62)
  6643. function Walker (dir, options) {
  6644. assert.strictEqual(typeof dir, 'string', '`dir` parameter should be of type string. Got type: ' + typeof dir)
  6645. var defaultStreamOptions = { objectMode: true }
  6646. var defaultOpts = { queueMethod: 'shift', pathSorter: undefined }
  6647. options = assign(defaultOpts, options, defaultStreamOptions)
  6648. Readable.call(this, options)
  6649. this.root = path.resolve(dir)
  6650. this.paths = [this.root]
  6651. this.options = options
  6652. }
  6653. util.inherits(Walker, Readable)
  6654. Walker.prototype._read = function () {
  6655. if (this.paths.length === 0) return this.push(null)
  6656. var self = this
  6657. var pathItem = this.paths[this.options.queueMethod]()
  6658. fs.lstat(pathItem, function (err, stats) {
  6659. var item = { path: pathItem, stats: stats }
  6660. if (err) return self.emit('error', err, item)
  6661. if (!stats.isDirectory()) return self.push(item)
  6662. fs.readdir(pathItem, function (err, pathItems) {
  6663. if (err) {
  6664. self.push(item)
  6665. return self.emit('error', err, item)
  6666. }
  6667. pathItems = pathItems.map(function (part) { return path.join(pathItem, part) })
  6668. if (self.options.pathSorter) pathItems.sort(self.options.pathSorter)
  6669. pathItems.forEach(function (pi) { self.paths.push(pi) })
  6670. self.push(item)
  6671. })
  6672. })
  6673. }
  6674. function walk (root, options) {
  6675. return new Walker(root, options)
  6676. }
  6677. module.exports = walk
  6678. /***/ },
  6679. /* 62 */
  6680. /***/ function(module, exports) {
  6681. // simple mutable assign (extracted from fs-extra)
  6682. // I really like object-assign package, but I wanted a lean package with zero deps
  6683. function _assign () {
  6684. var args = [].slice.call(arguments).filter(function (i) { return i })
  6685. var dest = args.shift()
  6686. args.forEach(function (src) {
  6687. Object.keys(src).forEach(function (key) {
  6688. dest[key] = src[key]
  6689. })
  6690. })
  6691. return dest
  6692. }
  6693. // thank you baby Jesus for Node v4 and Object.assign
  6694. module.exports = Object.assign || _assign
  6695. /***/ },
  6696. /* 63 */
  6697. /***/ function(module, exports, __webpack_require__) {
  6698. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*
  6699. Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
  6700. Redistribution and use in source and binary forms, with or without
  6701. modification, are permitted provided that the following conditions are met:
  6702. * Redistributions of source code must retain the above copyright
  6703. notice, this list of conditions and the following disclaimer.
  6704. * Redistributions in binary form must reproduce the above copyright
  6705. notice, this list of conditions and the following disclaimer in the
  6706. documentation and/or other materials provided with the distribution.
  6707. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  6708. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  6709. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  6710. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  6711. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  6712. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  6713. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  6714. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  6715. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  6716. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6717. */
  6718. (function (root, factory) {
  6719. 'use strict';
  6720. // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
  6721. // Rhino, and plain browser loading.
  6722. /* istanbul ignore next */
  6723. if (true) {
  6724. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  6725. } else if (typeof exports !== 'undefined') {
  6726. factory(exports);
  6727. } else {
  6728. factory((root.esprima = {}));
  6729. }
  6730. }(this, function (exports) {
  6731. 'use strict';
  6732. var Token,
  6733. TokenName,
  6734. FnExprTokens,
  6735. Syntax,
  6736. PlaceHolders,
  6737. Messages,
  6738. Regex,
  6739. source,
  6740. strict,
  6741. index,
  6742. lineNumber,
  6743. lineStart,
  6744. hasLineTerminator,
  6745. lastIndex,
  6746. lastLineNumber,
  6747. lastLineStart,
  6748. startIndex,
  6749. startLineNumber,
  6750. startLineStart,
  6751. scanning,
  6752. length,
  6753. lookahead,
  6754. state,
  6755. extra,
  6756. isBindingElement,
  6757. isAssignmentTarget,
  6758. firstCoverInitializedNameError;
  6759. Token = {
  6760. BooleanLiteral: 1,
  6761. EOF: 2,
  6762. Identifier: 3,
  6763. Keyword: 4,
  6764. NullLiteral: 5,
  6765. NumericLiteral: 6,
  6766. Punctuator: 7,
  6767. StringLiteral: 8,
  6768. RegularExpression: 9,
  6769. Template: 10
  6770. };
  6771. TokenName = {};
  6772. TokenName[Token.BooleanLiteral] = 'Boolean';
  6773. TokenName[Token.EOF] = '<end>';
  6774. TokenName[Token.Identifier] = 'Identifier';
  6775. TokenName[Token.Keyword] = 'Keyword';
  6776. TokenName[Token.NullLiteral] = 'Null';
  6777. TokenName[Token.NumericLiteral] = 'Numeric';
  6778. TokenName[Token.Punctuator] = 'Punctuator';
  6779. TokenName[Token.StringLiteral] = 'String';
  6780. TokenName[Token.RegularExpression] = 'RegularExpression';
  6781. TokenName[Token.Template] = 'Template';
  6782. // A function following one of those tokens is an expression.
  6783. FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
  6784. 'return', 'case', 'delete', 'throw', 'void',
  6785. // assignment operators
  6786. '=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',
  6787. '&=', '|=', '^=', ',',
  6788. // binary/unary operators
  6789. '+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
  6790. '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
  6791. '<=', '<', '>', '!=', '!=='];
  6792. Syntax = {
  6793. AssignmentExpression: 'AssignmentExpression',
  6794. AssignmentPattern: 'AssignmentPattern',
  6795. ArrayExpression: 'ArrayExpression',
  6796. ArrayPattern: 'ArrayPattern',
  6797. ArrowFunctionExpression: 'ArrowFunctionExpression',
  6798. BlockStatement: 'BlockStatement',
  6799. BinaryExpression: 'BinaryExpression',
  6800. BreakStatement: 'BreakStatement',
  6801. CallExpression: 'CallExpression',
  6802. CatchClause: 'CatchClause',
  6803. ClassBody: 'ClassBody',
  6804. ClassDeclaration: 'ClassDeclaration',
  6805. ClassExpression: 'ClassExpression',
  6806. ConditionalExpression: 'ConditionalExpression',
  6807. ContinueStatement: 'ContinueStatement',
  6808. DoWhileStatement: 'DoWhileStatement',
  6809. DebuggerStatement: 'DebuggerStatement',
  6810. EmptyStatement: 'EmptyStatement',
  6811. ExportAllDeclaration: 'ExportAllDeclaration',
  6812. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  6813. ExportNamedDeclaration: 'ExportNamedDeclaration',
  6814. ExportSpecifier: 'ExportSpecifier',
  6815. ExpressionStatement: 'ExpressionStatement',
  6816. ForStatement: 'ForStatement',
  6817. ForOfStatement: 'ForOfStatement',
  6818. ForInStatement: 'ForInStatement',
  6819. FunctionDeclaration: 'FunctionDeclaration',
  6820. FunctionExpression: 'FunctionExpression',
  6821. Identifier: 'Identifier',
  6822. IfStatement: 'IfStatement',
  6823. ImportDeclaration: 'ImportDeclaration',
  6824. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  6825. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  6826. ImportSpecifier: 'ImportSpecifier',
  6827. Literal: 'Literal',
  6828. LabeledStatement: 'LabeledStatement',
  6829. LogicalExpression: 'LogicalExpression',
  6830. MemberExpression: 'MemberExpression',
  6831. MetaProperty: 'MetaProperty',
  6832. MethodDefinition: 'MethodDefinition',
  6833. NewExpression: 'NewExpression',
  6834. ObjectExpression: 'ObjectExpression',
  6835. ObjectPattern: 'ObjectPattern',
  6836. Program: 'Program',
  6837. Property: 'Property',
  6838. RestElement: 'RestElement',
  6839. ReturnStatement: 'ReturnStatement',
  6840. SequenceExpression: 'SequenceExpression',
  6841. SpreadElement: 'SpreadElement',
  6842. Super: 'Super',
  6843. SwitchCase: 'SwitchCase',
  6844. SwitchStatement: 'SwitchStatement',
  6845. TaggedTemplateExpression: 'TaggedTemplateExpression',
  6846. TemplateElement: 'TemplateElement',
  6847. TemplateLiteral: 'TemplateLiteral',
  6848. ThisExpression: 'ThisExpression',
  6849. ThrowStatement: 'ThrowStatement',
  6850. TryStatement: 'TryStatement',
  6851. UnaryExpression: 'UnaryExpression',
  6852. UpdateExpression: 'UpdateExpression',
  6853. VariableDeclaration: 'VariableDeclaration',
  6854. VariableDeclarator: 'VariableDeclarator',
  6855. WhileStatement: 'WhileStatement',
  6856. WithStatement: 'WithStatement',
  6857. YieldExpression: 'YieldExpression'
  6858. };
  6859. PlaceHolders = {
  6860. ArrowParameterPlaceHolder: 'ArrowParameterPlaceHolder'
  6861. };
  6862. // Error messages should be identical to V8.
  6863. Messages = {
  6864. UnexpectedToken: 'Unexpected token %0',
  6865. UnexpectedNumber: 'Unexpected number',
  6866. UnexpectedString: 'Unexpected string',
  6867. UnexpectedIdentifier: 'Unexpected identifier',
  6868. UnexpectedReserved: 'Unexpected reserved word',
  6869. UnexpectedTemplate: 'Unexpected quasi %0',
  6870. UnexpectedEOS: 'Unexpected end of input',
  6871. NewlineAfterThrow: 'Illegal newline after throw',
  6872. InvalidRegExp: 'Invalid regular expression',
  6873. UnterminatedRegExp: 'Invalid regular expression: missing /',
  6874. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  6875. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  6876. InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
  6877. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  6878. NoCatchOrFinally: 'Missing catch or finally after try',
  6879. UnknownLabel: 'Undefined label \'%0\'',
  6880. Redeclaration: '%0 \'%1\' has already been declared',
  6881. IllegalContinue: 'Illegal continue statement',
  6882. IllegalBreak: 'Illegal break statement',
  6883. IllegalReturn: 'Illegal return statement',
  6884. StrictModeWith: 'Strict mode code may not include a with statement',
  6885. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  6886. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  6887. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  6888. StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
  6889. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  6890. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  6891. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  6892. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  6893. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  6894. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  6895. StrictReservedWord: 'Use of future reserved word in strict mode',
  6896. TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
  6897. ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
  6898. DefaultRestParameter: 'Unexpected token =',
  6899. ObjectPatternAsRestParameter: 'Unexpected token {',
  6900. DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
  6901. ConstructorSpecialMethod: 'Class constructor may not be an accessor',
  6902. DuplicateConstructor: 'A class may only have one constructor',
  6903. StaticPrototype: 'Classes may not have static property named prototype',
  6904. MissingFromClause: 'Unexpected token',
  6905. NoAsAfterImportNamespace: 'Unexpected token',
  6906. InvalidModuleSpecifier: 'Unexpected token',
  6907. IllegalImportDeclaration: 'Unexpected token',
  6908. IllegalExportDeclaration: 'Unexpected token',
  6909. DuplicateBinding: 'Duplicate binding %0'
  6910. };
  6911. // See also tools/generate-unicode-regex.js.
  6912. Regex = {
  6913. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierStart:
  6914. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDE00-\uDE11\uDE13-\uDE2B\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDE00-\uDE2F\uDE44\uDE80-\uDEAA]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|\uD809[\uDC00-\uDC6E]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]|\uD87E[\uDC00-\uDE1D]/,
  6915. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierPart:
  6916. NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDD0-\uDDDA\uDE00-\uDE11\uDE13-\uDE37\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF01-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|\uD809[\uDC00-\uDC6E]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
  6917. };
  6918. // Ensure the condition is true, otherwise throw an error.
  6919. // This is only to have a better contract semantic, i.e. another safety net
  6920. // to catch a logic error. The condition shall be fulfilled in normal case.
  6921. // Do NOT use this to enforce a certain condition on any user input.
  6922. function assert(condition, message) {
  6923. /* istanbul ignore if */
  6924. if (!condition) {
  6925. throw new Error('ASSERT: ' + message);
  6926. }
  6927. }
  6928. function isDecimalDigit(ch) {
  6929. return (ch >= 0x30 && ch <= 0x39); // 0..9
  6930. }
  6931. function isHexDigit(ch) {
  6932. return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;
  6933. }
  6934. function isOctalDigit(ch) {
  6935. return '01234567'.indexOf(ch) >= 0;
  6936. }
  6937. function octalToDecimal(ch) {
  6938. // \0 is not octal escape sequence
  6939. var octal = (ch !== '0'), code = '01234567'.indexOf(ch);
  6940. if (index < length && isOctalDigit(source[index])) {
  6941. octal = true;
  6942. code = code * 8 + '01234567'.indexOf(source[index++]);
  6943. // 3 digits are only allowed when string starts
  6944. // with 0, 1, 2, 3
  6945. if ('0123'.indexOf(ch) >= 0 &&
  6946. index < length &&
  6947. isOctalDigit(source[index])) {
  6948. code = code * 8 + '01234567'.indexOf(source[index++]);
  6949. }
  6950. }
  6951. return {
  6952. code: code,
  6953. octal: octal
  6954. };
  6955. }
  6956. // ECMA-262 11.2 White Space
  6957. function isWhiteSpace(ch) {
  6958. return (ch === 0x20) || (ch === 0x09) || (ch === 0x0B) || (ch === 0x0C) || (ch === 0xA0) ||
  6959. (ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(ch) >= 0);
  6960. }
  6961. // ECMA-262 11.3 Line Terminators
  6962. function isLineTerminator(ch) {
  6963. return (ch === 0x0A) || (ch === 0x0D) || (ch === 0x2028) || (ch === 0x2029);
  6964. }
  6965. // ECMA-262 11.6 Identifier Names and Identifiers
  6966. function fromCodePoint(cp) {
  6967. return (cp < 0x10000) ? String.fromCharCode(cp) :
  6968. String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
  6969. String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
  6970. }
  6971. function isIdentifierStart(ch) {
  6972. return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)
  6973. (ch >= 0x41 && ch <= 0x5A) || // A..Z
  6974. (ch >= 0x61 && ch <= 0x7A) || // a..z
  6975. (ch === 0x5C) || // \ (backslash)
  6976. ((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch)));
  6977. }
  6978. function isIdentifierPart(ch) {
  6979. return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)
  6980. (ch >= 0x41 && ch <= 0x5A) || // A..Z
  6981. (ch >= 0x61 && ch <= 0x7A) || // a..z
  6982. (ch >= 0x30 && ch <= 0x39) || // 0..9
  6983. (ch === 0x5C) || // \ (backslash)
  6984. ((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch)));
  6985. }
  6986. // ECMA-262 11.6.2.2 Future Reserved Words
  6987. function isFutureReservedWord(id) {
  6988. switch (id) {
  6989. case 'enum':
  6990. case 'export':
  6991. case 'import':
  6992. case 'super':
  6993. return true;
  6994. default:
  6995. return false;
  6996. }
  6997. }
  6998. function isStrictModeReservedWord(id) {
  6999. switch (id) {
  7000. case 'implements':
  7001. case 'interface':
  7002. case 'package':
  7003. case 'private':
  7004. case 'protected':
  7005. case 'public':
  7006. case 'static':
  7007. case 'yield':
  7008. case 'let':
  7009. return true;
  7010. default:
  7011. return false;
  7012. }
  7013. }
  7014. function isRestrictedWord(id) {
  7015. return id === 'eval' || id === 'arguments';
  7016. }
  7017. // ECMA-262 11.6.2.1 Keywords
  7018. function isKeyword(id) {
  7019. switch (id.length) {
  7020. case 2:
  7021. return (id === 'if') || (id === 'in') || (id === 'do');
  7022. case 3:
  7023. return (id === 'var') || (id === 'for') || (id === 'new') ||
  7024. (id === 'try') || (id === 'let');
  7025. case 4:
  7026. return (id === 'this') || (id === 'else') || (id === 'case') ||
  7027. (id === 'void') || (id === 'with') || (id === 'enum');
  7028. case 5:
  7029. return (id === 'while') || (id === 'break') || (id === 'catch') ||
  7030. (id === 'throw') || (id === 'const') || (id === 'yield') ||
  7031. (id === 'class') || (id === 'super');
  7032. case 6:
  7033. return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
  7034. (id === 'switch') || (id === 'export') || (id === 'import');
  7035. case 7:
  7036. return (id === 'default') || (id === 'finally') || (id === 'extends');
  7037. case 8:
  7038. return (id === 'function') || (id === 'continue') || (id === 'debugger');
  7039. case 10:
  7040. return (id === 'instanceof');
  7041. default:
  7042. return false;
  7043. }
  7044. }
  7045. // ECMA-262 11.4 Comments
  7046. function addComment(type, value, start, end, loc) {
  7047. var comment;
  7048. assert(typeof start === 'number', 'Comment must have valid position');
  7049. state.lastCommentStart = start;
  7050. comment = {
  7051. type: type,
  7052. value: value
  7053. };
  7054. if (extra.range) {
  7055. comment.range = [start, end];
  7056. }
  7057. if (extra.loc) {
  7058. comment.loc = loc;
  7059. }
  7060. extra.comments.push(comment);
  7061. if (extra.attachComment) {
  7062. extra.leadingComments.push(comment);
  7063. extra.trailingComments.push(comment);
  7064. }
  7065. if (extra.tokenize) {
  7066. comment.type = comment.type + 'Comment';
  7067. if (extra.delegate) {
  7068. comment = extra.delegate(comment);
  7069. }
  7070. extra.tokens.push(comment);
  7071. }
  7072. }
  7073. function skipSingleLineComment(offset) {
  7074. var start, loc, ch, comment;
  7075. start = index - offset;
  7076. loc = {
  7077. start: {
  7078. line: lineNumber,
  7079. column: index - lineStart - offset
  7080. }
  7081. };
  7082. while (index < length) {
  7083. ch = source.charCodeAt(index);
  7084. ++index;
  7085. if (isLineTerminator(ch)) {
  7086. hasLineTerminator = true;
  7087. if (extra.comments) {
  7088. comment = source.slice(start + offset, index - 1);
  7089. loc.end = {
  7090. line: lineNumber,
  7091. column: index - lineStart - 1
  7092. };
  7093. addComment('Line', comment, start, index - 1, loc);
  7094. }
  7095. if (ch === 13 && source.charCodeAt(index) === 10) {
  7096. ++index;
  7097. }
  7098. ++lineNumber;
  7099. lineStart = index;
  7100. return;
  7101. }
  7102. }
  7103. if (extra.comments) {
  7104. comment = source.slice(start + offset, index);
  7105. loc.end = {
  7106. line: lineNumber,
  7107. column: index - lineStart
  7108. };
  7109. addComment('Line', comment, start, index, loc);
  7110. }
  7111. }
  7112. function skipMultiLineComment() {
  7113. var start, loc, ch, comment;
  7114. if (extra.comments) {
  7115. start = index - 2;
  7116. loc = {
  7117. start: {
  7118. line: lineNumber,
  7119. column: index - lineStart - 2
  7120. }
  7121. };
  7122. }
  7123. while (index < length) {
  7124. ch = source.charCodeAt(index);
  7125. if (isLineTerminator(ch)) {
  7126. if (ch === 0x0D && source.charCodeAt(index + 1) === 0x0A) {
  7127. ++index;
  7128. }
  7129. hasLineTerminator = true;
  7130. ++lineNumber;
  7131. ++index;
  7132. lineStart = index;
  7133. } else if (ch === 0x2A) {
  7134. // Block comment ends with '*/'.
  7135. if (source.charCodeAt(index + 1) === 0x2F) {
  7136. ++index;
  7137. ++index;
  7138. if (extra.comments) {
  7139. comment = source.slice(start + 2, index - 2);
  7140. loc.end = {
  7141. line: lineNumber,
  7142. column: index - lineStart
  7143. };
  7144. addComment('Block', comment, start, index, loc);
  7145. }
  7146. return;
  7147. }
  7148. ++index;
  7149. } else {
  7150. ++index;
  7151. }
  7152. }
  7153. // Ran off the end of the file - the whole thing is a comment
  7154. if (extra.comments) {
  7155. loc.end = {
  7156. line: lineNumber,
  7157. column: index - lineStart
  7158. };
  7159. comment = source.slice(start + 2, index);
  7160. addComment('Block', comment, start, index, loc);
  7161. }
  7162. tolerateUnexpectedToken();
  7163. }
  7164. function skipComment() {
  7165. var ch, start;
  7166. hasLineTerminator = false;
  7167. start = (index === 0);
  7168. while (index < length) {
  7169. ch = source.charCodeAt(index);
  7170. if (isWhiteSpace(ch)) {
  7171. ++index;
  7172. } else if (isLineTerminator(ch)) {
  7173. hasLineTerminator = true;
  7174. ++index;
  7175. if (ch === 0x0D && source.charCodeAt(index) === 0x0A) {
  7176. ++index;
  7177. }
  7178. ++lineNumber;
  7179. lineStart = index;
  7180. start = true;
  7181. } else if (ch === 0x2F) { // U+002F is '/'
  7182. ch = source.charCodeAt(index + 1);
  7183. if (ch === 0x2F) {
  7184. ++index;
  7185. ++index;
  7186. skipSingleLineComment(2);
  7187. start = true;
  7188. } else if (ch === 0x2A) { // U+002A is '*'
  7189. ++index;
  7190. ++index;
  7191. skipMultiLineComment();
  7192. } else {
  7193. break;
  7194. }
  7195. } else if (start && ch === 0x2D) { // U+002D is '-'
  7196. // U+003E is '>'
  7197. if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) {
  7198. // '-->' is a single-line comment
  7199. index += 3;
  7200. skipSingleLineComment(3);
  7201. } else {
  7202. break;
  7203. }
  7204. } else if (ch === 0x3C) { // U+003C is '<'
  7205. if (source.slice(index + 1, index + 4) === '!--') {
  7206. ++index; // `<`
  7207. ++index; // `!`
  7208. ++index; // `-`
  7209. ++index; // `-`
  7210. skipSingleLineComment(4);
  7211. } else {
  7212. break;
  7213. }
  7214. } else {
  7215. break;
  7216. }
  7217. }
  7218. }
  7219. function scanHexEscape(prefix) {
  7220. var i, len, ch, code = 0;
  7221. len = (prefix === 'u') ? 4 : 2;
  7222. for (i = 0; i < len; ++i) {
  7223. if (index < length && isHexDigit(source[index])) {
  7224. ch = source[index++];
  7225. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  7226. } else {
  7227. return '';
  7228. }
  7229. }
  7230. return String.fromCharCode(code);
  7231. }
  7232. function scanUnicodeCodePointEscape() {
  7233. var ch, code;
  7234. ch = source[index];
  7235. code = 0;
  7236. // At least, one hex digit is required.
  7237. if (ch === '}') {
  7238. throwUnexpectedToken();
  7239. }
  7240. while (index < length) {
  7241. ch = source[index++];
  7242. if (!isHexDigit(ch)) {
  7243. break;
  7244. }
  7245. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  7246. }
  7247. if (code > 0x10FFFF || ch !== '}') {
  7248. throwUnexpectedToken();
  7249. }
  7250. return fromCodePoint(code);
  7251. }
  7252. function codePointAt(i) {
  7253. var cp, first, second;
  7254. cp = source.charCodeAt(i);
  7255. if (cp >= 0xD800 && cp <= 0xDBFF) {
  7256. second = source.charCodeAt(i + 1);
  7257. if (second >= 0xDC00 && second <= 0xDFFF) {
  7258. first = cp;
  7259. cp = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  7260. }
  7261. }
  7262. return cp;
  7263. }
  7264. function getComplexIdentifier() {
  7265. var cp, ch, id;
  7266. cp = codePointAt(index);
  7267. id = fromCodePoint(cp);
  7268. index += id.length;
  7269. // '\u' (U+005C, U+0075) denotes an escaped character.
  7270. if (cp === 0x5C) {
  7271. if (source.charCodeAt(index) !== 0x75) {
  7272. throwUnexpectedToken();
  7273. }
  7274. ++index;
  7275. if (source[index] === '{') {
  7276. ++index;
  7277. ch = scanUnicodeCodePointEscape();
  7278. } else {
  7279. ch = scanHexEscape('u');
  7280. cp = ch.charCodeAt(0);
  7281. if (!ch || ch === '\\' || !isIdentifierStart(cp)) {
  7282. throwUnexpectedToken();
  7283. }
  7284. }
  7285. id = ch;
  7286. }
  7287. while (index < length) {
  7288. cp = codePointAt(index);
  7289. if (!isIdentifierPart(cp)) {
  7290. break;
  7291. }
  7292. ch = fromCodePoint(cp);
  7293. id += ch;
  7294. index += ch.length;
  7295. // '\u' (U+005C, U+0075) denotes an escaped character.
  7296. if (cp === 0x5C) {
  7297. id = id.substr(0, id.length - 1);
  7298. if (source.charCodeAt(index) !== 0x75) {
  7299. throwUnexpectedToken();
  7300. }
  7301. ++index;
  7302. if (source[index] === '{') {
  7303. ++index;
  7304. ch = scanUnicodeCodePointEscape();
  7305. } else {
  7306. ch = scanHexEscape('u');
  7307. cp = ch.charCodeAt(0);
  7308. if (!ch || ch === '\\' || !isIdentifierPart(cp)) {
  7309. throwUnexpectedToken();
  7310. }
  7311. }
  7312. id += ch;
  7313. }
  7314. }
  7315. return id;
  7316. }
  7317. function getIdentifier() {
  7318. var start, ch;
  7319. start = index++;
  7320. while (index < length) {
  7321. ch = source.charCodeAt(index);
  7322. if (ch === 0x5C) {
  7323. // Blackslash (U+005C) marks Unicode escape sequence.
  7324. index = start;
  7325. return getComplexIdentifier();
  7326. } else if (ch >= 0xD800 && ch < 0xDFFF) {
  7327. // Need to handle surrogate pairs.
  7328. index = start;
  7329. return getComplexIdentifier();
  7330. }
  7331. if (isIdentifierPart(ch)) {
  7332. ++index;
  7333. } else {
  7334. break;
  7335. }
  7336. }
  7337. return source.slice(start, index);
  7338. }
  7339. function scanIdentifier() {
  7340. var start, id, type;
  7341. start = index;
  7342. // Backslash (U+005C) starts an escaped character.
  7343. id = (source.charCodeAt(index) === 0x5C) ? getComplexIdentifier() : getIdentifier();
  7344. // There is no keyword or literal with only one character.
  7345. // Thus, it must be an identifier.
  7346. if (id.length === 1) {
  7347. type = Token.Identifier;
  7348. } else if (isKeyword(id)) {
  7349. type = Token.Keyword;
  7350. } else if (id === 'null') {
  7351. type = Token.NullLiteral;
  7352. } else if (id === 'true' || id === 'false') {
  7353. type = Token.BooleanLiteral;
  7354. } else {
  7355. type = Token.Identifier;
  7356. }
  7357. return {
  7358. type: type,
  7359. value: id,
  7360. lineNumber: lineNumber,
  7361. lineStart: lineStart,
  7362. start: start,
  7363. end: index
  7364. };
  7365. }
  7366. // ECMA-262 11.7 Punctuators
  7367. function scanPunctuator() {
  7368. var token, str;
  7369. token = {
  7370. type: Token.Punctuator,
  7371. value: '',
  7372. lineNumber: lineNumber,
  7373. lineStart: lineStart,
  7374. start: index,
  7375. end: index
  7376. };
  7377. // Check for most common single-character punctuators.
  7378. str = source[index];
  7379. switch (str) {
  7380. case '(':
  7381. if (extra.tokenize) {
  7382. extra.openParenToken = extra.tokenValues.length;
  7383. }
  7384. ++index;
  7385. break;
  7386. case '{':
  7387. if (extra.tokenize) {
  7388. extra.openCurlyToken = extra.tokenValues.length;
  7389. }
  7390. state.curlyStack.push('{');
  7391. ++index;
  7392. break;
  7393. case '.':
  7394. ++index;
  7395. if (source[index] === '.' && source[index + 1] === '.') {
  7396. // Spread operator: ...
  7397. index += 2;
  7398. str = '...';
  7399. }
  7400. break;
  7401. case '}':
  7402. ++index;
  7403. state.curlyStack.pop();
  7404. break;
  7405. case ')':
  7406. case ';':
  7407. case ',':
  7408. case '[':
  7409. case ']':
  7410. case ':':
  7411. case '?':
  7412. case '~':
  7413. ++index;
  7414. break;
  7415. default:
  7416. // 4-character punctuator.
  7417. str = source.substr(index, 4);
  7418. if (str === '>>>=') {
  7419. index += 4;
  7420. } else {
  7421. // 3-character punctuators.
  7422. str = str.substr(0, 3);
  7423. if (str === '===' || str === '!==' || str === '>>>' ||
  7424. str === '<<=' || str === '>>=') {
  7425. index += 3;
  7426. } else {
  7427. // 2-character punctuators.
  7428. str = str.substr(0, 2);
  7429. if (str === '&&' || str === '||' || str === '==' || str === '!=' ||
  7430. str === '+=' || str === '-=' || str === '*=' || str === '/=' ||
  7431. str === '++' || str === '--' || str === '<<' || str === '>>' ||
  7432. str === '&=' || str === '|=' || str === '^=' || str === '%=' ||
  7433. str === '<=' || str === '>=' || str === '=>') {
  7434. index += 2;
  7435. } else {
  7436. // 1-character punctuators.
  7437. str = source[index];
  7438. if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {
  7439. ++index;
  7440. }
  7441. }
  7442. }
  7443. }
  7444. }
  7445. if (index === token.start) {
  7446. throwUnexpectedToken();
  7447. }
  7448. token.end = index;
  7449. token.value = str;
  7450. return token;
  7451. }
  7452. // ECMA-262 11.8.3 Numeric Literals
  7453. function scanHexLiteral(start) {
  7454. var number = '';
  7455. while (index < length) {
  7456. if (!isHexDigit(source[index])) {
  7457. break;
  7458. }
  7459. number += source[index++];
  7460. }
  7461. if (number.length === 0) {
  7462. throwUnexpectedToken();
  7463. }
  7464. if (isIdentifierStart(source.charCodeAt(index))) {
  7465. throwUnexpectedToken();
  7466. }
  7467. return {
  7468. type: Token.NumericLiteral,
  7469. value: parseInt('0x' + number, 16),
  7470. lineNumber: lineNumber,
  7471. lineStart: lineStart,
  7472. start: start,
  7473. end: index
  7474. };
  7475. }
  7476. function scanBinaryLiteral(start) {
  7477. var ch, number;
  7478. number = '';
  7479. while (index < length) {
  7480. ch = source[index];
  7481. if (ch !== '0' && ch !== '1') {
  7482. break;
  7483. }
  7484. number += source[index++];
  7485. }
  7486. if (number.length === 0) {
  7487. // only 0b or 0B
  7488. throwUnexpectedToken();
  7489. }
  7490. if (index < length) {
  7491. ch = source.charCodeAt(index);
  7492. /* istanbul ignore else */
  7493. if (isIdentifierStart(ch) || isDecimalDigit(ch)) {
  7494. throwUnexpectedToken();
  7495. }
  7496. }
  7497. return {
  7498. type: Token.NumericLiteral,
  7499. value: parseInt(number, 2),
  7500. lineNumber: lineNumber,
  7501. lineStart: lineStart,
  7502. start: start,
  7503. end: index
  7504. };
  7505. }
  7506. function scanOctalLiteral(prefix, start) {
  7507. var number, octal;
  7508. if (isOctalDigit(prefix)) {
  7509. octal = true;
  7510. number = '0' + source[index++];
  7511. } else {
  7512. octal = false;
  7513. ++index;
  7514. number = '';
  7515. }
  7516. while (index < length) {
  7517. if (!isOctalDigit(source[index])) {
  7518. break;
  7519. }
  7520. number += source[index++];
  7521. }
  7522. if (!octal && number.length === 0) {
  7523. // only 0o or 0O
  7524. throwUnexpectedToken();
  7525. }
  7526. if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {
  7527. throwUnexpectedToken();
  7528. }
  7529. return {
  7530. type: Token.NumericLiteral,
  7531. value: parseInt(number, 8),
  7532. octal: octal,
  7533. lineNumber: lineNumber,
  7534. lineStart: lineStart,
  7535. start: start,
  7536. end: index
  7537. };
  7538. }
  7539. function isImplicitOctalLiteral() {
  7540. var i, ch;
  7541. // Implicit octal, unless there is a non-octal digit.
  7542. // (Annex B.1.1 on Numeric Literals)
  7543. for (i = index + 1; i < length; ++i) {
  7544. ch = source[i];
  7545. if (ch === '8' || ch === '9') {
  7546. return false;
  7547. }
  7548. if (!isOctalDigit(ch)) {
  7549. return true;
  7550. }
  7551. }
  7552. return true;
  7553. }
  7554. function scanNumericLiteral() {
  7555. var number, start, ch;
  7556. ch = source[index];
  7557. assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),
  7558. 'Numeric literal must start with a decimal digit or a decimal point');
  7559. start = index;
  7560. number = '';
  7561. if (ch !== '.') {
  7562. number = source[index++];
  7563. ch = source[index];
  7564. // Hex number starts with '0x'.
  7565. // Octal number starts with '0'.
  7566. // Octal number in ES6 starts with '0o'.
  7567. // Binary number in ES6 starts with '0b'.
  7568. if (number === '0') {
  7569. if (ch === 'x' || ch === 'X') {
  7570. ++index;
  7571. return scanHexLiteral(start);
  7572. }
  7573. if (ch === 'b' || ch === 'B') {
  7574. ++index;
  7575. return scanBinaryLiteral(start);
  7576. }
  7577. if (ch === 'o' || ch === 'O') {
  7578. return scanOctalLiteral(ch, start);
  7579. }
  7580. if (isOctalDigit(ch)) {
  7581. if (isImplicitOctalLiteral()) {
  7582. return scanOctalLiteral(ch, start);
  7583. }
  7584. }
  7585. }
  7586. while (isDecimalDigit(source.charCodeAt(index))) {
  7587. number += source[index++];
  7588. }
  7589. ch = source[index];
  7590. }
  7591. if (ch === '.') {
  7592. number += source[index++];
  7593. while (isDecimalDigit(source.charCodeAt(index))) {
  7594. number += source[index++];
  7595. }
  7596. ch = source[index];
  7597. }
  7598. if (ch === 'e' || ch === 'E') {
  7599. number += source[index++];
  7600. ch = source[index];
  7601. if (ch === '+' || ch === '-') {
  7602. number += source[index++];
  7603. }
  7604. if (isDecimalDigit(source.charCodeAt(index))) {
  7605. while (isDecimalDigit(source.charCodeAt(index))) {
  7606. number += source[index++];
  7607. }
  7608. } else {
  7609. throwUnexpectedToken();
  7610. }
  7611. }
  7612. if (isIdentifierStart(source.charCodeAt(index))) {
  7613. throwUnexpectedToken();
  7614. }
  7615. return {
  7616. type: Token.NumericLiteral,
  7617. value: parseFloat(number),
  7618. lineNumber: lineNumber,
  7619. lineStart: lineStart,
  7620. start: start,
  7621. end: index
  7622. };
  7623. }
  7624. // ECMA-262 11.8.4 String Literals
  7625. function scanStringLiteral() {
  7626. var str = '', quote, start, ch, unescaped, octToDec, octal = false;
  7627. quote = source[index];
  7628. assert((quote === '\'' || quote === '"'),
  7629. 'String literal must starts with a quote');
  7630. start = index;
  7631. ++index;
  7632. while (index < length) {
  7633. ch = source[index++];
  7634. if (ch === quote) {
  7635. quote = '';
  7636. break;
  7637. } else if (ch === '\\') {
  7638. ch = source[index++];
  7639. if (!ch || !isLineTerminator(ch.charCodeAt(0))) {
  7640. switch (ch) {
  7641. case 'u':
  7642. case 'x':
  7643. if (source[index] === '{') {
  7644. ++index;
  7645. str += scanUnicodeCodePointEscape();
  7646. } else {
  7647. unescaped = scanHexEscape(ch);
  7648. if (!unescaped) {
  7649. throw throwUnexpectedToken();
  7650. }
  7651. str += unescaped;
  7652. }
  7653. break;
  7654. case 'n':
  7655. str += '\n';
  7656. break;
  7657. case 'r':
  7658. str += '\r';
  7659. break;
  7660. case 't':
  7661. str += '\t';
  7662. break;
  7663. case 'b':
  7664. str += '\b';
  7665. break;
  7666. case 'f':
  7667. str += '\f';
  7668. break;
  7669. case 'v':
  7670. str += '\x0B';
  7671. break;
  7672. case '8':
  7673. case '9':
  7674. str += ch;
  7675. tolerateUnexpectedToken();
  7676. break;
  7677. default:
  7678. if (isOctalDigit(ch)) {
  7679. octToDec = octalToDecimal(ch);
  7680. octal = octToDec.octal || octal;
  7681. str += String.fromCharCode(octToDec.code);
  7682. } else {
  7683. str += ch;
  7684. }
  7685. break;
  7686. }
  7687. } else {
  7688. ++lineNumber;
  7689. if (ch === '\r' && source[index] === '\n') {
  7690. ++index;
  7691. }
  7692. lineStart = index;
  7693. }
  7694. } else if (isLineTerminator(ch.charCodeAt(0))) {
  7695. break;
  7696. } else {
  7697. str += ch;
  7698. }
  7699. }
  7700. if (quote !== '') {
  7701. index = start;
  7702. throwUnexpectedToken();
  7703. }
  7704. return {
  7705. type: Token.StringLiteral,
  7706. value: str,
  7707. octal: octal,
  7708. lineNumber: startLineNumber,
  7709. lineStart: startLineStart,
  7710. start: start,
  7711. end: index
  7712. };
  7713. }
  7714. // ECMA-262 11.8.6 Template Literal Lexical Components
  7715. function scanTemplate() {
  7716. var cooked = '', ch, start, rawOffset, terminated, head, tail, restore, unescaped;
  7717. terminated = false;
  7718. tail = false;
  7719. start = index;
  7720. head = (source[index] === '`');
  7721. rawOffset = 2;
  7722. ++index;
  7723. while (index < length) {
  7724. ch = source[index++];
  7725. if (ch === '`') {
  7726. rawOffset = 1;
  7727. tail = true;
  7728. terminated = true;
  7729. break;
  7730. } else if (ch === '$') {
  7731. if (source[index] === '{') {
  7732. state.curlyStack.push('${');
  7733. ++index;
  7734. terminated = true;
  7735. break;
  7736. }
  7737. cooked += ch;
  7738. } else if (ch === '\\') {
  7739. ch = source[index++];
  7740. if (!isLineTerminator(ch.charCodeAt(0))) {
  7741. switch (ch) {
  7742. case 'n':
  7743. cooked += '\n';
  7744. break;
  7745. case 'r':
  7746. cooked += '\r';
  7747. break;
  7748. case 't':
  7749. cooked += '\t';
  7750. break;
  7751. case 'u':
  7752. case 'x':
  7753. if (source[index] === '{') {
  7754. ++index;
  7755. cooked += scanUnicodeCodePointEscape();
  7756. } else {
  7757. restore = index;
  7758. unescaped = scanHexEscape(ch);
  7759. if (unescaped) {
  7760. cooked += unescaped;
  7761. } else {
  7762. index = restore;
  7763. cooked += ch;
  7764. }
  7765. }
  7766. break;
  7767. case 'b':
  7768. cooked += '\b';
  7769. break;
  7770. case 'f':
  7771. cooked += '\f';
  7772. break;
  7773. case 'v':
  7774. cooked += '\v';
  7775. break;
  7776. default:
  7777. if (ch === '0') {
  7778. if (isDecimalDigit(source.charCodeAt(index))) {
  7779. // Illegal: \01 \02 and so on
  7780. throwError(Messages.TemplateOctalLiteral);
  7781. }
  7782. cooked += '\0';
  7783. } else if (isOctalDigit(ch)) {
  7784. // Illegal: \1 \2
  7785. throwError(Messages.TemplateOctalLiteral);
  7786. } else {
  7787. cooked += ch;
  7788. }
  7789. break;
  7790. }
  7791. } else {
  7792. ++lineNumber;
  7793. if (ch === '\r' && source[index] === '\n') {
  7794. ++index;
  7795. }
  7796. lineStart = index;
  7797. }
  7798. } else if (isLineTerminator(ch.charCodeAt(0))) {
  7799. ++lineNumber;
  7800. if (ch === '\r' && source[index] === '\n') {
  7801. ++index;
  7802. }
  7803. lineStart = index;
  7804. cooked += '\n';
  7805. } else {
  7806. cooked += ch;
  7807. }
  7808. }
  7809. if (!terminated) {
  7810. throwUnexpectedToken();
  7811. }
  7812. if (!head) {
  7813. state.curlyStack.pop();
  7814. }
  7815. return {
  7816. type: Token.Template,
  7817. value: {
  7818. cooked: cooked,
  7819. raw: source.slice(start + 1, index - rawOffset)
  7820. },
  7821. head: head,
  7822. tail: tail,
  7823. lineNumber: lineNumber,
  7824. lineStart: lineStart,
  7825. start: start,
  7826. end: index
  7827. };
  7828. }
  7829. // ECMA-262 11.8.5 Regular Expression Literals
  7830. function testRegExp(pattern, flags) {
  7831. // The BMP character to use as a replacement for astral symbols when
  7832. // translating an ES6 "u"-flagged pattern to an ES5-compatible
  7833. // approximation.
  7834. // Note: replacing with '\uFFFF' enables false positives in unlikely
  7835. // scenarios. For example, `[\u{1044f}-\u{10440}]` is an invalid
  7836. // pattern that would not be detected by this substitution.
  7837. var astralSubstitute = '\uFFFF',
  7838. tmp = pattern;
  7839. if (flags.indexOf('u') >= 0) {
  7840. tmp = tmp
  7841. // Replace every Unicode escape sequence with the equivalent
  7842. // BMP character or a constant ASCII code point in the case of
  7843. // astral symbols. (See the above note on `astralSubstitute`
  7844. // for more information.)
  7845. .replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, function ($0, $1, $2) {
  7846. var codePoint = parseInt($1 || $2, 16);
  7847. if (codePoint > 0x10FFFF) {
  7848. throwUnexpectedToken(null, Messages.InvalidRegExp);
  7849. }
  7850. if (codePoint <= 0xFFFF) {
  7851. return String.fromCharCode(codePoint);
  7852. }
  7853. return astralSubstitute;
  7854. })
  7855. // Replace each paired surrogate with a single ASCII symbol to
  7856. // avoid throwing on regular expressions that are only valid in
  7857. // combination with the "u" flag.
  7858. .replace(
  7859. /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  7860. astralSubstitute
  7861. );
  7862. }
  7863. // First, detect invalid regular expressions.
  7864. try {
  7865. RegExp(tmp);
  7866. } catch (e) {
  7867. throwUnexpectedToken(null, Messages.InvalidRegExp);
  7868. }
  7869. // Return a regular expression object for this pattern-flag pair, or
  7870. // `null` in case the current environment doesn't support the flags it
  7871. // uses.
  7872. try {
  7873. return new RegExp(pattern, flags);
  7874. } catch (exception) {
  7875. return null;
  7876. }
  7877. }
  7878. function scanRegExpBody() {
  7879. var ch, str, classMarker, terminated, body;
  7880. ch = source[index];
  7881. assert(ch === '/', 'Regular expression literal must start with a slash');
  7882. str = source[index++];
  7883. classMarker = false;
  7884. terminated = false;
  7885. while (index < length) {
  7886. ch = source[index++];
  7887. str += ch;
  7888. if (ch === '\\') {
  7889. ch = source[index++];
  7890. // ECMA-262 7.8.5
  7891. if (isLineTerminator(ch.charCodeAt(0))) {
  7892. throwUnexpectedToken(null, Messages.UnterminatedRegExp);
  7893. }
  7894. str += ch;
  7895. } else if (isLineTerminator(ch.charCodeAt(0))) {
  7896. throwUnexpectedToken(null, Messages.UnterminatedRegExp);
  7897. } else if (classMarker) {
  7898. if (ch === ']') {
  7899. classMarker = false;
  7900. }
  7901. } else {
  7902. if (ch === '/') {
  7903. terminated = true;
  7904. break;
  7905. } else if (ch === '[') {
  7906. classMarker = true;
  7907. }
  7908. }
  7909. }
  7910. if (!terminated) {
  7911. throwUnexpectedToken(null, Messages.UnterminatedRegExp);
  7912. }
  7913. // Exclude leading and trailing slash.
  7914. body = str.substr(1, str.length - 2);
  7915. return {
  7916. value: body,
  7917. literal: str
  7918. };
  7919. }
  7920. function scanRegExpFlags() {
  7921. var ch, str, flags, restore;
  7922. str = '';
  7923. flags = '';
  7924. while (index < length) {
  7925. ch = source[index];
  7926. if (!isIdentifierPart(ch.charCodeAt(0))) {
  7927. break;
  7928. }
  7929. ++index;
  7930. if (ch === '\\' && index < length) {
  7931. ch = source[index];
  7932. if (ch === 'u') {
  7933. ++index;
  7934. restore = index;
  7935. ch = scanHexEscape('u');
  7936. if (ch) {
  7937. flags += ch;
  7938. for (str += '\\u'; restore < index; ++restore) {
  7939. str += source[restore];
  7940. }
  7941. } else {
  7942. index = restore;
  7943. flags += 'u';
  7944. str += '\\u';
  7945. }
  7946. tolerateUnexpectedToken();
  7947. } else {
  7948. str += '\\';
  7949. tolerateUnexpectedToken();
  7950. }
  7951. } else {
  7952. flags += ch;
  7953. str += ch;
  7954. }
  7955. }
  7956. return {
  7957. value: flags,
  7958. literal: str
  7959. };
  7960. }
  7961. function scanRegExp() {
  7962. var start, body, flags, value;
  7963. scanning = true;
  7964. lookahead = null;
  7965. skipComment();
  7966. start = index;
  7967. body = scanRegExpBody();
  7968. flags = scanRegExpFlags();
  7969. value = testRegExp(body.value, flags.value);
  7970. scanning = false;
  7971. if (extra.tokenize) {
  7972. return {
  7973. type: Token.RegularExpression,
  7974. value: value,
  7975. regex: {
  7976. pattern: body.value,
  7977. flags: flags.value
  7978. },
  7979. lineNumber: lineNumber,
  7980. lineStart: lineStart,
  7981. start: start,
  7982. end: index
  7983. };
  7984. }
  7985. return {
  7986. literal: body.literal + flags.literal,
  7987. value: value,
  7988. regex: {
  7989. pattern: body.value,
  7990. flags: flags.value
  7991. },
  7992. start: start,
  7993. end: index
  7994. };
  7995. }
  7996. function collectRegex() {
  7997. var pos, loc, regex, token;
  7998. skipComment();
  7999. pos = index;
  8000. loc = {
  8001. start: {
  8002. line: lineNumber,
  8003. column: index - lineStart
  8004. }
  8005. };
  8006. regex = scanRegExp();
  8007. loc.end = {
  8008. line: lineNumber,
  8009. column: index - lineStart
  8010. };
  8011. /* istanbul ignore next */
  8012. if (!extra.tokenize) {
  8013. // Pop the previous token, which is likely '/' or '/='
  8014. if (extra.tokens.length > 0) {
  8015. token = extra.tokens[extra.tokens.length - 1];
  8016. if (token.range[0] === pos && token.type === 'Punctuator') {
  8017. if (token.value === '/' || token.value === '/=') {
  8018. extra.tokens.pop();
  8019. }
  8020. }
  8021. }
  8022. extra.tokens.push({
  8023. type: 'RegularExpression',
  8024. value: regex.literal,
  8025. regex: regex.regex,
  8026. range: [pos, index],
  8027. loc: loc
  8028. });
  8029. }
  8030. return regex;
  8031. }
  8032. function isIdentifierName(token) {
  8033. return token.type === Token.Identifier ||
  8034. token.type === Token.Keyword ||
  8035. token.type === Token.BooleanLiteral ||
  8036. token.type === Token.NullLiteral;
  8037. }
  8038. // Using the following algorithm:
  8039. // https://github.com/mozilla/sweet.js/wiki/design
  8040. function advanceSlash() {
  8041. var regex, previous, check;
  8042. function testKeyword(value) {
  8043. return value && (value.length > 1) && (value[0] >= 'a') && (value[0] <= 'z');
  8044. }
  8045. previous = extra.tokenValues[extra.tokens.length - 1];
  8046. regex = (previous !== null);
  8047. switch (previous) {
  8048. case 'this':
  8049. case ']':
  8050. regex = false;
  8051. break;
  8052. case ')':
  8053. check = extra.tokenValues[extra.openParenToken - 1];
  8054. regex = (check === 'if' || check === 'while' || check === 'for' || check === 'with');
  8055. break;
  8056. case '}':
  8057. // Dividing a function by anything makes little sense,
  8058. // but we have to check for that.
  8059. regex = false;
  8060. if (testKeyword(extra.tokenValues[extra.openCurlyToken - 3])) {
  8061. // Anonymous function, e.g. function(){} /42
  8062. check = extra.tokenValues[extra.openCurlyToken - 4];
  8063. regex = check ? (FnExprTokens.indexOf(check) < 0) : false;
  8064. } else if (testKeyword(extra.tokenValues[extra.openCurlyToken - 4])) {
  8065. // Named function, e.g. function f(){} /42/
  8066. check = extra.tokenValues[extra.openCurlyToken - 5];
  8067. regex = check ? (FnExprTokens.indexOf(check) < 0) : true;
  8068. }
  8069. }
  8070. return regex ? collectRegex() : scanPunctuator();
  8071. }
  8072. function advance() {
  8073. var cp, token;
  8074. if (index >= length) {
  8075. return {
  8076. type: Token.EOF,
  8077. lineNumber: lineNumber,
  8078. lineStart: lineStart,
  8079. start: index,
  8080. end: index
  8081. };
  8082. }
  8083. cp = source.charCodeAt(index);
  8084. if (isIdentifierStart(cp)) {
  8085. token = scanIdentifier();
  8086. if (strict && isStrictModeReservedWord(token.value)) {
  8087. token.type = Token.Keyword;
  8088. }
  8089. return token;
  8090. }
  8091. // Very common: ( and ) and ;
  8092. if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
  8093. return scanPunctuator();
  8094. }
  8095. // String literal starts with single quote (U+0027) or double quote (U+0022).
  8096. if (cp === 0x27 || cp === 0x22) {
  8097. return scanStringLiteral();
  8098. }
  8099. // Dot (.) U+002E can also start a floating-point number, hence the need
  8100. // to check the next character.
  8101. if (cp === 0x2E) {
  8102. if (isDecimalDigit(source.charCodeAt(index + 1))) {
  8103. return scanNumericLiteral();
  8104. }
  8105. return scanPunctuator();
  8106. }
  8107. if (isDecimalDigit(cp)) {
  8108. return scanNumericLiteral();
  8109. }
  8110. // Slash (/) U+002F can also start a regex.
  8111. if (extra.tokenize && cp === 0x2F) {
  8112. return advanceSlash();
  8113. }
  8114. // Template literals start with ` (U+0060) for template head
  8115. // or } (U+007D) for template middle or template tail.
  8116. if (cp === 0x60 || (cp === 0x7D && state.curlyStack[state.curlyStack.length - 1] === '${')) {
  8117. return scanTemplate();
  8118. }
  8119. // Possible identifier start in a surrogate pair.
  8120. if (cp >= 0xD800 && cp < 0xDFFF) {
  8121. cp = codePointAt(index);
  8122. if (isIdentifierStart(cp)) {
  8123. return scanIdentifier();
  8124. }
  8125. }
  8126. return scanPunctuator();
  8127. }
  8128. function collectToken() {
  8129. var loc, token, value, entry;
  8130. loc = {
  8131. start: {
  8132. line: lineNumber,
  8133. column: index - lineStart
  8134. }
  8135. };
  8136. token = advance();
  8137. loc.end = {
  8138. line: lineNumber,
  8139. column: index - lineStart
  8140. };
  8141. if (token.type !== Token.EOF) {
  8142. value = source.slice(token.start, token.end);
  8143. entry = {
  8144. type: TokenName[token.type],
  8145. value: value,
  8146. range: [token.start, token.end],
  8147. loc: loc
  8148. };
  8149. if (token.regex) {
  8150. entry.regex = {
  8151. pattern: token.regex.pattern,
  8152. flags: token.regex.flags
  8153. };
  8154. }
  8155. if (extra.tokenValues) {
  8156. extra.tokenValues.push((entry.type === 'Punctuator' || entry.type === 'Keyword') ? entry.value : null);
  8157. }
  8158. if (extra.tokenize) {
  8159. if (!extra.range) {
  8160. delete entry.range;
  8161. }
  8162. if (!extra.loc) {
  8163. delete entry.loc;
  8164. }
  8165. if (extra.delegate) {
  8166. entry = extra.delegate(entry);
  8167. }
  8168. }
  8169. extra.tokens.push(entry);
  8170. }
  8171. return token;
  8172. }
  8173. function lex() {
  8174. var token;
  8175. scanning = true;
  8176. lastIndex = index;
  8177. lastLineNumber = lineNumber;
  8178. lastLineStart = lineStart;
  8179. skipComment();
  8180. token = lookahead;
  8181. startIndex = index;
  8182. startLineNumber = lineNumber;
  8183. startLineStart = lineStart;
  8184. lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();
  8185. scanning = false;
  8186. return token;
  8187. }
  8188. function peek() {
  8189. scanning = true;
  8190. skipComment();
  8191. lastIndex = index;
  8192. lastLineNumber = lineNumber;
  8193. lastLineStart = lineStart;
  8194. startIndex = index;
  8195. startLineNumber = lineNumber;
  8196. startLineStart = lineStart;
  8197. lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();
  8198. scanning = false;
  8199. }
  8200. function Position() {
  8201. this.line = startLineNumber;
  8202. this.column = startIndex - startLineStart;
  8203. }
  8204. function SourceLocation() {
  8205. this.start = new Position();
  8206. this.end = null;
  8207. }
  8208. function WrappingSourceLocation(startToken) {
  8209. this.start = {
  8210. line: startToken.lineNumber,
  8211. column: startToken.start - startToken.lineStart
  8212. };
  8213. this.end = null;
  8214. }
  8215. function Node() {
  8216. if (extra.range) {
  8217. this.range = [startIndex, 0];
  8218. }
  8219. if (extra.loc) {
  8220. this.loc = new SourceLocation();
  8221. }
  8222. }
  8223. function WrappingNode(startToken) {
  8224. if (extra.range) {
  8225. this.range = [startToken.start, 0];
  8226. }
  8227. if (extra.loc) {
  8228. this.loc = new WrappingSourceLocation(startToken);
  8229. }
  8230. }
  8231. WrappingNode.prototype = Node.prototype = {
  8232. processComment: function () {
  8233. var lastChild,
  8234. innerComments,
  8235. leadingComments,
  8236. trailingComments,
  8237. bottomRight = extra.bottomRightStack,
  8238. i,
  8239. comment,
  8240. last = bottomRight[bottomRight.length - 1];
  8241. if (this.type === Syntax.Program) {
  8242. if (this.body.length > 0) {
  8243. return;
  8244. }
  8245. }
  8246. /**
  8247. * patch innnerComments for properties empty block
  8248. * `function a() {/** comments **\/}`
  8249. */
  8250. if (this.type === Syntax.BlockStatement && this.body.length === 0) {
  8251. innerComments = [];
  8252. for (i = extra.leadingComments.length - 1; i >= 0; --i) {
  8253. comment = extra.leadingComments[i];
  8254. if (this.range[1] >= comment.range[1]) {
  8255. innerComments.unshift(comment);
  8256. extra.leadingComments.splice(i, 1);
  8257. extra.trailingComments.splice(i, 1);
  8258. }
  8259. }
  8260. if (innerComments.length) {
  8261. this.innerComments = innerComments;
  8262. //bottomRight.push(this);
  8263. return;
  8264. }
  8265. }
  8266. if (extra.trailingComments.length > 0) {
  8267. trailingComments = [];
  8268. for (i = extra.trailingComments.length - 1; i >= 0; --i) {
  8269. comment = extra.trailingComments[i];
  8270. if (comment.range[0] >= this.range[1]) {
  8271. trailingComments.unshift(comment);
  8272. extra.trailingComments.splice(i, 1);
  8273. }
  8274. }
  8275. extra.trailingComments = [];
  8276. } else {
  8277. if (last && last.trailingComments && last.trailingComments[0].range[0] >= this.range[1]) {
  8278. trailingComments = last.trailingComments;
  8279. delete last.trailingComments;
  8280. }
  8281. }
  8282. // Eating the stack.
  8283. while (last && last.range[0] >= this.range[0]) {
  8284. lastChild = bottomRight.pop();
  8285. last = bottomRight[bottomRight.length - 1];
  8286. }
  8287. if (lastChild) {
  8288. if (lastChild.leadingComments) {
  8289. leadingComments = [];
  8290. for (i = lastChild.leadingComments.length - 1; i >= 0; --i) {
  8291. comment = lastChild.leadingComments[i];
  8292. if (comment.range[1] <= this.range[0]) {
  8293. leadingComments.unshift(comment);
  8294. lastChild.leadingComments.splice(i, 1);
  8295. }
  8296. }
  8297. if (!lastChild.leadingComments.length) {
  8298. lastChild.leadingComments = undefined;
  8299. }
  8300. }
  8301. } else if (extra.leadingComments.length > 0) {
  8302. leadingComments = [];
  8303. for (i = extra.leadingComments.length - 1; i >= 0; --i) {
  8304. comment = extra.leadingComments[i];
  8305. if (comment.range[1] <= this.range[0]) {
  8306. leadingComments.unshift(comment);
  8307. extra.leadingComments.splice(i, 1);
  8308. }
  8309. }
  8310. }
  8311. if (leadingComments && leadingComments.length > 0) {
  8312. this.leadingComments = leadingComments;
  8313. }
  8314. if (trailingComments && trailingComments.length > 0) {
  8315. this.trailingComments = trailingComments;
  8316. }
  8317. bottomRight.push(this);
  8318. },
  8319. finish: function () {
  8320. if (extra.range) {
  8321. this.range[1] = lastIndex;
  8322. }
  8323. if (extra.loc) {
  8324. this.loc.end = {
  8325. line: lastLineNumber,
  8326. column: lastIndex - lastLineStart
  8327. };
  8328. if (extra.source) {
  8329. this.loc.source = extra.source;
  8330. }
  8331. }
  8332. if (extra.attachComment) {
  8333. this.processComment();
  8334. }
  8335. },
  8336. finishArrayExpression: function (elements) {
  8337. this.type = Syntax.ArrayExpression;
  8338. this.elements = elements;
  8339. this.finish();
  8340. return this;
  8341. },
  8342. finishArrayPattern: function (elements) {
  8343. this.type = Syntax.ArrayPattern;
  8344. this.elements = elements;
  8345. this.finish();
  8346. return this;
  8347. },
  8348. finishArrowFunctionExpression: function (params, defaults, body, expression) {
  8349. this.type = Syntax.ArrowFunctionExpression;
  8350. this.id = null;
  8351. this.params = params;
  8352. this.defaults = defaults;
  8353. this.body = body;
  8354. this.generator = false;
  8355. this.expression = expression;
  8356. this.finish();
  8357. return this;
  8358. },
  8359. finishAssignmentExpression: function (operator, left, right) {
  8360. this.type = Syntax.AssignmentExpression;
  8361. this.operator = operator;
  8362. this.left = left;
  8363. this.right = right;
  8364. this.finish();
  8365. return this;
  8366. },
  8367. finishAssignmentPattern: function (left, right) {
  8368. this.type = Syntax.AssignmentPattern;
  8369. this.left = left;
  8370. this.right = right;
  8371. this.finish();
  8372. return this;
  8373. },
  8374. finishBinaryExpression: function (operator, left, right) {
  8375. this.type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression : Syntax.BinaryExpression;
  8376. this.operator = operator;
  8377. this.left = left;
  8378. this.right = right;
  8379. this.finish();
  8380. return this;
  8381. },
  8382. finishBlockStatement: function (body) {
  8383. this.type = Syntax.BlockStatement;
  8384. this.body = body;
  8385. this.finish();
  8386. return this;
  8387. },
  8388. finishBreakStatement: function (label) {
  8389. this.type = Syntax.BreakStatement;
  8390. this.label = label;
  8391. this.finish();
  8392. return this;
  8393. },
  8394. finishCallExpression: function (callee, args) {
  8395. this.type = Syntax.CallExpression;
  8396. this.callee = callee;
  8397. this.arguments = args;
  8398. this.finish();
  8399. return this;
  8400. },
  8401. finishCatchClause: function (param, body) {
  8402. this.type = Syntax.CatchClause;
  8403. this.param = param;
  8404. this.body = body;
  8405. this.finish();
  8406. return this;
  8407. },
  8408. finishClassBody: function (body) {
  8409. this.type = Syntax.ClassBody;
  8410. this.body = body;
  8411. this.finish();
  8412. return this;
  8413. },
  8414. finishClassDeclaration: function (id, superClass, body) {
  8415. this.type = Syntax.ClassDeclaration;
  8416. this.id = id;
  8417. this.superClass = superClass;
  8418. this.body = body;
  8419. this.finish();
  8420. return this;
  8421. },
  8422. finishClassExpression: function (id, superClass, body) {
  8423. this.type = Syntax.ClassExpression;
  8424. this.id = id;
  8425. this.superClass = superClass;
  8426. this.body = body;
  8427. this.finish();
  8428. return this;
  8429. },
  8430. finishConditionalExpression: function (test, consequent, alternate) {
  8431. this.type = Syntax.ConditionalExpression;
  8432. this.test = test;
  8433. this.consequent = consequent;
  8434. this.alternate = alternate;
  8435. this.finish();
  8436. return this;
  8437. },
  8438. finishContinueStatement: function (label) {
  8439. this.type = Syntax.ContinueStatement;
  8440. this.label = label;
  8441. this.finish();
  8442. return this;
  8443. },
  8444. finishDebuggerStatement: function () {
  8445. this.type = Syntax.DebuggerStatement;
  8446. this.finish();
  8447. return this;
  8448. },
  8449. finishDoWhileStatement: function (body, test) {
  8450. this.type = Syntax.DoWhileStatement;
  8451. this.body = body;
  8452. this.test = test;
  8453. this.finish();
  8454. return this;
  8455. },
  8456. finishEmptyStatement: function () {
  8457. this.type = Syntax.EmptyStatement;
  8458. this.finish();
  8459. return this;
  8460. },
  8461. finishExpressionStatement: function (expression) {
  8462. this.type = Syntax.ExpressionStatement;
  8463. this.expression = expression;
  8464. this.finish();
  8465. return this;
  8466. },
  8467. finishForStatement: function (init, test, update, body) {
  8468. this.type = Syntax.ForStatement;
  8469. this.init = init;
  8470. this.test = test;
  8471. this.update = update;
  8472. this.body = body;
  8473. this.finish();
  8474. return this;
  8475. },
  8476. finishForOfStatement: function (left, right, body) {
  8477. this.type = Syntax.ForOfStatement;
  8478. this.left = left;
  8479. this.right = right;
  8480. this.body = body;
  8481. this.finish();
  8482. return this;
  8483. },
  8484. finishForInStatement: function (left, right, body) {
  8485. this.type = Syntax.ForInStatement;
  8486. this.left = left;
  8487. this.right = right;
  8488. this.body = body;
  8489. this.each = false;
  8490. this.finish();
  8491. return this;
  8492. },
  8493. finishFunctionDeclaration: function (id, params, defaults, body, generator) {
  8494. this.type = Syntax.FunctionDeclaration;
  8495. this.id = id;
  8496. this.params = params;
  8497. this.defaults = defaults;
  8498. this.body = body;
  8499. this.generator = generator;
  8500. this.expression = false;
  8501. this.finish();
  8502. return this;
  8503. },
  8504. finishFunctionExpression: function (id, params, defaults, body, generator) {
  8505. this.type = Syntax.FunctionExpression;
  8506. this.id = id;
  8507. this.params = params;
  8508. this.defaults = defaults;
  8509. this.body = body;
  8510. this.generator = generator;
  8511. this.expression = false;
  8512. this.finish();
  8513. return this;
  8514. },
  8515. finishIdentifier: function (name) {
  8516. this.type = Syntax.Identifier;
  8517. this.name = name;
  8518. this.finish();
  8519. return this;
  8520. },
  8521. finishIfStatement: function (test, consequent, alternate) {
  8522. this.type = Syntax.IfStatement;
  8523. this.test = test;
  8524. this.consequent = consequent;
  8525. this.alternate = alternate;
  8526. this.finish();
  8527. return this;
  8528. },
  8529. finishLabeledStatement: function (label, body) {
  8530. this.type = Syntax.LabeledStatement;
  8531. this.label = label;
  8532. this.body = body;
  8533. this.finish();
  8534. return this;
  8535. },
  8536. finishLiteral: function (token) {
  8537. this.type = Syntax.Literal;
  8538. this.value = token.value;
  8539. this.raw = source.slice(token.start, token.end);
  8540. if (token.regex) {
  8541. this.regex = token.regex;
  8542. }
  8543. this.finish();
  8544. return this;
  8545. },
  8546. finishMemberExpression: function (accessor, object, property) {
  8547. this.type = Syntax.MemberExpression;
  8548. this.computed = accessor === '[';
  8549. this.object = object;
  8550. this.property = property;
  8551. this.finish();
  8552. return this;
  8553. },
  8554. finishMetaProperty: function (meta, property) {
  8555. this.type = Syntax.MetaProperty;
  8556. this.meta = meta;
  8557. this.property = property;
  8558. this.finish();
  8559. return this;
  8560. },
  8561. finishNewExpression: function (callee, args) {
  8562. this.type = Syntax.NewExpression;
  8563. this.callee = callee;
  8564. this.arguments = args;
  8565. this.finish();
  8566. return this;
  8567. },
  8568. finishObjectExpression: function (properties) {
  8569. this.type = Syntax.ObjectExpression;
  8570. this.properties = properties;
  8571. this.finish();
  8572. return this;
  8573. },
  8574. finishObjectPattern: function (properties) {
  8575. this.type = Syntax.ObjectPattern;
  8576. this.properties = properties;
  8577. this.finish();
  8578. return this;
  8579. },
  8580. finishPostfixExpression: function (operator, argument) {
  8581. this.type = Syntax.UpdateExpression;
  8582. this.operator = operator;
  8583. this.argument = argument;
  8584. this.prefix = false;
  8585. this.finish();
  8586. return this;
  8587. },
  8588. finishProgram: function (body, sourceType) {
  8589. this.type = Syntax.Program;
  8590. this.body = body;
  8591. this.sourceType = sourceType;
  8592. this.finish();
  8593. return this;
  8594. },
  8595. finishProperty: function (kind, key, computed, value, method, shorthand) {
  8596. this.type = Syntax.Property;
  8597. this.key = key;
  8598. this.computed = computed;
  8599. this.value = value;
  8600. this.kind = kind;
  8601. this.method = method;
  8602. this.shorthand = shorthand;
  8603. this.finish();
  8604. return this;
  8605. },
  8606. finishRestElement: function (argument) {
  8607. this.type = Syntax.RestElement;
  8608. this.argument = argument;
  8609. this.finish();
  8610. return this;
  8611. },
  8612. finishReturnStatement: function (argument) {
  8613. this.type = Syntax.ReturnStatement;
  8614. this.argument = argument;
  8615. this.finish();
  8616. return this;
  8617. },
  8618. finishSequenceExpression: function (expressions) {
  8619. this.type = Syntax.SequenceExpression;
  8620. this.expressions = expressions;
  8621. this.finish();
  8622. return this;
  8623. },
  8624. finishSpreadElement: function (argument) {
  8625. this.type = Syntax.SpreadElement;
  8626. this.argument = argument;
  8627. this.finish();
  8628. return this;
  8629. },
  8630. finishSwitchCase: function (test, consequent) {
  8631. this.type = Syntax.SwitchCase;
  8632. this.test = test;
  8633. this.consequent = consequent;
  8634. this.finish();
  8635. return this;
  8636. },
  8637. finishSuper: function () {
  8638. this.type = Syntax.Super;
  8639. this.finish();
  8640. return this;
  8641. },
  8642. finishSwitchStatement: function (discriminant, cases) {
  8643. this.type = Syntax.SwitchStatement;
  8644. this.discriminant = discriminant;
  8645. this.cases = cases;
  8646. this.finish();
  8647. return this;
  8648. },
  8649. finishTaggedTemplateExpression: function (tag, quasi) {
  8650. this.type = Syntax.TaggedTemplateExpression;
  8651. this.tag = tag;
  8652. this.quasi = quasi;
  8653. this.finish();
  8654. return this;
  8655. },
  8656. finishTemplateElement: function (value, tail) {
  8657. this.type = Syntax.TemplateElement;
  8658. this.value = value;
  8659. this.tail = tail;
  8660. this.finish();
  8661. return this;
  8662. },
  8663. finishTemplateLiteral: function (quasis, expressions) {
  8664. this.type = Syntax.TemplateLiteral;
  8665. this.quasis = quasis;
  8666. this.expressions = expressions;
  8667. this.finish();
  8668. return this;
  8669. },
  8670. finishThisExpression: function () {
  8671. this.type = Syntax.ThisExpression;
  8672. this.finish();
  8673. return this;
  8674. },
  8675. finishThrowStatement: function (argument) {
  8676. this.type = Syntax.ThrowStatement;
  8677. this.argument = argument;
  8678. this.finish();
  8679. return this;
  8680. },
  8681. finishTryStatement: function (block, handler, finalizer) {
  8682. this.type = Syntax.TryStatement;
  8683. this.block = block;
  8684. this.guardedHandlers = [];
  8685. this.handlers = handler ? [handler] : [];
  8686. this.handler = handler;
  8687. this.finalizer = finalizer;
  8688. this.finish();
  8689. return this;
  8690. },
  8691. finishUnaryExpression: function (operator, argument) {
  8692. this.type = (operator === '++' || operator === '--') ? Syntax.UpdateExpression : Syntax.UnaryExpression;
  8693. this.operator = operator;
  8694. this.argument = argument;
  8695. this.prefix = true;
  8696. this.finish();
  8697. return this;
  8698. },
  8699. finishVariableDeclaration: function (declarations) {
  8700. this.type = Syntax.VariableDeclaration;
  8701. this.declarations = declarations;
  8702. this.kind = 'var';
  8703. this.finish();
  8704. return this;
  8705. },
  8706. finishLexicalDeclaration: function (declarations, kind) {
  8707. this.type = Syntax.VariableDeclaration;
  8708. this.declarations = declarations;
  8709. this.kind = kind;
  8710. this.finish();
  8711. return this;
  8712. },
  8713. finishVariableDeclarator: function (id, init) {
  8714. this.type = Syntax.VariableDeclarator;
  8715. this.id = id;
  8716. this.init = init;
  8717. this.finish();
  8718. return this;
  8719. },
  8720. finishWhileStatement: function (test, body) {
  8721. this.type = Syntax.WhileStatement;
  8722. this.test = test;
  8723. this.body = body;
  8724. this.finish();
  8725. return this;
  8726. },
  8727. finishWithStatement: function (object, body) {
  8728. this.type = Syntax.WithStatement;
  8729. this.object = object;
  8730. this.body = body;
  8731. this.finish();
  8732. return this;
  8733. },
  8734. finishExportSpecifier: function (local, exported) {
  8735. this.type = Syntax.ExportSpecifier;
  8736. this.exported = exported || local;
  8737. this.local = local;
  8738. this.finish();
  8739. return this;
  8740. },
  8741. finishImportDefaultSpecifier: function (local) {
  8742. this.type = Syntax.ImportDefaultSpecifier;
  8743. this.local = local;
  8744. this.finish();
  8745. return this;
  8746. },
  8747. finishImportNamespaceSpecifier: function (local) {
  8748. this.type = Syntax.ImportNamespaceSpecifier;
  8749. this.local = local;
  8750. this.finish();
  8751. return this;
  8752. },
  8753. finishExportNamedDeclaration: function (declaration, specifiers, src) {
  8754. this.type = Syntax.ExportNamedDeclaration;
  8755. this.declaration = declaration;
  8756. this.specifiers = specifiers;
  8757. this.source = src;
  8758. this.finish();
  8759. return this;
  8760. },
  8761. finishExportDefaultDeclaration: function (declaration) {
  8762. this.type = Syntax.ExportDefaultDeclaration;
  8763. this.declaration = declaration;
  8764. this.finish();
  8765. return this;
  8766. },
  8767. finishExportAllDeclaration: function (src) {
  8768. this.type = Syntax.ExportAllDeclaration;
  8769. this.source = src;
  8770. this.finish();
  8771. return this;
  8772. },
  8773. finishImportSpecifier: function (local, imported) {
  8774. this.type = Syntax.ImportSpecifier;
  8775. this.local = local || imported;
  8776. this.imported = imported;
  8777. this.finish();
  8778. return this;
  8779. },
  8780. finishImportDeclaration: function (specifiers, src) {
  8781. this.type = Syntax.ImportDeclaration;
  8782. this.specifiers = specifiers;
  8783. this.source = src;
  8784. this.finish();
  8785. return this;
  8786. },
  8787. finishYieldExpression: function (argument, delegate) {
  8788. this.type = Syntax.YieldExpression;
  8789. this.argument = argument;
  8790. this.delegate = delegate;
  8791. this.finish();
  8792. return this;
  8793. }
  8794. };
  8795. function recordError(error) {
  8796. var e, existing;
  8797. for (e = 0; e < extra.errors.length; e++) {
  8798. existing = extra.errors[e];
  8799. // Prevent duplicated error.
  8800. /* istanbul ignore next */
  8801. if (existing.index === error.index && existing.message === error.message) {
  8802. return;
  8803. }
  8804. }
  8805. extra.errors.push(error);
  8806. }
  8807. function constructError(msg, column) {
  8808. var error = new Error(msg);
  8809. try {
  8810. throw error;
  8811. } catch (base) {
  8812. /* istanbul ignore else */
  8813. if (Object.create && Object.defineProperty) {
  8814. error = Object.create(base);
  8815. Object.defineProperty(error, 'column', { value: column });
  8816. }
  8817. } finally {
  8818. return error;
  8819. }
  8820. }
  8821. function createError(line, pos, description) {
  8822. var msg, column, error;
  8823. msg = 'Line ' + line + ': ' + description;
  8824. column = pos - (scanning ? lineStart : lastLineStart) + 1;
  8825. error = constructError(msg, column);
  8826. error.lineNumber = line;
  8827. error.description = description;
  8828. error.index = pos;
  8829. return error;
  8830. }
  8831. // Throw an exception
  8832. function throwError(messageFormat) {
  8833. var args, msg;
  8834. args = Array.prototype.slice.call(arguments, 1);
  8835. msg = messageFormat.replace(/%(\d)/g,
  8836. function (whole, idx) {
  8837. assert(idx < args.length, 'Message reference must be in range');
  8838. return args[idx];
  8839. }
  8840. );
  8841. throw createError(lastLineNumber, lastIndex, msg);
  8842. }
  8843. function tolerateError(messageFormat) {
  8844. var args, msg, error;
  8845. args = Array.prototype.slice.call(arguments, 1);
  8846. /* istanbul ignore next */
  8847. msg = messageFormat.replace(/%(\d)/g,
  8848. function (whole, idx) {
  8849. assert(idx < args.length, 'Message reference must be in range');
  8850. return args[idx];
  8851. }
  8852. );
  8853. error = createError(lineNumber, lastIndex, msg);
  8854. if (extra.errors) {
  8855. recordError(error);
  8856. } else {
  8857. throw error;
  8858. }
  8859. }
  8860. // Throw an exception because of the token.
  8861. function unexpectedTokenError(token, message) {
  8862. var value, msg = message || Messages.UnexpectedToken;
  8863. if (token) {
  8864. if (!message) {
  8865. msg = (token.type === Token.EOF) ? Messages.UnexpectedEOS :
  8866. (token.type === Token.Identifier) ? Messages.UnexpectedIdentifier :
  8867. (token.type === Token.NumericLiteral) ? Messages.UnexpectedNumber :
  8868. (token.type === Token.StringLiteral) ? Messages.UnexpectedString :
  8869. (token.type === Token.Template) ? Messages.UnexpectedTemplate :
  8870. Messages.UnexpectedToken;
  8871. if (token.type === Token.Keyword) {
  8872. if (isFutureReservedWord(token.value)) {
  8873. msg = Messages.UnexpectedReserved;
  8874. } else if (strict && isStrictModeReservedWord(token.value)) {
  8875. msg = Messages.StrictReservedWord;
  8876. }
  8877. }
  8878. }
  8879. value = (token.type === Token.Template) ? token.value.raw : token.value;
  8880. } else {
  8881. value = 'ILLEGAL';
  8882. }
  8883. msg = msg.replace('%0', value);
  8884. return (token && typeof token.lineNumber === 'number') ?
  8885. createError(token.lineNumber, token.start, msg) :
  8886. createError(scanning ? lineNumber : lastLineNumber, scanning ? index : lastIndex, msg);
  8887. }
  8888. function throwUnexpectedToken(token, message) {
  8889. throw unexpectedTokenError(token, message);
  8890. }
  8891. function tolerateUnexpectedToken(token, message) {
  8892. var error = unexpectedTokenError(token, message);
  8893. if (extra.errors) {
  8894. recordError(error);
  8895. } else {
  8896. throw error;
  8897. }
  8898. }
  8899. // Expect the next token to match the specified punctuator.
  8900. // If not, an exception will be thrown.
  8901. function expect(value) {
  8902. var token = lex();
  8903. if (token.type !== Token.Punctuator || token.value !== value) {
  8904. throwUnexpectedToken(token);
  8905. }
  8906. }
  8907. /**
  8908. * @name expectCommaSeparator
  8909. * @description Quietly expect a comma when in tolerant mode, otherwise delegates
  8910. * to <code>expect(value)</code>
  8911. * @since 2.0
  8912. */
  8913. function expectCommaSeparator() {
  8914. var token;
  8915. if (extra.errors) {
  8916. token = lookahead;
  8917. if (token.type === Token.Punctuator && token.value === ',') {
  8918. lex();
  8919. } else if (token.type === Token.Punctuator && token.value === ';') {
  8920. lex();
  8921. tolerateUnexpectedToken(token);
  8922. } else {
  8923. tolerateUnexpectedToken(token, Messages.UnexpectedToken);
  8924. }
  8925. } else {
  8926. expect(',');
  8927. }
  8928. }
  8929. // Expect the next token to match the specified keyword.
  8930. // If not, an exception will be thrown.
  8931. function expectKeyword(keyword) {
  8932. var token = lex();
  8933. if (token.type !== Token.Keyword || token.value !== keyword) {
  8934. throwUnexpectedToken(token);
  8935. }
  8936. }
  8937. // Return true if the next token matches the specified punctuator.
  8938. function match(value) {
  8939. return lookahead.type === Token.Punctuator && lookahead.value === value;
  8940. }
  8941. // Return true if the next token matches the specified keyword
  8942. function matchKeyword(keyword) {
  8943. return lookahead.type === Token.Keyword && lookahead.value === keyword;
  8944. }
  8945. // Return true if the next token matches the specified contextual keyword
  8946. // (where an identifier is sometimes a keyword depending on the context)
  8947. function matchContextualKeyword(keyword) {
  8948. return lookahead.type === Token.Identifier && lookahead.value === keyword;
  8949. }
  8950. // Return true if the next token is an assignment operator
  8951. function matchAssign() {
  8952. var op;
  8953. if (lookahead.type !== Token.Punctuator) {
  8954. return false;
  8955. }
  8956. op = lookahead.value;
  8957. return op === '=' ||
  8958. op === '*=' ||
  8959. op === '/=' ||
  8960. op === '%=' ||
  8961. op === '+=' ||
  8962. op === '-=' ||
  8963. op === '<<=' ||
  8964. op === '>>=' ||
  8965. op === '>>>=' ||
  8966. op === '&=' ||
  8967. op === '^=' ||
  8968. op === '|=';
  8969. }
  8970. function consumeSemicolon() {
  8971. // Catch the very common case first: immediately a semicolon (U+003B).
  8972. if (source.charCodeAt(startIndex) === 0x3B || match(';')) {
  8973. lex();
  8974. return;
  8975. }
  8976. if (hasLineTerminator) {
  8977. return;
  8978. }
  8979. // FIXME(ikarienator): this is seemingly an issue in the previous location info convention.
  8980. lastIndex = startIndex;
  8981. lastLineNumber = startLineNumber;
  8982. lastLineStart = startLineStart;
  8983. if (lookahead.type !== Token.EOF && !match('}')) {
  8984. throwUnexpectedToken(lookahead);
  8985. }
  8986. }
  8987. // Cover grammar support.
  8988. //
  8989. // When an assignment expression position starts with an left parenthesis, the determination of the type
  8990. // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
  8991. // or the first comma. This situation also defers the determination of all the expressions nested in the pair.
  8992. //
  8993. // There are three productions that can be parsed in a parentheses pair that needs to be determined
  8994. // after the outermost pair is closed. They are:
  8995. //
  8996. // 1. AssignmentExpression
  8997. // 2. BindingElements
  8998. // 3. AssignmentTargets
  8999. //
  9000. // In order to avoid exponential backtracking, we use two flags to denote if the production can be
  9001. // binding element or assignment target.
  9002. //
  9003. // The three productions have the relationship:
  9004. //
  9005. // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
  9006. //
  9007. // with a single exception that CoverInitializedName when used directly in an Expression, generates
  9008. // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
  9009. // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
  9010. //
  9011. // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
  9012. // effect the current flags. This means the production the parser parses is only used as an expression. Therefore
  9013. // the CoverInitializedName check is conducted.
  9014. //
  9015. // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
  9016. // the flags outside of the parser. This means the production the parser parses is used as a part of a potential
  9017. // pattern. The CoverInitializedName check is deferred.
  9018. function isolateCoverGrammar(parser) {
  9019. var oldIsBindingElement = isBindingElement,
  9020. oldIsAssignmentTarget = isAssignmentTarget,
  9021. oldFirstCoverInitializedNameError = firstCoverInitializedNameError,
  9022. result;
  9023. isBindingElement = true;
  9024. isAssignmentTarget = true;
  9025. firstCoverInitializedNameError = null;
  9026. result = parser();
  9027. if (firstCoverInitializedNameError !== null) {
  9028. throwUnexpectedToken(firstCoverInitializedNameError);
  9029. }
  9030. isBindingElement = oldIsBindingElement;
  9031. isAssignmentTarget = oldIsAssignmentTarget;
  9032. firstCoverInitializedNameError = oldFirstCoverInitializedNameError;
  9033. return result;
  9034. }
  9035. function inheritCoverGrammar(parser) {
  9036. var oldIsBindingElement = isBindingElement,
  9037. oldIsAssignmentTarget = isAssignmentTarget,
  9038. oldFirstCoverInitializedNameError = firstCoverInitializedNameError,
  9039. result;
  9040. isBindingElement = true;
  9041. isAssignmentTarget = true;
  9042. firstCoverInitializedNameError = null;
  9043. result = parser();
  9044. isBindingElement = isBindingElement && oldIsBindingElement;
  9045. isAssignmentTarget = isAssignmentTarget && oldIsAssignmentTarget;
  9046. firstCoverInitializedNameError = oldFirstCoverInitializedNameError || firstCoverInitializedNameError;
  9047. return result;
  9048. }
  9049. // ECMA-262 13.3.3 Destructuring Binding Patterns
  9050. function parseArrayPattern(params, kind) {
  9051. var node = new Node(), elements = [], rest, restNode;
  9052. expect('[');
  9053. while (!match(']')) {
  9054. if (match(',')) {
  9055. lex();
  9056. elements.push(null);
  9057. } else {
  9058. if (match('...')) {
  9059. restNode = new Node();
  9060. lex();
  9061. params.push(lookahead);
  9062. rest = parseVariableIdentifier(kind);
  9063. elements.push(restNode.finishRestElement(rest));
  9064. break;
  9065. } else {
  9066. elements.push(parsePatternWithDefault(params, kind));
  9067. }
  9068. if (!match(']')) {
  9069. expect(',');
  9070. }
  9071. }
  9072. }
  9073. expect(']');
  9074. return node.finishArrayPattern(elements);
  9075. }
  9076. function parsePropertyPattern(params, kind) {
  9077. var node = new Node(), key, keyToken, computed = match('['), init;
  9078. if (lookahead.type === Token.Identifier) {
  9079. keyToken = lookahead;
  9080. key = parseVariableIdentifier();
  9081. if (match('=')) {
  9082. params.push(keyToken);
  9083. lex();
  9084. init = parseAssignmentExpression();
  9085. return node.finishProperty(
  9086. 'init', key, false,
  9087. new WrappingNode(keyToken).finishAssignmentPattern(key, init), false, true);
  9088. } else if (!match(':')) {
  9089. params.push(keyToken);
  9090. return node.finishProperty('init', key, false, key, false, true);
  9091. }
  9092. } else {
  9093. key = parseObjectPropertyKey();
  9094. }
  9095. expect(':');
  9096. init = parsePatternWithDefault(params, kind);
  9097. return node.finishProperty('init', key, computed, init, false, false);
  9098. }
  9099. function parseObjectPattern(params, kind) {
  9100. var node = new Node(), properties = [];
  9101. expect('{');
  9102. while (!match('}')) {
  9103. properties.push(parsePropertyPattern(params, kind));
  9104. if (!match('}')) {
  9105. expect(',');
  9106. }
  9107. }
  9108. lex();
  9109. return node.finishObjectPattern(properties);
  9110. }
  9111. function parsePattern(params, kind) {
  9112. if (match('[')) {
  9113. return parseArrayPattern(params, kind);
  9114. } else if (match('{')) {
  9115. return parseObjectPattern(params, kind);
  9116. } else if (matchKeyword('let')) {
  9117. if (kind === 'const' || kind === 'let') {
  9118. tolerateUnexpectedToken(lookahead, Messages.UnexpectedToken);
  9119. }
  9120. }
  9121. params.push(lookahead);
  9122. return parseVariableIdentifier(kind);
  9123. }
  9124. function parsePatternWithDefault(params, kind) {
  9125. var startToken = lookahead, pattern, previousAllowYield, right;
  9126. pattern = parsePattern(params, kind);
  9127. if (match('=')) {
  9128. lex();
  9129. previousAllowYield = state.allowYield;
  9130. state.allowYield = true;
  9131. right = isolateCoverGrammar(parseAssignmentExpression);
  9132. state.allowYield = previousAllowYield;
  9133. pattern = new WrappingNode(startToken).finishAssignmentPattern(pattern, right);
  9134. }
  9135. return pattern;
  9136. }
  9137. // ECMA-262 12.2.5 Array Initializer
  9138. function parseArrayInitializer() {
  9139. var elements = [], node = new Node(), restSpread;
  9140. expect('[');
  9141. while (!match(']')) {
  9142. if (match(',')) {
  9143. lex();
  9144. elements.push(null);
  9145. } else if (match('...')) {
  9146. restSpread = new Node();
  9147. lex();
  9148. restSpread.finishSpreadElement(inheritCoverGrammar(parseAssignmentExpression));
  9149. if (!match(']')) {
  9150. isAssignmentTarget = isBindingElement = false;
  9151. expect(',');
  9152. }
  9153. elements.push(restSpread);
  9154. } else {
  9155. elements.push(inheritCoverGrammar(parseAssignmentExpression));
  9156. if (!match(']')) {
  9157. expect(',');
  9158. }
  9159. }
  9160. }
  9161. lex();
  9162. return node.finishArrayExpression(elements);
  9163. }
  9164. // ECMA-262 12.2.6 Object Initializer
  9165. function parsePropertyFunction(node, paramInfo, isGenerator) {
  9166. var previousStrict, body;
  9167. isAssignmentTarget = isBindingElement = false;
  9168. previousStrict = strict;
  9169. body = isolateCoverGrammar(parseFunctionSourceElements);
  9170. if (strict && paramInfo.firstRestricted) {
  9171. tolerateUnexpectedToken(paramInfo.firstRestricted, paramInfo.message);
  9172. }
  9173. if (strict && paramInfo.stricted) {
  9174. tolerateUnexpectedToken(paramInfo.stricted, paramInfo.message);
  9175. }
  9176. strict = previousStrict;
  9177. return node.finishFunctionExpression(null, paramInfo.params, paramInfo.defaults, body, isGenerator);
  9178. }
  9179. function parsePropertyMethodFunction() {
  9180. var params, method, node = new Node(),
  9181. previousAllowYield = state.allowYield;
  9182. state.allowYield = false;
  9183. params = parseParams();
  9184. state.allowYield = previousAllowYield;
  9185. state.allowYield = false;
  9186. method = parsePropertyFunction(node, params, false);
  9187. state.allowYield = previousAllowYield;
  9188. return method;
  9189. }
  9190. function parseObjectPropertyKey() {
  9191. var token, node = new Node(), expr;
  9192. token = lex();
  9193. // Note: This function is called only from parseObjectProperty(), where
  9194. // EOF and Punctuator tokens are already filtered out.
  9195. switch (token.type) {
  9196. case Token.StringLiteral:
  9197. case Token.NumericLiteral:
  9198. if (strict && token.octal) {
  9199. tolerateUnexpectedToken(token, Messages.StrictOctalLiteral);
  9200. }
  9201. return node.finishLiteral(token);
  9202. case Token.Identifier:
  9203. case Token.BooleanLiteral:
  9204. case Token.NullLiteral:
  9205. case Token.Keyword:
  9206. return node.finishIdentifier(token.value);
  9207. case Token.Punctuator:
  9208. if (token.value === '[') {
  9209. expr = isolateCoverGrammar(parseAssignmentExpression);
  9210. expect(']');
  9211. return expr;
  9212. }
  9213. break;
  9214. }
  9215. throwUnexpectedToken(token);
  9216. }
  9217. function lookaheadPropertyName() {
  9218. switch (lookahead.type) {
  9219. case Token.Identifier:
  9220. case Token.StringLiteral:
  9221. case Token.BooleanLiteral:
  9222. case Token.NullLiteral:
  9223. case Token.NumericLiteral:
  9224. case Token.Keyword:
  9225. return true;
  9226. case Token.Punctuator:
  9227. return lookahead.value === '[';
  9228. }
  9229. return false;
  9230. }
  9231. // This function is to try to parse a MethodDefinition as defined in 14.3. But in the case of object literals,
  9232. // it might be called at a position where there is in fact a short hand identifier pattern or a data property.
  9233. // This can only be determined after we consumed up to the left parentheses.
  9234. //
  9235. // In order to avoid back tracking, it returns `null` if the position is not a MethodDefinition and the caller
  9236. // is responsible to visit other options.
  9237. function tryParseMethodDefinition(token, key, computed, node) {
  9238. var value, options, methodNode, params,
  9239. previousAllowYield = state.allowYield;
  9240. if (token.type === Token.Identifier) {
  9241. // check for `get` and `set`;
  9242. if (token.value === 'get' && lookaheadPropertyName()) {
  9243. computed = match('[');
  9244. key = parseObjectPropertyKey();
  9245. methodNode = new Node();
  9246. expect('(');
  9247. expect(')');
  9248. state.allowYield = false;
  9249. value = parsePropertyFunction(methodNode, {
  9250. params: [],
  9251. defaults: [],
  9252. stricted: null,
  9253. firstRestricted: null,
  9254. message: null
  9255. }, false);
  9256. state.allowYield = previousAllowYield;
  9257. return node.finishProperty('get', key, computed, value, false, false);
  9258. } else if (token.value === 'set' && lookaheadPropertyName()) {
  9259. computed = match('[');
  9260. key = parseObjectPropertyKey();
  9261. methodNode = new Node();
  9262. expect('(');
  9263. options = {
  9264. params: [],
  9265. defaultCount: 0,
  9266. defaults: [],
  9267. firstRestricted: null,
  9268. paramSet: {}
  9269. };
  9270. if (match(')')) {
  9271. tolerateUnexpectedToken(lookahead);
  9272. } else {
  9273. state.allowYield = false;
  9274. parseParam(options);
  9275. state.allowYield = previousAllowYield;
  9276. if (options.defaultCount === 0) {
  9277. options.defaults = [];
  9278. }
  9279. }
  9280. expect(')');
  9281. state.allowYield = false;
  9282. value = parsePropertyFunction(methodNode, options, false);
  9283. state.allowYield = previousAllowYield;
  9284. return node.finishProperty('set', key, computed, value, false, false);
  9285. }
  9286. } else if (token.type === Token.Punctuator && token.value === '*' && lookaheadPropertyName()) {
  9287. computed = match('[');
  9288. key = parseObjectPropertyKey();
  9289. methodNode = new Node();
  9290. state.allowYield = true;
  9291. params = parseParams();
  9292. state.allowYield = previousAllowYield;
  9293. state.allowYield = false;
  9294. value = parsePropertyFunction(methodNode, params, true);
  9295. state.allowYield = previousAllowYield;
  9296. return node.finishProperty('init', key, computed, value, true, false);
  9297. }
  9298. if (key && match('(')) {
  9299. value = parsePropertyMethodFunction();
  9300. return node.finishProperty('init', key, computed, value, true, false);
  9301. }
  9302. // Not a MethodDefinition.
  9303. return null;
  9304. }
  9305. function parseObjectProperty(hasProto) {
  9306. var token = lookahead, node = new Node(), computed, key, maybeMethod, proto, value;
  9307. computed = match('[');
  9308. if (match('*')) {
  9309. lex();
  9310. } else {
  9311. key = parseObjectPropertyKey();
  9312. }
  9313. maybeMethod = tryParseMethodDefinition(token, key, computed, node);
  9314. if (maybeMethod) {
  9315. return maybeMethod;
  9316. }
  9317. if (!key) {
  9318. throwUnexpectedToken(lookahead);
  9319. }
  9320. // Check for duplicated __proto__
  9321. if (!computed) {
  9322. proto = (key.type === Syntax.Identifier && key.name === '__proto__') ||
  9323. (key.type === Syntax.Literal && key.value === '__proto__');
  9324. if (hasProto.value && proto) {
  9325. tolerateError(Messages.DuplicateProtoProperty);
  9326. }
  9327. hasProto.value |= proto;
  9328. }
  9329. if (match(':')) {
  9330. lex();
  9331. value = inheritCoverGrammar(parseAssignmentExpression);
  9332. return node.finishProperty('init', key, computed, value, false, false);
  9333. }
  9334. if (token.type === Token.Identifier) {
  9335. if (match('=')) {
  9336. firstCoverInitializedNameError = lookahead;
  9337. lex();
  9338. value = isolateCoverGrammar(parseAssignmentExpression);
  9339. return node.finishProperty('init', key, computed,
  9340. new WrappingNode(token).finishAssignmentPattern(key, value), false, true);
  9341. }
  9342. return node.finishProperty('init', key, computed, key, false, true);
  9343. }
  9344. throwUnexpectedToken(lookahead);
  9345. }
  9346. function parseObjectInitializer() {
  9347. var properties = [], hasProto = {value: false}, node = new Node();
  9348. expect('{');
  9349. while (!match('}')) {
  9350. properties.push(parseObjectProperty(hasProto));
  9351. if (!match('}')) {
  9352. expectCommaSeparator();
  9353. }
  9354. }
  9355. expect('}');
  9356. return node.finishObjectExpression(properties);
  9357. }
  9358. function reinterpretExpressionAsPattern(expr) {
  9359. var i;
  9360. switch (expr.type) {
  9361. case Syntax.Identifier:
  9362. case Syntax.MemberExpression:
  9363. case Syntax.RestElement:
  9364. case Syntax.AssignmentPattern:
  9365. break;
  9366. case Syntax.SpreadElement:
  9367. expr.type = Syntax.RestElement;
  9368. reinterpretExpressionAsPattern(expr.argument);
  9369. break;
  9370. case Syntax.ArrayExpression:
  9371. expr.type = Syntax.ArrayPattern;
  9372. for (i = 0; i < expr.elements.length; i++) {
  9373. if (expr.elements[i] !== null) {
  9374. reinterpretExpressionAsPattern(expr.elements[i]);
  9375. }
  9376. }
  9377. break;
  9378. case Syntax.ObjectExpression:
  9379. expr.type = Syntax.ObjectPattern;
  9380. for (i = 0; i < expr.properties.length; i++) {
  9381. reinterpretExpressionAsPattern(expr.properties[i].value);
  9382. }
  9383. break;
  9384. case Syntax.AssignmentExpression:
  9385. expr.type = Syntax.AssignmentPattern;
  9386. reinterpretExpressionAsPattern(expr.left);
  9387. break;
  9388. default:
  9389. // Allow other node type for tolerant parsing.
  9390. break;
  9391. }
  9392. }
  9393. // ECMA-262 12.2.9 Template Literals
  9394. function parseTemplateElement(option) {
  9395. var node, token;
  9396. if (lookahead.type !== Token.Template || (option.head && !lookahead.head)) {
  9397. throwUnexpectedToken();
  9398. }
  9399. node = new Node();
  9400. token = lex();
  9401. return node.finishTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail);
  9402. }
  9403. function parseTemplateLiteral() {
  9404. var quasi, quasis, expressions, node = new Node();
  9405. quasi = parseTemplateElement({ head: true });
  9406. quasis = [quasi];
  9407. expressions = [];
  9408. while (!quasi.tail) {
  9409. expressions.push(parseExpression());
  9410. quasi = parseTemplateElement({ head: false });
  9411. quasis.push(quasi);
  9412. }
  9413. return node.finishTemplateLiteral(quasis, expressions);
  9414. }
  9415. // ECMA-262 12.2.10 The Grouping Operator
  9416. function parseGroupExpression() {
  9417. var expr, expressions, startToken, i, params = [];
  9418. expect('(');
  9419. if (match(')')) {
  9420. lex();
  9421. if (!match('=>')) {
  9422. expect('=>');
  9423. }
  9424. return {
  9425. type: PlaceHolders.ArrowParameterPlaceHolder,
  9426. params: [],
  9427. rawParams: []
  9428. };
  9429. }
  9430. startToken = lookahead;
  9431. if (match('...')) {
  9432. expr = parseRestElement(params);
  9433. expect(')');
  9434. if (!match('=>')) {
  9435. expect('=>');
  9436. }
  9437. return {
  9438. type: PlaceHolders.ArrowParameterPlaceHolder,
  9439. params: [expr]
  9440. };
  9441. }
  9442. isBindingElement = true;
  9443. expr = inheritCoverGrammar(parseAssignmentExpression);
  9444. if (match(',')) {
  9445. isAssignmentTarget = false;
  9446. expressions = [expr];
  9447. while (startIndex < length) {
  9448. if (!match(',')) {
  9449. break;
  9450. }
  9451. lex();
  9452. if (match('...')) {
  9453. if (!isBindingElement) {
  9454. throwUnexpectedToken(lookahead);
  9455. }
  9456. expressions.push(parseRestElement(params));
  9457. expect(')');
  9458. if (!match('=>')) {
  9459. expect('=>');
  9460. }
  9461. isBindingElement = false;
  9462. for (i = 0; i < expressions.length; i++) {
  9463. reinterpretExpressionAsPattern(expressions[i]);
  9464. }
  9465. return {
  9466. type: PlaceHolders.ArrowParameterPlaceHolder,
  9467. params: expressions
  9468. };
  9469. }
  9470. expressions.push(inheritCoverGrammar(parseAssignmentExpression));
  9471. }
  9472. expr = new WrappingNode(startToken).finishSequenceExpression(expressions);
  9473. }
  9474. expect(')');
  9475. if (match('=>')) {
  9476. if (expr.type === Syntax.Identifier && expr.name === 'yield') {
  9477. return {
  9478. type: PlaceHolders.ArrowParameterPlaceHolder,
  9479. params: [expr]
  9480. };
  9481. }
  9482. if (!isBindingElement) {
  9483. throwUnexpectedToken(lookahead);
  9484. }
  9485. if (expr.type === Syntax.SequenceExpression) {
  9486. for (i = 0; i < expr.expressions.length; i++) {
  9487. reinterpretExpressionAsPattern(expr.expressions[i]);
  9488. }
  9489. } else {
  9490. reinterpretExpressionAsPattern(expr);
  9491. }
  9492. expr = {
  9493. type: PlaceHolders.ArrowParameterPlaceHolder,
  9494. params: expr.type === Syntax.SequenceExpression ? expr.expressions : [expr]
  9495. };
  9496. }
  9497. isBindingElement = false;
  9498. return expr;
  9499. }
  9500. // ECMA-262 12.2 Primary Expressions
  9501. function parsePrimaryExpression() {
  9502. var type, token, expr, node;
  9503. if (match('(')) {
  9504. isBindingElement = false;
  9505. return inheritCoverGrammar(parseGroupExpression);
  9506. }
  9507. if (match('[')) {
  9508. return inheritCoverGrammar(parseArrayInitializer);
  9509. }
  9510. if (match('{')) {
  9511. return inheritCoverGrammar(parseObjectInitializer);
  9512. }
  9513. type = lookahead.type;
  9514. node = new Node();
  9515. if (type === Token.Identifier) {
  9516. if (state.sourceType === 'module' && lookahead.value === 'await') {
  9517. tolerateUnexpectedToken(lookahead);
  9518. }
  9519. expr = node.finishIdentifier(lex().value);
  9520. } else if (type === Token.StringLiteral || type === Token.NumericLiteral) {
  9521. isAssignmentTarget = isBindingElement = false;
  9522. if (strict && lookahead.octal) {
  9523. tolerateUnexpectedToken(lookahead, Messages.StrictOctalLiteral);
  9524. }
  9525. expr = node.finishLiteral(lex());
  9526. } else if (type === Token.Keyword) {
  9527. if (!strict && state.allowYield && matchKeyword('yield')) {
  9528. return parseNonComputedProperty();
  9529. }
  9530. if (!strict && matchKeyword('let')) {
  9531. return node.finishIdentifier(lex().value);
  9532. }
  9533. isAssignmentTarget = isBindingElement = false;
  9534. if (matchKeyword('function')) {
  9535. return parseFunctionExpression();
  9536. }
  9537. if (matchKeyword('this')) {
  9538. lex();
  9539. return node.finishThisExpression();
  9540. }
  9541. if (matchKeyword('class')) {
  9542. return parseClassExpression();
  9543. }
  9544. throwUnexpectedToken(lex());
  9545. } else if (type === Token.BooleanLiteral) {
  9546. isAssignmentTarget = isBindingElement = false;
  9547. token = lex();
  9548. token.value = (token.value === 'true');
  9549. expr = node.finishLiteral(token);
  9550. } else if (type === Token.NullLiteral) {
  9551. isAssignmentTarget = isBindingElement = false;
  9552. token = lex();
  9553. token.value = null;
  9554. expr = node.finishLiteral(token);
  9555. } else if (match('/') || match('/=')) {
  9556. isAssignmentTarget = isBindingElement = false;
  9557. index = startIndex;
  9558. if (typeof extra.tokens !== 'undefined') {
  9559. token = collectRegex();
  9560. } else {
  9561. token = scanRegExp();
  9562. }
  9563. lex();
  9564. expr = node.finishLiteral(token);
  9565. } else if (type === Token.Template) {
  9566. expr = parseTemplateLiteral();
  9567. } else {
  9568. throwUnexpectedToken(lex());
  9569. }
  9570. return expr;
  9571. }
  9572. // ECMA-262 12.3 Left-Hand-Side Expressions
  9573. function parseArguments() {
  9574. var args = [], expr;
  9575. expect('(');
  9576. if (!match(')')) {
  9577. while (startIndex < length) {
  9578. if (match('...')) {
  9579. expr = new Node();
  9580. lex();
  9581. expr.finishSpreadElement(isolateCoverGrammar(parseAssignmentExpression));
  9582. } else {
  9583. expr = isolateCoverGrammar(parseAssignmentExpression);
  9584. }
  9585. args.push(expr);
  9586. if (match(')')) {
  9587. break;
  9588. }
  9589. expectCommaSeparator();
  9590. }
  9591. }
  9592. expect(')');
  9593. return args;
  9594. }
  9595. function parseNonComputedProperty() {
  9596. var token, node = new Node();
  9597. token = lex();
  9598. if (!isIdentifierName(token)) {
  9599. throwUnexpectedToken(token);
  9600. }
  9601. return node.finishIdentifier(token.value);
  9602. }
  9603. function parseNonComputedMember() {
  9604. expect('.');
  9605. return parseNonComputedProperty();
  9606. }
  9607. function parseComputedMember() {
  9608. var expr;
  9609. expect('[');
  9610. expr = isolateCoverGrammar(parseExpression);
  9611. expect(']');
  9612. return expr;
  9613. }
  9614. // ECMA-262 12.3.3 The new Operator
  9615. function parseNewExpression() {
  9616. var callee, args, node = new Node();
  9617. expectKeyword('new');
  9618. if (match('.')) {
  9619. lex();
  9620. if (lookahead.type === Token.Identifier && lookahead.value === 'target') {
  9621. if (state.inFunctionBody) {
  9622. lex();
  9623. return node.finishMetaProperty('new', 'target');
  9624. }
  9625. }
  9626. throwUnexpectedToken(lookahead);
  9627. }
  9628. callee = isolateCoverGrammar(parseLeftHandSideExpression);
  9629. args = match('(') ? parseArguments() : [];
  9630. isAssignmentTarget = isBindingElement = false;
  9631. return node.finishNewExpression(callee, args);
  9632. }
  9633. // ECMA-262 12.3.4 Function Calls
  9634. function parseLeftHandSideExpressionAllowCall() {
  9635. var quasi, expr, args, property, startToken, previousAllowIn = state.allowIn;
  9636. startToken = lookahead;
  9637. state.allowIn = true;
  9638. if (matchKeyword('super') && state.inFunctionBody) {
  9639. expr = new Node();
  9640. lex();
  9641. expr = expr.finishSuper();
  9642. if (!match('(') && !match('.') && !match('[')) {
  9643. throwUnexpectedToken(lookahead);
  9644. }
  9645. } else {
  9646. expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);
  9647. }
  9648. for (;;) {
  9649. if (match('.')) {
  9650. isBindingElement = false;
  9651. isAssignmentTarget = true;
  9652. property = parseNonComputedMember();
  9653. expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);
  9654. } else if (match('(')) {
  9655. isBindingElement = false;
  9656. isAssignmentTarget = false;
  9657. args = parseArguments();
  9658. expr = new WrappingNode(startToken).finishCallExpression(expr, args);
  9659. } else if (match('[')) {
  9660. isBindingElement = false;
  9661. isAssignmentTarget = true;
  9662. property = parseComputedMember();
  9663. expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);
  9664. } else if (lookahead.type === Token.Template && lookahead.head) {
  9665. quasi = parseTemplateLiteral();
  9666. expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);
  9667. } else {
  9668. break;
  9669. }
  9670. }
  9671. state.allowIn = previousAllowIn;
  9672. return expr;
  9673. }
  9674. // ECMA-262 12.3 Left-Hand-Side Expressions
  9675. function parseLeftHandSideExpression() {
  9676. var quasi, expr, property, startToken;
  9677. assert(state.allowIn, 'callee of new expression always allow in keyword.');
  9678. startToken = lookahead;
  9679. if (matchKeyword('super') && state.inFunctionBody) {
  9680. expr = new Node();
  9681. lex();
  9682. expr = expr.finishSuper();
  9683. if (!match('[') && !match('.')) {
  9684. throwUnexpectedToken(lookahead);
  9685. }
  9686. } else {
  9687. expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);
  9688. }
  9689. for (;;) {
  9690. if (match('[')) {
  9691. isBindingElement = false;
  9692. isAssignmentTarget = true;
  9693. property = parseComputedMember();
  9694. expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);
  9695. } else if (match('.')) {
  9696. isBindingElement = false;
  9697. isAssignmentTarget = true;
  9698. property = parseNonComputedMember();
  9699. expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);
  9700. } else if (lookahead.type === Token.Template && lookahead.head) {
  9701. quasi = parseTemplateLiteral();
  9702. expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);
  9703. } else {
  9704. break;
  9705. }
  9706. }
  9707. return expr;
  9708. }
  9709. // ECMA-262 12.4 Postfix Expressions
  9710. function parsePostfixExpression() {
  9711. var expr, token, startToken = lookahead;
  9712. expr = inheritCoverGrammar(parseLeftHandSideExpressionAllowCall);
  9713. if (!hasLineTerminator && lookahead.type === Token.Punctuator) {
  9714. if (match('++') || match('--')) {
  9715. // ECMA-262 11.3.1, 11.3.2
  9716. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  9717. tolerateError(Messages.StrictLHSPostfix);
  9718. }
  9719. if (!isAssignmentTarget) {
  9720. tolerateError(Messages.InvalidLHSInAssignment);
  9721. }
  9722. isAssignmentTarget = isBindingElement = false;
  9723. token = lex();
  9724. expr = new WrappingNode(startToken).finishPostfixExpression(token.value, expr);
  9725. }
  9726. }
  9727. return expr;
  9728. }
  9729. // ECMA-262 12.5 Unary Operators
  9730. function parseUnaryExpression() {
  9731. var token, expr, startToken;
  9732. if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {
  9733. expr = parsePostfixExpression();
  9734. } else if (match('++') || match('--')) {
  9735. startToken = lookahead;
  9736. token = lex();
  9737. expr = inheritCoverGrammar(parseUnaryExpression);
  9738. // ECMA-262 11.4.4, 11.4.5
  9739. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  9740. tolerateError(Messages.StrictLHSPrefix);
  9741. }
  9742. if (!isAssignmentTarget) {
  9743. tolerateError(Messages.InvalidLHSInAssignment);
  9744. }
  9745. expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
  9746. isAssignmentTarget = isBindingElement = false;
  9747. } else if (match('+') || match('-') || match('~') || match('!')) {
  9748. startToken = lookahead;
  9749. token = lex();
  9750. expr = inheritCoverGrammar(parseUnaryExpression);
  9751. expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
  9752. isAssignmentTarget = isBindingElement = false;
  9753. } else if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {
  9754. startToken = lookahead;
  9755. token = lex();
  9756. expr = inheritCoverGrammar(parseUnaryExpression);
  9757. expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
  9758. if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {
  9759. tolerateError(Messages.StrictDelete);
  9760. }
  9761. isAssignmentTarget = isBindingElement = false;
  9762. } else {
  9763. expr = parsePostfixExpression();
  9764. }
  9765. return expr;
  9766. }
  9767. function binaryPrecedence(token, allowIn) {
  9768. var prec = 0;
  9769. if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {
  9770. return 0;
  9771. }
  9772. switch (token.value) {
  9773. case '||':
  9774. prec = 1;
  9775. break;
  9776. case '&&':
  9777. prec = 2;
  9778. break;
  9779. case '|':
  9780. prec = 3;
  9781. break;
  9782. case '^':
  9783. prec = 4;
  9784. break;
  9785. case '&':
  9786. prec = 5;
  9787. break;
  9788. case '==':
  9789. case '!=':
  9790. case '===':
  9791. case '!==':
  9792. prec = 6;
  9793. break;
  9794. case '<':
  9795. case '>':
  9796. case '<=':
  9797. case '>=':
  9798. case 'instanceof':
  9799. prec = 7;
  9800. break;
  9801. case 'in':
  9802. prec = allowIn ? 7 : 0;
  9803. break;
  9804. case '<<':
  9805. case '>>':
  9806. case '>>>':
  9807. prec = 8;
  9808. break;
  9809. case '+':
  9810. case '-':
  9811. prec = 9;
  9812. break;
  9813. case '*':
  9814. case '/':
  9815. case '%':
  9816. prec = 11;
  9817. break;
  9818. default:
  9819. break;
  9820. }
  9821. return prec;
  9822. }
  9823. // ECMA-262 12.6 Multiplicative Operators
  9824. // ECMA-262 12.7 Additive Operators
  9825. // ECMA-262 12.8 Bitwise Shift Operators
  9826. // ECMA-262 12.9 Relational Operators
  9827. // ECMA-262 12.10 Equality Operators
  9828. // ECMA-262 12.11 Binary Bitwise Operators
  9829. // ECMA-262 12.12 Binary Logical Operators
  9830. function parseBinaryExpression() {
  9831. var marker, markers, expr, token, prec, stack, right, operator, left, i;
  9832. marker = lookahead;
  9833. left = inheritCoverGrammar(parseUnaryExpression);
  9834. token = lookahead;
  9835. prec = binaryPrecedence(token, state.allowIn);
  9836. if (prec === 0) {
  9837. return left;
  9838. }
  9839. isAssignmentTarget = isBindingElement = false;
  9840. token.prec = prec;
  9841. lex();
  9842. markers = [marker, lookahead];
  9843. right = isolateCoverGrammar(parseUnaryExpression);
  9844. stack = [left, token, right];
  9845. while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {
  9846. // Reduce: make a binary expression from the three topmost entries.
  9847. while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
  9848. right = stack.pop();
  9849. operator = stack.pop().value;
  9850. left = stack.pop();
  9851. markers.pop();
  9852. expr = new WrappingNode(markers[markers.length - 1]).finishBinaryExpression(operator, left, right);
  9853. stack.push(expr);
  9854. }
  9855. // Shift.
  9856. token = lex();
  9857. token.prec = prec;
  9858. stack.push(token);
  9859. markers.push(lookahead);
  9860. expr = isolateCoverGrammar(parseUnaryExpression);
  9861. stack.push(expr);
  9862. }
  9863. // Final reduce to clean-up the stack.
  9864. i = stack.length - 1;
  9865. expr = stack[i];
  9866. markers.pop();
  9867. while (i > 1) {
  9868. expr = new WrappingNode(markers.pop()).finishBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
  9869. i -= 2;
  9870. }
  9871. return expr;
  9872. }
  9873. // ECMA-262 12.13 Conditional Operator
  9874. function parseConditionalExpression() {
  9875. var expr, previousAllowIn, consequent, alternate, startToken;
  9876. startToken = lookahead;
  9877. expr = inheritCoverGrammar(parseBinaryExpression);
  9878. if (match('?')) {
  9879. lex();
  9880. previousAllowIn = state.allowIn;
  9881. state.allowIn = true;
  9882. consequent = isolateCoverGrammar(parseAssignmentExpression);
  9883. state.allowIn = previousAllowIn;
  9884. expect(':');
  9885. alternate = isolateCoverGrammar(parseAssignmentExpression);
  9886. expr = new WrappingNode(startToken).finishConditionalExpression(expr, consequent, alternate);
  9887. isAssignmentTarget = isBindingElement = false;
  9888. }
  9889. return expr;
  9890. }
  9891. // ECMA-262 14.2 Arrow Function Definitions
  9892. function parseConciseBody() {
  9893. if (match('{')) {
  9894. return parseFunctionSourceElements();
  9895. }
  9896. return isolateCoverGrammar(parseAssignmentExpression);
  9897. }
  9898. function checkPatternParam(options, param) {
  9899. var i;
  9900. switch (param.type) {
  9901. case Syntax.Identifier:
  9902. validateParam(options, param, param.name);
  9903. break;
  9904. case Syntax.RestElement:
  9905. checkPatternParam(options, param.argument);
  9906. break;
  9907. case Syntax.AssignmentPattern:
  9908. checkPatternParam(options, param.left);
  9909. break;
  9910. case Syntax.ArrayPattern:
  9911. for (i = 0; i < param.elements.length; i++) {
  9912. if (param.elements[i] !== null) {
  9913. checkPatternParam(options, param.elements[i]);
  9914. }
  9915. }
  9916. break;
  9917. case Syntax.YieldExpression:
  9918. break;
  9919. default:
  9920. assert(param.type === Syntax.ObjectPattern, 'Invalid type');
  9921. for (i = 0; i < param.properties.length; i++) {
  9922. checkPatternParam(options, param.properties[i].value);
  9923. }
  9924. break;
  9925. }
  9926. }
  9927. function reinterpretAsCoverFormalsList(expr) {
  9928. var i, len, param, params, defaults, defaultCount, options, token;
  9929. defaults = [];
  9930. defaultCount = 0;
  9931. params = [expr];
  9932. switch (expr.type) {
  9933. case Syntax.Identifier:
  9934. break;
  9935. case PlaceHolders.ArrowParameterPlaceHolder:
  9936. params = expr.params;
  9937. break;
  9938. default:
  9939. return null;
  9940. }
  9941. options = {
  9942. paramSet: {}
  9943. };
  9944. for (i = 0, len = params.length; i < len; i += 1) {
  9945. param = params[i];
  9946. switch (param.type) {
  9947. case Syntax.AssignmentPattern:
  9948. params[i] = param.left;
  9949. if (param.right.type === Syntax.YieldExpression) {
  9950. if (param.right.argument) {
  9951. throwUnexpectedToken(lookahead);
  9952. }
  9953. param.right.type = Syntax.Identifier;
  9954. param.right.name = 'yield';
  9955. delete param.right.argument;
  9956. delete param.right.delegate;
  9957. }
  9958. defaults.push(param.right);
  9959. ++defaultCount;
  9960. checkPatternParam(options, param.left);
  9961. break;
  9962. default:
  9963. checkPatternParam(options, param);
  9964. params[i] = param;
  9965. defaults.push(null);
  9966. break;
  9967. }
  9968. }
  9969. if (strict || !state.allowYield) {
  9970. for (i = 0, len = params.length; i < len; i += 1) {
  9971. param = params[i];
  9972. if (param.type === Syntax.YieldExpression) {
  9973. throwUnexpectedToken(lookahead);
  9974. }
  9975. }
  9976. }
  9977. if (options.message === Messages.StrictParamDupe) {
  9978. token = strict ? options.stricted : options.firstRestricted;
  9979. throwUnexpectedToken(token, options.message);
  9980. }
  9981. if (defaultCount === 0) {
  9982. defaults = [];
  9983. }
  9984. return {
  9985. params: params,
  9986. defaults: defaults,
  9987. stricted: options.stricted,
  9988. firstRestricted: options.firstRestricted,
  9989. message: options.message
  9990. };
  9991. }
  9992. function parseArrowFunctionExpression(options, node) {
  9993. var previousStrict, previousAllowYield, body;
  9994. if (hasLineTerminator) {
  9995. tolerateUnexpectedToken(lookahead);
  9996. }
  9997. expect('=>');
  9998. previousStrict = strict;
  9999. previousAllowYield = state.allowYield;
  10000. state.allowYield = true;
  10001. body = parseConciseBody();
  10002. if (strict && options.firstRestricted) {
  10003. throwUnexpectedToken(options.firstRestricted, options.message);
  10004. }
  10005. if (strict && options.stricted) {
  10006. tolerateUnexpectedToken(options.stricted, options.message);
  10007. }
  10008. strict = previousStrict;
  10009. state.allowYield = previousAllowYield;
  10010. return node.finishArrowFunctionExpression(options.params, options.defaults, body, body.type !== Syntax.BlockStatement);
  10011. }
  10012. // ECMA-262 14.4 Yield expression
  10013. function parseYieldExpression() {
  10014. var argument, expr, delegate, previousAllowYield;
  10015. argument = null;
  10016. expr = new Node();
  10017. delegate = false;
  10018. expectKeyword('yield');
  10019. if (!hasLineTerminator) {
  10020. previousAllowYield = state.allowYield;
  10021. state.allowYield = false;
  10022. delegate = match('*');
  10023. if (delegate) {
  10024. lex();
  10025. argument = parseAssignmentExpression();
  10026. } else {
  10027. if (!match(';') && !match('}') && !match(')') && lookahead.type !== Token.EOF) {
  10028. argument = parseAssignmentExpression();
  10029. }
  10030. }
  10031. state.allowYield = previousAllowYield;
  10032. }
  10033. return expr.finishYieldExpression(argument, delegate);
  10034. }
  10035. // ECMA-262 12.14 Assignment Operators
  10036. function parseAssignmentExpression() {
  10037. var token, expr, right, list, startToken;
  10038. startToken = lookahead;
  10039. token = lookahead;
  10040. if (!state.allowYield && matchKeyword('yield')) {
  10041. return parseYieldExpression();
  10042. }
  10043. expr = parseConditionalExpression();
  10044. if (expr.type === PlaceHolders.ArrowParameterPlaceHolder || match('=>')) {
  10045. isAssignmentTarget = isBindingElement = false;
  10046. list = reinterpretAsCoverFormalsList(expr);
  10047. if (list) {
  10048. firstCoverInitializedNameError = null;
  10049. return parseArrowFunctionExpression(list, new WrappingNode(startToken));
  10050. }
  10051. return expr;
  10052. }
  10053. if (matchAssign()) {
  10054. if (!isAssignmentTarget) {
  10055. tolerateError(Messages.InvalidLHSInAssignment);
  10056. }
  10057. // ECMA-262 12.1.1
  10058. if (strict && expr.type === Syntax.Identifier) {
  10059. if (isRestrictedWord(expr.name)) {
  10060. tolerateUnexpectedToken(token, Messages.StrictLHSAssignment);
  10061. }
  10062. if (isStrictModeReservedWord(expr.name)) {
  10063. tolerateUnexpectedToken(token, Messages.StrictReservedWord);
  10064. }
  10065. }
  10066. if (!match('=')) {
  10067. isAssignmentTarget = isBindingElement = false;
  10068. } else {
  10069. reinterpretExpressionAsPattern(expr);
  10070. }
  10071. token = lex();
  10072. right = isolateCoverGrammar(parseAssignmentExpression);
  10073. expr = new WrappingNode(startToken).finishAssignmentExpression(token.value, expr, right);
  10074. firstCoverInitializedNameError = null;
  10075. }
  10076. return expr;
  10077. }
  10078. // ECMA-262 12.15 Comma Operator
  10079. function parseExpression() {
  10080. var expr, startToken = lookahead, expressions;
  10081. expr = isolateCoverGrammar(parseAssignmentExpression);
  10082. if (match(',')) {
  10083. expressions = [expr];
  10084. while (startIndex < length) {
  10085. if (!match(',')) {
  10086. break;
  10087. }
  10088. lex();
  10089. expressions.push(isolateCoverGrammar(parseAssignmentExpression));
  10090. }
  10091. expr = new WrappingNode(startToken).finishSequenceExpression(expressions);
  10092. }
  10093. return expr;
  10094. }
  10095. // ECMA-262 13.2 Block
  10096. function parseStatementListItem() {
  10097. if (lookahead.type === Token.Keyword) {
  10098. switch (lookahead.value) {
  10099. case 'export':
  10100. if (state.sourceType !== 'module') {
  10101. tolerateUnexpectedToken(lookahead, Messages.IllegalExportDeclaration);
  10102. }
  10103. return parseExportDeclaration();
  10104. case 'import':
  10105. if (state.sourceType !== 'module') {
  10106. tolerateUnexpectedToken(lookahead, Messages.IllegalImportDeclaration);
  10107. }
  10108. return parseImportDeclaration();
  10109. case 'const':
  10110. return parseLexicalDeclaration({inFor: false});
  10111. case 'function':
  10112. return parseFunctionDeclaration(new Node());
  10113. case 'class':
  10114. return parseClassDeclaration();
  10115. }
  10116. }
  10117. if (matchKeyword('let') && isLexicalDeclaration()) {
  10118. return parseLexicalDeclaration({inFor: false});
  10119. }
  10120. return parseStatement();
  10121. }
  10122. function parseStatementList() {
  10123. var list = [];
  10124. while (startIndex < length) {
  10125. if (match('}')) {
  10126. break;
  10127. }
  10128. list.push(parseStatementListItem());
  10129. }
  10130. return list;
  10131. }
  10132. function parseBlock() {
  10133. var block, node = new Node();
  10134. expect('{');
  10135. block = parseStatementList();
  10136. expect('}');
  10137. return node.finishBlockStatement(block);
  10138. }
  10139. // ECMA-262 13.3.2 Variable Statement
  10140. function parseVariableIdentifier(kind) {
  10141. var token, node = new Node();
  10142. token = lex();
  10143. if (token.type === Token.Keyword && token.value === 'yield') {
  10144. if (strict) {
  10145. tolerateUnexpectedToken(token, Messages.StrictReservedWord);
  10146. } if (!state.allowYield) {
  10147. throwUnexpectedToken(token);
  10148. }
  10149. } else if (token.type !== Token.Identifier) {
  10150. if (strict && token.type === Token.Keyword && isStrictModeReservedWord(token.value)) {
  10151. tolerateUnexpectedToken(token, Messages.StrictReservedWord);
  10152. } else {
  10153. if (strict || token.value !== 'let' || kind !== 'var') {
  10154. throwUnexpectedToken(token);
  10155. }
  10156. }
  10157. } else if (state.sourceType === 'module' && token.type === Token.Identifier && token.value === 'await') {
  10158. tolerateUnexpectedToken(token);
  10159. }
  10160. return node.finishIdentifier(token.value);
  10161. }
  10162. function parseVariableDeclaration(options) {
  10163. var init = null, id, node = new Node(), params = [];
  10164. id = parsePattern(params, 'var');
  10165. // ECMA-262 12.2.1
  10166. if (strict && isRestrictedWord(id.name)) {
  10167. tolerateError(Messages.StrictVarName);
  10168. }
  10169. if (match('=')) {
  10170. lex();
  10171. init = isolateCoverGrammar(parseAssignmentExpression);
  10172. } else if (id.type !== Syntax.Identifier && !options.inFor) {
  10173. expect('=');
  10174. }
  10175. return node.finishVariableDeclarator(id, init);
  10176. }
  10177. function parseVariableDeclarationList(options) {
  10178. var opt, list;
  10179. opt = { inFor: options.inFor };
  10180. list = [parseVariableDeclaration(opt)];
  10181. while (match(',')) {
  10182. lex();
  10183. list.push(parseVariableDeclaration(opt));
  10184. }
  10185. return list;
  10186. }
  10187. function parseVariableStatement(node) {
  10188. var declarations;
  10189. expectKeyword('var');
  10190. declarations = parseVariableDeclarationList({ inFor: false });
  10191. consumeSemicolon();
  10192. return node.finishVariableDeclaration(declarations);
  10193. }
  10194. // ECMA-262 13.3.1 Let and Const Declarations
  10195. function parseLexicalBinding(kind, options) {
  10196. var init = null, id, node = new Node(), params = [];
  10197. id = parsePattern(params, kind);
  10198. // ECMA-262 12.2.1
  10199. if (strict && id.type === Syntax.Identifier && isRestrictedWord(id.name)) {
  10200. tolerateError(Messages.StrictVarName);
  10201. }
  10202. if (kind === 'const') {
  10203. if (!matchKeyword('in') && !matchContextualKeyword('of')) {
  10204. expect('=');
  10205. init = isolateCoverGrammar(parseAssignmentExpression);
  10206. }
  10207. } else if ((!options.inFor && id.type !== Syntax.Identifier) || match('=')) {
  10208. expect('=');
  10209. init = isolateCoverGrammar(parseAssignmentExpression);
  10210. }
  10211. return node.finishVariableDeclarator(id, init);
  10212. }
  10213. function parseBindingList(kind, options) {
  10214. var list = [parseLexicalBinding(kind, options)];
  10215. while (match(',')) {
  10216. lex();
  10217. list.push(parseLexicalBinding(kind, options));
  10218. }
  10219. return list;
  10220. }
  10221. function tokenizerState() {
  10222. return {
  10223. index: index,
  10224. lineNumber: lineNumber,
  10225. lineStart: lineStart,
  10226. hasLineTerminator: hasLineTerminator,
  10227. lastIndex: lastIndex,
  10228. lastLineNumber: lastLineNumber,
  10229. lastLineStart: lastLineStart,
  10230. startIndex: startIndex,
  10231. startLineNumber: startLineNumber,
  10232. startLineStart: startLineStart,
  10233. lookahead: lookahead,
  10234. tokenCount: extra.tokens ? extra.tokens.length : 0
  10235. };
  10236. }
  10237. function resetTokenizerState(ts) {
  10238. index = ts.index;
  10239. lineNumber = ts.lineNumber;
  10240. lineStart = ts.lineStart;
  10241. hasLineTerminator = ts.hasLineTerminator;
  10242. lastIndex = ts.lastIndex;
  10243. lastLineNumber = ts.lastLineNumber;
  10244. lastLineStart = ts.lastLineStart;
  10245. startIndex = ts.startIndex;
  10246. startLineNumber = ts.startLineNumber;
  10247. startLineStart = ts.startLineStart;
  10248. lookahead = ts.lookahead;
  10249. if (extra.tokens) {
  10250. extra.tokens.splice(ts.tokenCount, extra.tokens.length);
  10251. }
  10252. }
  10253. function isLexicalDeclaration() {
  10254. var lexical, ts;
  10255. ts = tokenizerState();
  10256. lex();
  10257. lexical = (lookahead.type === Token.Identifier) || match('[') || match('{') ||
  10258. matchKeyword('let') || matchKeyword('yield');
  10259. resetTokenizerState(ts);
  10260. return lexical;
  10261. }
  10262. function parseLexicalDeclaration(options) {
  10263. var kind, declarations, node = new Node();
  10264. kind = lex().value;
  10265. assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
  10266. declarations = parseBindingList(kind, options);
  10267. consumeSemicolon();
  10268. return node.finishLexicalDeclaration(declarations, kind);
  10269. }
  10270. function parseRestElement(params) {
  10271. var param, node = new Node();
  10272. lex();
  10273. if (match('{')) {
  10274. throwError(Messages.ObjectPatternAsRestParameter);
  10275. }
  10276. params.push(lookahead);
  10277. param = parseVariableIdentifier();
  10278. if (match('=')) {
  10279. throwError(Messages.DefaultRestParameter);
  10280. }
  10281. if (!match(')')) {
  10282. throwError(Messages.ParameterAfterRestParameter);
  10283. }
  10284. return node.finishRestElement(param);
  10285. }
  10286. // ECMA-262 13.4 Empty Statement
  10287. function parseEmptyStatement(node) {
  10288. expect(';');
  10289. return node.finishEmptyStatement();
  10290. }
  10291. // ECMA-262 12.4 Expression Statement
  10292. function parseExpressionStatement(node) {
  10293. var expr = parseExpression();
  10294. consumeSemicolon();
  10295. return node.finishExpressionStatement(expr);
  10296. }
  10297. // ECMA-262 13.6 If statement
  10298. function parseIfStatement(node) {
  10299. var test, consequent, alternate;
  10300. expectKeyword('if');
  10301. expect('(');
  10302. test = parseExpression();
  10303. expect(')');
  10304. consequent = parseStatement();
  10305. if (matchKeyword('else')) {
  10306. lex();
  10307. alternate = parseStatement();
  10308. } else {
  10309. alternate = null;
  10310. }
  10311. return node.finishIfStatement(test, consequent, alternate);
  10312. }
  10313. // ECMA-262 13.7 Iteration Statements
  10314. function parseDoWhileStatement(node) {
  10315. var body, test, oldInIteration;
  10316. expectKeyword('do');
  10317. oldInIteration = state.inIteration;
  10318. state.inIteration = true;
  10319. body = parseStatement();
  10320. state.inIteration = oldInIteration;
  10321. expectKeyword('while');
  10322. expect('(');
  10323. test = parseExpression();
  10324. expect(')');
  10325. if (match(';')) {
  10326. lex();
  10327. }
  10328. return node.finishDoWhileStatement(body, test);
  10329. }
  10330. function parseWhileStatement(node) {
  10331. var test, body, oldInIteration;
  10332. expectKeyword('while');
  10333. expect('(');
  10334. test = parseExpression();
  10335. expect(')');
  10336. oldInIteration = state.inIteration;
  10337. state.inIteration = true;
  10338. body = parseStatement();
  10339. state.inIteration = oldInIteration;
  10340. return node.finishWhileStatement(test, body);
  10341. }
  10342. function parseForStatement(node) {
  10343. var init, forIn, initSeq, initStartToken, test, update, left, right, kind, declarations,
  10344. body, oldInIteration, previousAllowIn = state.allowIn;
  10345. init = test = update = null;
  10346. forIn = true;
  10347. expectKeyword('for');
  10348. expect('(');
  10349. if (match(';')) {
  10350. lex();
  10351. } else {
  10352. if (matchKeyword('var')) {
  10353. init = new Node();
  10354. lex();
  10355. state.allowIn = false;
  10356. declarations = parseVariableDeclarationList({ inFor: true });
  10357. state.allowIn = previousAllowIn;
  10358. if (declarations.length === 1 && matchKeyword('in')) {
  10359. init = init.finishVariableDeclaration(declarations);
  10360. lex();
  10361. left = init;
  10362. right = parseExpression();
  10363. init = null;
  10364. } else if (declarations.length === 1 && declarations[0].init === null && matchContextualKeyword('of')) {
  10365. init = init.finishVariableDeclaration(declarations);
  10366. lex();
  10367. left = init;
  10368. right = parseAssignmentExpression();
  10369. init = null;
  10370. forIn = false;
  10371. } else {
  10372. init = init.finishVariableDeclaration(declarations);
  10373. expect(';');
  10374. }
  10375. } else if (matchKeyword('const') || matchKeyword('let')) {
  10376. init = new Node();
  10377. kind = lex().value;
  10378. if (!strict && lookahead.value === 'in') {
  10379. init = init.finishIdentifier(kind);
  10380. lex();
  10381. left = init;
  10382. right = parseExpression();
  10383. init = null;
  10384. } else {
  10385. state.allowIn = false;
  10386. declarations = parseBindingList(kind, {inFor: true});
  10387. state.allowIn = previousAllowIn;
  10388. if (declarations.length === 1 && declarations[0].init === null && matchKeyword('in')) {
  10389. init = init.finishLexicalDeclaration(declarations, kind);
  10390. lex();
  10391. left = init;
  10392. right = parseExpression();
  10393. init = null;
  10394. } else if (declarations.length === 1 && declarations[0].init === null && matchContextualKeyword('of')) {
  10395. init = init.finishLexicalDeclaration(declarations, kind);
  10396. lex();
  10397. left = init;
  10398. right = parseAssignmentExpression();
  10399. init = null;
  10400. forIn = false;
  10401. } else {
  10402. consumeSemicolon();
  10403. init = init.finishLexicalDeclaration(declarations, kind);
  10404. }
  10405. }
  10406. } else {
  10407. initStartToken = lookahead;
  10408. state.allowIn = false;
  10409. init = inheritCoverGrammar(parseAssignmentExpression);
  10410. state.allowIn = previousAllowIn;
  10411. if (matchKeyword('in')) {
  10412. if (!isAssignmentTarget) {
  10413. tolerateError(Messages.InvalidLHSInForIn);
  10414. }
  10415. lex();
  10416. reinterpretExpressionAsPattern(init);
  10417. left = init;
  10418. right = parseExpression();
  10419. init = null;
  10420. } else if (matchContextualKeyword('of')) {
  10421. if (!isAssignmentTarget) {
  10422. tolerateError(Messages.InvalidLHSInForLoop);
  10423. }
  10424. lex();
  10425. reinterpretExpressionAsPattern(init);
  10426. left = init;
  10427. right = parseAssignmentExpression();
  10428. init = null;
  10429. forIn = false;
  10430. } else {
  10431. if (match(',')) {
  10432. initSeq = [init];
  10433. while (match(',')) {
  10434. lex();
  10435. initSeq.push(isolateCoverGrammar(parseAssignmentExpression));
  10436. }
  10437. init = new WrappingNode(initStartToken).finishSequenceExpression(initSeq);
  10438. }
  10439. expect(';');
  10440. }
  10441. }
  10442. }
  10443. if (typeof left === 'undefined') {
  10444. if (!match(';')) {
  10445. test = parseExpression();
  10446. }
  10447. expect(';');
  10448. if (!match(')')) {
  10449. update = parseExpression();
  10450. }
  10451. }
  10452. expect(')');
  10453. oldInIteration = state.inIteration;
  10454. state.inIteration = true;
  10455. body = isolateCoverGrammar(parseStatement);
  10456. state.inIteration = oldInIteration;
  10457. return (typeof left === 'undefined') ?
  10458. node.finishForStatement(init, test, update, body) :
  10459. forIn ? node.finishForInStatement(left, right, body) :
  10460. node.finishForOfStatement(left, right, body);
  10461. }
  10462. // ECMA-262 13.8 The continue statement
  10463. function parseContinueStatement(node) {
  10464. var label = null, key;
  10465. expectKeyword('continue');
  10466. // Optimize the most common form: 'continue;'.
  10467. if (source.charCodeAt(startIndex) === 0x3B) {
  10468. lex();
  10469. if (!state.inIteration) {
  10470. throwError(Messages.IllegalContinue);
  10471. }
  10472. return node.finishContinueStatement(null);
  10473. }
  10474. if (hasLineTerminator) {
  10475. if (!state.inIteration) {
  10476. throwError(Messages.IllegalContinue);
  10477. }
  10478. return node.finishContinueStatement(null);
  10479. }
  10480. if (lookahead.type === Token.Identifier) {
  10481. label = parseVariableIdentifier();
  10482. key = '$' + label.name;
  10483. if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  10484. throwError(Messages.UnknownLabel, label.name);
  10485. }
  10486. }
  10487. consumeSemicolon();
  10488. if (label === null && !state.inIteration) {
  10489. throwError(Messages.IllegalContinue);
  10490. }
  10491. return node.finishContinueStatement(label);
  10492. }
  10493. // ECMA-262 13.9 The break statement
  10494. function parseBreakStatement(node) {
  10495. var label = null, key;
  10496. expectKeyword('break');
  10497. // Catch the very common case first: immediately a semicolon (U+003B).
  10498. if (source.charCodeAt(lastIndex) === 0x3B) {
  10499. lex();
  10500. if (!(state.inIteration || state.inSwitch)) {
  10501. throwError(Messages.IllegalBreak);
  10502. }
  10503. return node.finishBreakStatement(null);
  10504. }
  10505. if (hasLineTerminator) {
  10506. if (!(state.inIteration || state.inSwitch)) {
  10507. throwError(Messages.IllegalBreak);
  10508. }
  10509. } else if (lookahead.type === Token.Identifier) {
  10510. label = parseVariableIdentifier();
  10511. key = '$' + label.name;
  10512. if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  10513. throwError(Messages.UnknownLabel, label.name);
  10514. }
  10515. }
  10516. consumeSemicolon();
  10517. if (label === null && !(state.inIteration || state.inSwitch)) {
  10518. throwError(Messages.IllegalBreak);
  10519. }
  10520. return node.finishBreakStatement(label);
  10521. }
  10522. // ECMA-262 13.10 The return statement
  10523. function parseReturnStatement(node) {
  10524. var argument = null;
  10525. expectKeyword('return');
  10526. if (!state.inFunctionBody) {
  10527. tolerateError(Messages.IllegalReturn);
  10528. }
  10529. // 'return' followed by a space and an identifier is very common.
  10530. if (source.charCodeAt(lastIndex) === 0x20) {
  10531. if (isIdentifierStart(source.charCodeAt(lastIndex + 1))) {
  10532. argument = parseExpression();
  10533. consumeSemicolon();
  10534. return node.finishReturnStatement(argument);
  10535. }
  10536. }
  10537. if (hasLineTerminator) {
  10538. // HACK
  10539. return node.finishReturnStatement(null);
  10540. }
  10541. if (!match(';')) {
  10542. if (!match('}') && lookahead.type !== Token.EOF) {
  10543. argument = parseExpression();
  10544. }
  10545. }
  10546. consumeSemicolon();
  10547. return node.finishReturnStatement(argument);
  10548. }
  10549. // ECMA-262 13.11 The with statement
  10550. function parseWithStatement(node) {
  10551. var object, body;
  10552. if (strict) {
  10553. tolerateError(Messages.StrictModeWith);
  10554. }
  10555. expectKeyword('with');
  10556. expect('(');
  10557. object = parseExpression();
  10558. expect(')');
  10559. body = parseStatement();
  10560. return node.finishWithStatement(object, body);
  10561. }
  10562. // ECMA-262 13.12 The switch statement
  10563. function parseSwitchCase() {
  10564. var test, consequent = [], statement, node = new Node();
  10565. if (matchKeyword('default')) {
  10566. lex();
  10567. test = null;
  10568. } else {
  10569. expectKeyword('case');
  10570. test = parseExpression();
  10571. }
  10572. expect(':');
  10573. while (startIndex < length) {
  10574. if (match('}') || matchKeyword('default') || matchKeyword('case')) {
  10575. break;
  10576. }
  10577. statement = parseStatementListItem();
  10578. consequent.push(statement);
  10579. }
  10580. return node.finishSwitchCase(test, consequent);
  10581. }
  10582. function parseSwitchStatement(node) {
  10583. var discriminant, cases, clause, oldInSwitch, defaultFound;
  10584. expectKeyword('switch');
  10585. expect('(');
  10586. discriminant = parseExpression();
  10587. expect(')');
  10588. expect('{');
  10589. cases = [];
  10590. if (match('}')) {
  10591. lex();
  10592. return node.finishSwitchStatement(discriminant, cases);
  10593. }
  10594. oldInSwitch = state.inSwitch;
  10595. state.inSwitch = true;
  10596. defaultFound = false;
  10597. while (startIndex < length) {
  10598. if (match('}')) {
  10599. break;
  10600. }
  10601. clause = parseSwitchCase();
  10602. if (clause.test === null) {
  10603. if (defaultFound) {
  10604. throwError(Messages.MultipleDefaultsInSwitch);
  10605. }
  10606. defaultFound = true;
  10607. }
  10608. cases.push(clause);
  10609. }
  10610. state.inSwitch = oldInSwitch;
  10611. expect('}');
  10612. return node.finishSwitchStatement(discriminant, cases);
  10613. }
  10614. // ECMA-262 13.14 The throw statement
  10615. function parseThrowStatement(node) {
  10616. var argument;
  10617. expectKeyword('throw');
  10618. if (hasLineTerminator) {
  10619. throwError(Messages.NewlineAfterThrow);
  10620. }
  10621. argument = parseExpression();
  10622. consumeSemicolon();
  10623. return node.finishThrowStatement(argument);
  10624. }
  10625. // ECMA-262 13.15 The try statement
  10626. function parseCatchClause() {
  10627. var param, params = [], paramMap = {}, key, i, body, node = new Node();
  10628. expectKeyword('catch');
  10629. expect('(');
  10630. if (match(')')) {
  10631. throwUnexpectedToken(lookahead);
  10632. }
  10633. param = parsePattern(params);
  10634. for (i = 0; i < params.length; i++) {
  10635. key = '$' + params[i].value;
  10636. if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
  10637. tolerateError(Messages.DuplicateBinding, params[i].value);
  10638. }
  10639. paramMap[key] = true;
  10640. }
  10641. // ECMA-262 12.14.1
  10642. if (strict && isRestrictedWord(param.name)) {
  10643. tolerateError(Messages.StrictCatchVariable);
  10644. }
  10645. expect(')');
  10646. body = parseBlock();
  10647. return node.finishCatchClause(param, body);
  10648. }
  10649. function parseTryStatement(node) {
  10650. var block, handler = null, finalizer = null;
  10651. expectKeyword('try');
  10652. block = parseBlock();
  10653. if (matchKeyword('catch')) {
  10654. handler = parseCatchClause();
  10655. }
  10656. if (matchKeyword('finally')) {
  10657. lex();
  10658. finalizer = parseBlock();
  10659. }
  10660. if (!handler && !finalizer) {
  10661. throwError(Messages.NoCatchOrFinally);
  10662. }
  10663. return node.finishTryStatement(block, handler, finalizer);
  10664. }
  10665. // ECMA-262 13.16 The debugger statement
  10666. function parseDebuggerStatement(node) {
  10667. expectKeyword('debugger');
  10668. consumeSemicolon();
  10669. return node.finishDebuggerStatement();
  10670. }
  10671. // 13 Statements
  10672. function parseStatement() {
  10673. var type = lookahead.type,
  10674. expr,
  10675. labeledBody,
  10676. key,
  10677. node;
  10678. if (type === Token.EOF) {
  10679. throwUnexpectedToken(lookahead);
  10680. }
  10681. if (type === Token.Punctuator && lookahead.value === '{') {
  10682. return parseBlock();
  10683. }
  10684. isAssignmentTarget = isBindingElement = true;
  10685. node = new Node();
  10686. if (type === Token.Punctuator) {
  10687. switch (lookahead.value) {
  10688. case ';':
  10689. return parseEmptyStatement(node);
  10690. case '(':
  10691. return parseExpressionStatement(node);
  10692. default:
  10693. break;
  10694. }
  10695. } else if (type === Token.Keyword) {
  10696. switch (lookahead.value) {
  10697. case 'break':
  10698. return parseBreakStatement(node);
  10699. case 'continue':
  10700. return parseContinueStatement(node);
  10701. case 'debugger':
  10702. return parseDebuggerStatement(node);
  10703. case 'do':
  10704. return parseDoWhileStatement(node);
  10705. case 'for':
  10706. return parseForStatement(node);
  10707. case 'function':
  10708. return parseFunctionDeclaration(node);
  10709. case 'if':
  10710. return parseIfStatement(node);
  10711. case 'return':
  10712. return parseReturnStatement(node);
  10713. case 'switch':
  10714. return parseSwitchStatement(node);
  10715. case 'throw':
  10716. return parseThrowStatement(node);
  10717. case 'try':
  10718. return parseTryStatement(node);
  10719. case 'var':
  10720. return parseVariableStatement(node);
  10721. case 'while':
  10722. return parseWhileStatement(node);
  10723. case 'with':
  10724. return parseWithStatement(node);
  10725. default:
  10726. break;
  10727. }
  10728. }
  10729. expr = parseExpression();
  10730. // ECMA-262 12.12 Labelled Statements
  10731. if ((expr.type === Syntax.Identifier) && match(':')) {
  10732. lex();
  10733. key = '$' + expr.name;
  10734. if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  10735. throwError(Messages.Redeclaration, 'Label', expr.name);
  10736. }
  10737. state.labelSet[key] = true;
  10738. labeledBody = parseStatement();
  10739. delete state.labelSet[key];
  10740. return node.finishLabeledStatement(expr, labeledBody);
  10741. }
  10742. consumeSemicolon();
  10743. return node.finishExpressionStatement(expr);
  10744. }
  10745. // ECMA-262 14.1 Function Definition
  10746. function parseFunctionSourceElements() {
  10747. var statement, body = [], token, directive, firstRestricted,
  10748. oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody,
  10749. node = new Node();
  10750. expect('{');
  10751. while (startIndex < length) {
  10752. if (lookahead.type !== Token.StringLiteral) {
  10753. break;
  10754. }
  10755. token = lookahead;
  10756. statement = parseStatementListItem();
  10757. body.push(statement);
  10758. if (statement.expression.type !== Syntax.Literal) {
  10759. // this is not directive
  10760. break;
  10761. }
  10762. directive = source.slice(token.start + 1, token.end - 1);
  10763. if (directive === 'use strict') {
  10764. strict = true;
  10765. if (firstRestricted) {
  10766. tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);
  10767. }
  10768. } else {
  10769. if (!firstRestricted && token.octal) {
  10770. firstRestricted = token;
  10771. }
  10772. }
  10773. }
  10774. oldLabelSet = state.labelSet;
  10775. oldInIteration = state.inIteration;
  10776. oldInSwitch = state.inSwitch;
  10777. oldInFunctionBody = state.inFunctionBody;
  10778. state.labelSet = {};
  10779. state.inIteration = false;
  10780. state.inSwitch = false;
  10781. state.inFunctionBody = true;
  10782. while (startIndex < length) {
  10783. if (match('}')) {
  10784. break;
  10785. }
  10786. body.push(parseStatementListItem());
  10787. }
  10788. expect('}');
  10789. state.labelSet = oldLabelSet;
  10790. state.inIteration = oldInIteration;
  10791. state.inSwitch = oldInSwitch;
  10792. state.inFunctionBody = oldInFunctionBody;
  10793. return node.finishBlockStatement(body);
  10794. }
  10795. function validateParam(options, param, name) {
  10796. var key = '$' + name;
  10797. if (strict) {
  10798. if (isRestrictedWord(name)) {
  10799. options.stricted = param;
  10800. options.message = Messages.StrictParamName;
  10801. }
  10802. if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  10803. options.stricted = param;
  10804. options.message = Messages.StrictParamDupe;
  10805. }
  10806. } else if (!options.firstRestricted) {
  10807. if (isRestrictedWord(name)) {
  10808. options.firstRestricted = param;
  10809. options.message = Messages.StrictParamName;
  10810. } else if (isStrictModeReservedWord(name)) {
  10811. options.firstRestricted = param;
  10812. options.message = Messages.StrictReservedWord;
  10813. } else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  10814. options.stricted = param;
  10815. options.message = Messages.StrictParamDupe;
  10816. }
  10817. }
  10818. options.paramSet[key] = true;
  10819. }
  10820. function parseParam(options) {
  10821. var token, param, params = [], i, def;
  10822. token = lookahead;
  10823. if (token.value === '...') {
  10824. param = parseRestElement(params);
  10825. validateParam(options, param.argument, param.argument.name);
  10826. options.params.push(param);
  10827. options.defaults.push(null);
  10828. return false;
  10829. }
  10830. param = parsePatternWithDefault(params);
  10831. for (i = 0; i < params.length; i++) {
  10832. validateParam(options, params[i], params[i].value);
  10833. }
  10834. if (param.type === Syntax.AssignmentPattern) {
  10835. def = param.right;
  10836. param = param.left;
  10837. ++options.defaultCount;
  10838. }
  10839. options.params.push(param);
  10840. options.defaults.push(def);
  10841. return !match(')');
  10842. }
  10843. function parseParams(firstRestricted) {
  10844. var options;
  10845. options = {
  10846. params: [],
  10847. defaultCount: 0,
  10848. defaults: [],
  10849. firstRestricted: firstRestricted
  10850. };
  10851. expect('(');
  10852. if (!match(')')) {
  10853. options.paramSet = {};
  10854. while (startIndex < length) {
  10855. if (!parseParam(options)) {
  10856. break;
  10857. }
  10858. expect(',');
  10859. }
  10860. }
  10861. expect(')');
  10862. if (options.defaultCount === 0) {
  10863. options.defaults = [];
  10864. }
  10865. return {
  10866. params: options.params,
  10867. defaults: options.defaults,
  10868. stricted: options.stricted,
  10869. firstRestricted: options.firstRestricted,
  10870. message: options.message
  10871. };
  10872. }
  10873. function parseFunctionDeclaration(node, identifierIsOptional) {
  10874. var id = null, params = [], defaults = [], body, token, stricted, tmp, firstRestricted, message, previousStrict,
  10875. isGenerator, previousAllowYield;
  10876. previousAllowYield = state.allowYield;
  10877. expectKeyword('function');
  10878. isGenerator = match('*');
  10879. if (isGenerator) {
  10880. lex();
  10881. }
  10882. if (!identifierIsOptional || !match('(')) {
  10883. token = lookahead;
  10884. id = parseVariableIdentifier();
  10885. if (strict) {
  10886. if (isRestrictedWord(token.value)) {
  10887. tolerateUnexpectedToken(token, Messages.StrictFunctionName);
  10888. }
  10889. } else {
  10890. if (isRestrictedWord(token.value)) {
  10891. firstRestricted = token;
  10892. message = Messages.StrictFunctionName;
  10893. } else if (isStrictModeReservedWord(token.value)) {
  10894. firstRestricted = token;
  10895. message = Messages.StrictReservedWord;
  10896. }
  10897. }
  10898. }
  10899. state.allowYield = !isGenerator;
  10900. tmp = parseParams(firstRestricted);
  10901. params = tmp.params;
  10902. defaults = tmp.defaults;
  10903. stricted = tmp.stricted;
  10904. firstRestricted = tmp.firstRestricted;
  10905. if (tmp.message) {
  10906. message = tmp.message;
  10907. }
  10908. previousStrict = strict;
  10909. body = parseFunctionSourceElements();
  10910. if (strict && firstRestricted) {
  10911. throwUnexpectedToken(firstRestricted, message);
  10912. }
  10913. if (strict && stricted) {
  10914. tolerateUnexpectedToken(stricted, message);
  10915. }
  10916. strict = previousStrict;
  10917. state.allowYield = previousAllowYield;
  10918. return node.finishFunctionDeclaration(id, params, defaults, body, isGenerator);
  10919. }
  10920. function parseFunctionExpression() {
  10921. var token, id = null, stricted, firstRestricted, message, tmp,
  10922. params = [], defaults = [], body, previousStrict, node = new Node(),
  10923. isGenerator, previousAllowYield;
  10924. previousAllowYield = state.allowYield;
  10925. expectKeyword('function');
  10926. isGenerator = match('*');
  10927. if (isGenerator) {
  10928. lex();
  10929. }
  10930. state.allowYield = !isGenerator;
  10931. if (!match('(')) {
  10932. token = lookahead;
  10933. id = (!strict && !isGenerator && matchKeyword('yield')) ? parseNonComputedProperty() : parseVariableIdentifier();
  10934. if (strict) {
  10935. if (isRestrictedWord(token.value)) {
  10936. tolerateUnexpectedToken(token, Messages.StrictFunctionName);
  10937. }
  10938. } else {
  10939. if (isRestrictedWord(token.value)) {
  10940. firstRestricted = token;
  10941. message = Messages.StrictFunctionName;
  10942. } else if (isStrictModeReservedWord(token.value)) {
  10943. firstRestricted = token;
  10944. message = Messages.StrictReservedWord;
  10945. }
  10946. }
  10947. }
  10948. tmp = parseParams(firstRestricted);
  10949. params = tmp.params;
  10950. defaults = tmp.defaults;
  10951. stricted = tmp.stricted;
  10952. firstRestricted = tmp.firstRestricted;
  10953. if (tmp.message) {
  10954. message = tmp.message;
  10955. }
  10956. previousStrict = strict;
  10957. body = parseFunctionSourceElements();
  10958. if (strict && firstRestricted) {
  10959. throwUnexpectedToken(firstRestricted, message);
  10960. }
  10961. if (strict && stricted) {
  10962. tolerateUnexpectedToken(stricted, message);
  10963. }
  10964. strict = previousStrict;
  10965. state.allowYield = previousAllowYield;
  10966. return node.finishFunctionExpression(id, params, defaults, body, isGenerator);
  10967. }
  10968. // ECMA-262 14.5 Class Definitions
  10969. function parseClassBody() {
  10970. var classBody, token, isStatic, hasConstructor = false, body, method, computed, key;
  10971. classBody = new Node();
  10972. expect('{');
  10973. body = [];
  10974. while (!match('}')) {
  10975. if (match(';')) {
  10976. lex();
  10977. } else {
  10978. method = new Node();
  10979. token = lookahead;
  10980. isStatic = false;
  10981. computed = match('[');
  10982. if (match('*')) {
  10983. lex();
  10984. } else {
  10985. key = parseObjectPropertyKey();
  10986. if (key.name === 'static' && (lookaheadPropertyName() || match('*'))) {
  10987. token = lookahead;
  10988. isStatic = true;
  10989. computed = match('[');
  10990. if (match('*')) {
  10991. lex();
  10992. } else {
  10993. key = parseObjectPropertyKey();
  10994. }
  10995. }
  10996. }
  10997. method = tryParseMethodDefinition(token, key, computed, method);
  10998. if (method) {
  10999. method['static'] = isStatic; // jscs:ignore requireDotNotation
  11000. if (method.kind === 'init') {
  11001. method.kind = 'method';
  11002. }
  11003. if (!isStatic) {
  11004. if (!method.computed && (method.key.name || method.key.value.toString()) === 'constructor') {
  11005. if (method.kind !== 'method' || !method.method || method.value.generator) {
  11006. throwUnexpectedToken(token, Messages.ConstructorSpecialMethod);
  11007. }
  11008. if (hasConstructor) {
  11009. throwUnexpectedToken(token, Messages.DuplicateConstructor);
  11010. } else {
  11011. hasConstructor = true;
  11012. }
  11013. method.kind = 'constructor';
  11014. }
  11015. } else {
  11016. if (!method.computed && (method.key.name || method.key.value.toString()) === 'prototype') {
  11017. throwUnexpectedToken(token, Messages.StaticPrototype);
  11018. }
  11019. }
  11020. method.type = Syntax.MethodDefinition;
  11021. delete method.method;
  11022. delete method.shorthand;
  11023. body.push(method);
  11024. } else {
  11025. throwUnexpectedToken(lookahead);
  11026. }
  11027. }
  11028. }
  11029. lex();
  11030. return classBody.finishClassBody(body);
  11031. }
  11032. function parseClassDeclaration(identifierIsOptional) {
  11033. var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;
  11034. strict = true;
  11035. expectKeyword('class');
  11036. if (!identifierIsOptional || lookahead.type === Token.Identifier) {
  11037. id = parseVariableIdentifier();
  11038. }
  11039. if (matchKeyword('extends')) {
  11040. lex();
  11041. superClass = isolateCoverGrammar(parseLeftHandSideExpressionAllowCall);
  11042. }
  11043. classBody = parseClassBody();
  11044. strict = previousStrict;
  11045. return classNode.finishClassDeclaration(id, superClass, classBody);
  11046. }
  11047. function parseClassExpression() {
  11048. var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;
  11049. strict = true;
  11050. expectKeyword('class');
  11051. if (lookahead.type === Token.Identifier) {
  11052. id = parseVariableIdentifier();
  11053. }
  11054. if (matchKeyword('extends')) {
  11055. lex();
  11056. superClass = isolateCoverGrammar(parseLeftHandSideExpressionAllowCall);
  11057. }
  11058. classBody = parseClassBody();
  11059. strict = previousStrict;
  11060. return classNode.finishClassExpression(id, superClass, classBody);
  11061. }
  11062. // ECMA-262 15.2 Modules
  11063. function parseModuleSpecifier() {
  11064. var node = new Node();
  11065. if (lookahead.type !== Token.StringLiteral) {
  11066. throwError(Messages.InvalidModuleSpecifier);
  11067. }
  11068. return node.finishLiteral(lex());
  11069. }
  11070. // ECMA-262 15.2.3 Exports
  11071. function parseExportSpecifier() {
  11072. var exported, local, node = new Node(), def;
  11073. if (matchKeyword('default')) {
  11074. // export {default} from 'something';
  11075. def = new Node();
  11076. lex();
  11077. local = def.finishIdentifier('default');
  11078. } else {
  11079. local = parseVariableIdentifier();
  11080. }
  11081. if (matchContextualKeyword('as')) {
  11082. lex();
  11083. exported = parseNonComputedProperty();
  11084. }
  11085. return node.finishExportSpecifier(local, exported);
  11086. }
  11087. function parseExportNamedDeclaration(node) {
  11088. var declaration = null,
  11089. isExportFromIdentifier,
  11090. src = null, specifiers = [];
  11091. // non-default export
  11092. if (lookahead.type === Token.Keyword) {
  11093. // covers:
  11094. // export var f = 1;
  11095. switch (lookahead.value) {
  11096. case 'let':
  11097. case 'const':
  11098. declaration = parseLexicalDeclaration({inFor: false});
  11099. return node.finishExportNamedDeclaration(declaration, specifiers, null);
  11100. case 'var':
  11101. case 'class':
  11102. case 'function':
  11103. declaration = parseStatementListItem();
  11104. return node.finishExportNamedDeclaration(declaration, specifiers, null);
  11105. }
  11106. }
  11107. expect('{');
  11108. while (!match('}')) {
  11109. isExportFromIdentifier = isExportFromIdentifier || matchKeyword('default');
  11110. specifiers.push(parseExportSpecifier());
  11111. if (!match('}')) {
  11112. expect(',');
  11113. if (match('}')) {
  11114. break;
  11115. }
  11116. }
  11117. }
  11118. expect('}');
  11119. if (matchContextualKeyword('from')) {
  11120. // covering:
  11121. // export {default} from 'foo';
  11122. // export {foo} from 'foo';
  11123. lex();
  11124. src = parseModuleSpecifier();
  11125. consumeSemicolon();
  11126. } else if (isExportFromIdentifier) {
  11127. // covering:
  11128. // export {default}; // missing fromClause
  11129. throwError(lookahead.value ?
  11130. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  11131. } else {
  11132. // cover
  11133. // export {foo};
  11134. consumeSemicolon();
  11135. }
  11136. return node.finishExportNamedDeclaration(declaration, specifiers, src);
  11137. }
  11138. function parseExportDefaultDeclaration(node) {
  11139. var declaration = null,
  11140. expression = null;
  11141. // covers:
  11142. // export default ...
  11143. expectKeyword('default');
  11144. if (matchKeyword('function')) {
  11145. // covers:
  11146. // export default function foo () {}
  11147. // export default function () {}
  11148. declaration = parseFunctionDeclaration(new Node(), true);
  11149. return node.finishExportDefaultDeclaration(declaration);
  11150. }
  11151. if (matchKeyword('class')) {
  11152. declaration = parseClassDeclaration(true);
  11153. return node.finishExportDefaultDeclaration(declaration);
  11154. }
  11155. if (matchContextualKeyword('from')) {
  11156. throwError(Messages.UnexpectedToken, lookahead.value);
  11157. }
  11158. // covers:
  11159. // export default {};
  11160. // export default [];
  11161. // export default (1 + 2);
  11162. if (match('{')) {
  11163. expression = parseObjectInitializer();
  11164. } else if (match('[')) {
  11165. expression = parseArrayInitializer();
  11166. } else {
  11167. expression = parseAssignmentExpression();
  11168. }
  11169. consumeSemicolon();
  11170. return node.finishExportDefaultDeclaration(expression);
  11171. }
  11172. function parseExportAllDeclaration(node) {
  11173. var src;
  11174. // covers:
  11175. // export * from 'foo';
  11176. expect('*');
  11177. if (!matchContextualKeyword('from')) {
  11178. throwError(lookahead.value ?
  11179. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  11180. }
  11181. lex();
  11182. src = parseModuleSpecifier();
  11183. consumeSemicolon();
  11184. return node.finishExportAllDeclaration(src);
  11185. }
  11186. function parseExportDeclaration() {
  11187. var node = new Node();
  11188. if (state.inFunctionBody) {
  11189. throwError(Messages.IllegalExportDeclaration);
  11190. }
  11191. expectKeyword('export');
  11192. if (matchKeyword('default')) {
  11193. return parseExportDefaultDeclaration(node);
  11194. }
  11195. if (match('*')) {
  11196. return parseExportAllDeclaration(node);
  11197. }
  11198. return parseExportNamedDeclaration(node);
  11199. }
  11200. // ECMA-262 15.2.2 Imports
  11201. function parseImportSpecifier() {
  11202. // import {<foo as bar>} ...;
  11203. var local, imported, node = new Node();
  11204. imported = parseNonComputedProperty();
  11205. if (matchContextualKeyword('as')) {
  11206. lex();
  11207. local = parseVariableIdentifier();
  11208. }
  11209. return node.finishImportSpecifier(local, imported);
  11210. }
  11211. function parseNamedImports() {
  11212. var specifiers = [];
  11213. // {foo, bar as bas}
  11214. expect('{');
  11215. while (!match('}')) {
  11216. specifiers.push(parseImportSpecifier());
  11217. if (!match('}')) {
  11218. expect(',');
  11219. if (match('}')) {
  11220. break;
  11221. }
  11222. }
  11223. }
  11224. expect('}');
  11225. return specifiers;
  11226. }
  11227. function parseImportDefaultSpecifier() {
  11228. // import <foo> ...;
  11229. var local, node = new Node();
  11230. local = parseNonComputedProperty();
  11231. return node.finishImportDefaultSpecifier(local);
  11232. }
  11233. function parseImportNamespaceSpecifier() {
  11234. // import <* as foo> ...;
  11235. var local, node = new Node();
  11236. expect('*');
  11237. if (!matchContextualKeyword('as')) {
  11238. throwError(Messages.NoAsAfterImportNamespace);
  11239. }
  11240. lex();
  11241. local = parseNonComputedProperty();
  11242. return node.finishImportNamespaceSpecifier(local);
  11243. }
  11244. function parseImportDeclaration() {
  11245. var specifiers = [], src, node = new Node();
  11246. if (state.inFunctionBody) {
  11247. throwError(Messages.IllegalImportDeclaration);
  11248. }
  11249. expectKeyword('import');
  11250. if (lookahead.type === Token.StringLiteral) {
  11251. // import 'foo';
  11252. src = parseModuleSpecifier();
  11253. } else {
  11254. if (match('{')) {
  11255. // import {bar}
  11256. specifiers = specifiers.concat(parseNamedImports());
  11257. } else if (match('*')) {
  11258. // import * as foo
  11259. specifiers.push(parseImportNamespaceSpecifier());
  11260. } else if (isIdentifierName(lookahead) && !matchKeyword('default')) {
  11261. // import foo
  11262. specifiers.push(parseImportDefaultSpecifier());
  11263. if (match(',')) {
  11264. lex();
  11265. if (match('*')) {
  11266. // import foo, * as foo
  11267. specifiers.push(parseImportNamespaceSpecifier());
  11268. } else if (match('{')) {
  11269. // import foo, {bar}
  11270. specifiers = specifiers.concat(parseNamedImports());
  11271. } else {
  11272. throwUnexpectedToken(lookahead);
  11273. }
  11274. }
  11275. } else {
  11276. throwUnexpectedToken(lex());
  11277. }
  11278. if (!matchContextualKeyword('from')) {
  11279. throwError(lookahead.value ?
  11280. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  11281. }
  11282. lex();
  11283. src = parseModuleSpecifier();
  11284. }
  11285. consumeSemicolon();
  11286. return node.finishImportDeclaration(specifiers, src);
  11287. }
  11288. // ECMA-262 15.1 Scripts
  11289. function parseScriptBody() {
  11290. var statement, body = [], token, directive, firstRestricted;
  11291. while (startIndex < length) {
  11292. token = lookahead;
  11293. if (token.type !== Token.StringLiteral) {
  11294. break;
  11295. }
  11296. statement = parseStatementListItem();
  11297. body.push(statement);
  11298. if (statement.expression.type !== Syntax.Literal) {
  11299. // this is not directive
  11300. break;
  11301. }
  11302. directive = source.slice(token.start + 1, token.end - 1);
  11303. if (directive === 'use strict') {
  11304. strict = true;
  11305. if (firstRestricted) {
  11306. tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);
  11307. }
  11308. } else {
  11309. if (!firstRestricted && token.octal) {
  11310. firstRestricted = token;
  11311. }
  11312. }
  11313. }
  11314. while (startIndex < length) {
  11315. statement = parseStatementListItem();
  11316. /* istanbul ignore if */
  11317. if (typeof statement === 'undefined') {
  11318. break;
  11319. }
  11320. body.push(statement);
  11321. }
  11322. return body;
  11323. }
  11324. function parseProgram() {
  11325. var body, node;
  11326. peek();
  11327. node = new Node();
  11328. body = parseScriptBody();
  11329. return node.finishProgram(body, state.sourceType);
  11330. }
  11331. function filterTokenLocation() {
  11332. var i, entry, token, tokens = [];
  11333. for (i = 0; i < extra.tokens.length; ++i) {
  11334. entry = extra.tokens[i];
  11335. token = {
  11336. type: entry.type,
  11337. value: entry.value
  11338. };
  11339. if (entry.regex) {
  11340. token.regex = {
  11341. pattern: entry.regex.pattern,
  11342. flags: entry.regex.flags
  11343. };
  11344. }
  11345. if (extra.range) {
  11346. token.range = entry.range;
  11347. }
  11348. if (extra.loc) {
  11349. token.loc = entry.loc;
  11350. }
  11351. tokens.push(token);
  11352. }
  11353. extra.tokens = tokens;
  11354. }
  11355. function tokenize(code, options, delegate) {
  11356. var toString,
  11357. tokens;
  11358. toString = String;
  11359. if (typeof code !== 'string' && !(code instanceof String)) {
  11360. code = toString(code);
  11361. }
  11362. source = code;
  11363. index = 0;
  11364. lineNumber = (source.length > 0) ? 1 : 0;
  11365. lineStart = 0;
  11366. startIndex = index;
  11367. startLineNumber = lineNumber;
  11368. startLineStart = lineStart;
  11369. length = source.length;
  11370. lookahead = null;
  11371. state = {
  11372. allowIn: true,
  11373. allowYield: true,
  11374. labelSet: {},
  11375. inFunctionBody: false,
  11376. inIteration: false,
  11377. inSwitch: false,
  11378. lastCommentStart: -1,
  11379. curlyStack: []
  11380. };
  11381. extra = {};
  11382. // Options matching.
  11383. options = options || {};
  11384. // Of course we collect tokens here.
  11385. options.tokens = true;
  11386. extra.tokens = [];
  11387. extra.tokenValues = [];
  11388. extra.tokenize = true;
  11389. extra.delegate = delegate;
  11390. // The following two fields are necessary to compute the Regex tokens.
  11391. extra.openParenToken = -1;
  11392. extra.openCurlyToken = -1;
  11393. extra.range = (typeof options.range === 'boolean') && options.range;
  11394. extra.loc = (typeof options.loc === 'boolean') && options.loc;
  11395. if (typeof options.comment === 'boolean' && options.comment) {
  11396. extra.comments = [];
  11397. }
  11398. if (typeof options.tolerant === 'boolean' && options.tolerant) {
  11399. extra.errors = [];
  11400. }
  11401. try {
  11402. peek();
  11403. if (lookahead.type === Token.EOF) {
  11404. return extra.tokens;
  11405. }
  11406. lex();
  11407. while (lookahead.type !== Token.EOF) {
  11408. try {
  11409. lex();
  11410. } catch (lexError) {
  11411. if (extra.errors) {
  11412. recordError(lexError);
  11413. // We have to break on the first error
  11414. // to avoid infinite loops.
  11415. break;
  11416. } else {
  11417. throw lexError;
  11418. }
  11419. }
  11420. }
  11421. tokens = extra.tokens;
  11422. if (typeof extra.errors !== 'undefined') {
  11423. tokens.errors = extra.errors;
  11424. }
  11425. } catch (e) {
  11426. throw e;
  11427. } finally {
  11428. extra = {};
  11429. }
  11430. return tokens;
  11431. }
  11432. function parse(code, options) {
  11433. var program, toString;
  11434. toString = String;
  11435. if (typeof code !== 'string' && !(code instanceof String)) {
  11436. code = toString(code);
  11437. }
  11438. source = code;
  11439. index = 0;
  11440. lineNumber = (source.length > 0) ? 1 : 0;
  11441. lineStart = 0;
  11442. startIndex = index;
  11443. startLineNumber = lineNumber;
  11444. startLineStart = lineStart;
  11445. length = source.length;
  11446. lookahead = null;
  11447. state = {
  11448. allowIn: true,
  11449. allowYield: true,
  11450. labelSet: {},
  11451. inFunctionBody: false,
  11452. inIteration: false,
  11453. inSwitch: false,
  11454. lastCommentStart: -1,
  11455. curlyStack: [],
  11456. sourceType: 'script'
  11457. };
  11458. strict = false;
  11459. extra = {};
  11460. if (typeof options !== 'undefined') {
  11461. extra.range = (typeof options.range === 'boolean') && options.range;
  11462. extra.loc = (typeof options.loc === 'boolean') && options.loc;
  11463. extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;
  11464. if (extra.loc && options.source !== null && options.source !== undefined) {
  11465. extra.source = toString(options.source);
  11466. }
  11467. if (typeof options.tokens === 'boolean' && options.tokens) {
  11468. extra.tokens = [];
  11469. }
  11470. if (typeof options.comment === 'boolean' && options.comment) {
  11471. extra.comments = [];
  11472. }
  11473. if (typeof options.tolerant === 'boolean' && options.tolerant) {
  11474. extra.errors = [];
  11475. }
  11476. if (extra.attachComment) {
  11477. extra.range = true;
  11478. extra.comments = [];
  11479. extra.bottomRightStack = [];
  11480. extra.trailingComments = [];
  11481. extra.leadingComments = [];
  11482. }
  11483. if (options.sourceType === 'module') {
  11484. // very restrictive condition for now
  11485. state.sourceType = options.sourceType;
  11486. strict = true;
  11487. }
  11488. }
  11489. try {
  11490. program = parseProgram();
  11491. if (typeof extra.comments !== 'undefined') {
  11492. program.comments = extra.comments;
  11493. }
  11494. if (typeof extra.tokens !== 'undefined') {
  11495. filterTokenLocation();
  11496. program.tokens = extra.tokens;
  11497. }
  11498. if (typeof extra.errors !== 'undefined') {
  11499. program.errors = extra.errors;
  11500. }
  11501. } catch (e) {
  11502. throw e;
  11503. } finally {
  11504. extra = {};
  11505. }
  11506. return program;
  11507. }
  11508. // Sync with *.json manifests.
  11509. exports.version = '2.7.2';
  11510. exports.tokenize = tokenize;
  11511. exports.parse = parse;
  11512. // Deep copy.
  11513. /* istanbul ignore next */
  11514. exports.Syntax = (function () {
  11515. var name, types = {};
  11516. if (typeof Object.create === 'function') {
  11517. types = Object.create(null);
  11518. }
  11519. for (name in Syntax) {
  11520. if (Syntax.hasOwnProperty(name)) {
  11521. types[name] = Syntax[name];
  11522. }
  11523. }
  11524. if (typeof Object.freeze === 'function') {
  11525. Object.freeze(types);
  11526. }
  11527. return types;
  11528. }());
  11529. }));
  11530. /* vim: set sw=4 ts=4 et tw=80 : */
  11531. /***/ }
  11532. /******/ ]);