worker-javascript.js 278 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419
  1. "no use strict";
  2. ;(function(window) {
  3. if (typeof window.window != "undefined" && window.document) {
  4. return;
  5. }
  6. window.console = function() {
  7. var msgs = Array.prototype.slice.call(arguments, 0);
  8. postMessage({type: "log", data: msgs});
  9. };
  10. window.console.error =
  11. window.console.warn =
  12. window.console.log =
  13. window.console.trace = window.console;
  14. window.window = window;
  15. window.ace = window;
  16. window.onerror = function(message, file, line, col, err) {
  17. console.error("Worker " + (err ? err.stack : message));
  18. };
  19. window.normalizeModule = function(parentId, moduleName) {
  20. // normalize plugin requires
  21. if (moduleName.indexOf("!") !== -1) {
  22. var chunks = moduleName.split("!");
  23. return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
  24. }
  25. // normalize relative requires
  26. if (moduleName.charAt(0) == ".") {
  27. var base = parentId.split("/").slice(0, -1).join("/");
  28. moduleName = (base ? base + "/" : "") + moduleName;
  29. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  30. var previous = moduleName;
  31. moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  32. }
  33. }
  34. return moduleName;
  35. };
  36. window.require = function(parentId, id) {
  37. if (!id) {
  38. id = parentId;
  39. parentId = null;
  40. }
  41. if (!id.charAt)
  42. throw new Error("worker.js require() accepts only (parentId, id) as arguments");
  43. id = window.normalizeModule(parentId, id);
  44. var module = window.require.modules[id];
  45. if (module) {
  46. if (!module.initialized) {
  47. module.initialized = true;
  48. module.exports = module.factory().exports;
  49. }
  50. return module.exports;
  51. }
  52. var chunks = id.split("/");
  53. if (!window.require.tlns)
  54. return console.log("unable to load " + id);
  55. chunks[0] = window.require.tlns[chunks[0]] || chunks[0];
  56. var path = chunks.join("/") + ".js";
  57. window.require.id = id;
  58. importScripts(path);
  59. return window.require(parentId, id);
  60. };
  61. window.require.modules = {};
  62. window.require.tlns = {};
  63. window.define = function(id, deps, factory) {
  64. if (arguments.length == 2) {
  65. factory = deps;
  66. if (typeof id != "string") {
  67. deps = id;
  68. id = window.require.id;
  69. }
  70. } else if (arguments.length == 1) {
  71. factory = id;
  72. deps = [];
  73. id = window.require.id;
  74. }
  75. if (!deps.length)
  76. // If there is no dependencies, we inject 'require', 'exports' and
  77. // 'module' as dependencies, to provide CommonJS compatibility.
  78. deps = ['require', 'exports', 'module'];
  79. if (id.indexOf("text!") === 0)
  80. return;
  81. var req = function(childId) {
  82. return window.require(id, childId);
  83. };
  84. window.require.modules[id] = {
  85. exports: {},
  86. factory: function() {
  87. var module = this;
  88. var returnExports = factory.apply(this, deps.map(function(dep) {
  89. switch(dep) {
  90. // Because 'require', 'exports' and 'module' aren't actual
  91. // dependencies, we must handle them seperately.
  92. case 'require': return req;
  93. case 'exports': return module.exports;
  94. case 'module': return module;
  95. // But for all other dependencies, we can just go ahead and
  96. // require them.
  97. default: return req(dep);
  98. }
  99. }));
  100. if (returnExports)
  101. module.exports = returnExports;
  102. return module;
  103. }
  104. };
  105. };
  106. window.define.amd = {};
  107. window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
  108. require.tlns = topLevelNamespaces;
  109. };
  110. window.initSender = function initSender() {
  111. var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
  112. var oop = window.require("ace/lib/oop");
  113. var Sender = function() {};
  114. (function() {
  115. oop.implement(this, EventEmitter);
  116. this.callback = function(data, callbackId) {
  117. postMessage({
  118. type: "call",
  119. id: callbackId,
  120. data: data
  121. });
  122. };
  123. this.emit = function(name, data) {
  124. postMessage({
  125. type: "event",
  126. name: name,
  127. data: data
  128. });
  129. };
  130. }).call(Sender.prototype);
  131. return new Sender();
  132. };
  133. var main = window.main = null;
  134. var sender = window.sender = null;
  135. window.onmessage = function(e) {
  136. var msg = e.data;
  137. if (msg.command) {
  138. if (main[msg.command])
  139. main[msg.command].apply(main, msg.args);
  140. else
  141. throw new Error("Unknown command:" + msg.command);
  142. }
  143. else if (msg.init) {
  144. initBaseUrls(msg.tlns);
  145. require("ace/lib/es5-shim");
  146. sender = window.sender = initSender();
  147. var clazz = require(msg.module)[msg.classname];
  148. main = window.main = new clazz(sender);
  149. }
  150. else if (msg.event && sender) {
  151. sender._signal(msg.event, msg.data);
  152. }
  153. };
  154. })(this);
  155. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  156. "use strict";
  157. exports.inherits = function(ctor, superCtor) {
  158. ctor.super_ = superCtor;
  159. ctor.prototype = Object.create(superCtor.prototype, {
  160. constructor: {
  161. value: ctor,
  162. enumerable: false,
  163. writable: true,
  164. configurable: true
  165. }
  166. });
  167. };
  168. exports.mixin = function(obj, mixin) {
  169. for (var key in mixin) {
  170. obj[key] = mixin[key];
  171. }
  172. return obj;
  173. };
  174. exports.implement = function(proto, mixin) {
  175. exports.mixin(proto, mixin);
  176. };
  177. });
  178. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  179. "use strict";
  180. var EventEmitter = {};
  181. var stopPropagation = function() { this.propagationStopped = true; };
  182. var preventDefault = function() { this.defaultPrevented = true; };
  183. EventEmitter._emit =
  184. EventEmitter._dispatchEvent = function(eventName, e) {
  185. this._eventRegistry || (this._eventRegistry = {});
  186. this._defaultHandlers || (this._defaultHandlers = {});
  187. var listeners = this._eventRegistry[eventName] || [];
  188. var defaultHandler = this._defaultHandlers[eventName];
  189. if (!listeners.length && !defaultHandler)
  190. return;
  191. if (typeof e != "object" || !e)
  192. e = {};
  193. if (!e.type)
  194. e.type = eventName;
  195. if (!e.stopPropagation)
  196. e.stopPropagation = stopPropagation;
  197. if (!e.preventDefault)
  198. e.preventDefault = preventDefault;
  199. listeners = listeners.slice();
  200. for (var i=0; i<listeners.length; i++) {
  201. listeners[i](e, this);
  202. if (e.propagationStopped)
  203. break;
  204. }
  205. if (defaultHandler && !e.defaultPrevented)
  206. return defaultHandler(e, this);
  207. };
  208. EventEmitter._signal = function(eventName, e) {
  209. var listeners = (this._eventRegistry || {})[eventName];
  210. if (!listeners)
  211. return;
  212. listeners = listeners.slice();
  213. for (var i=0; i<listeners.length; i++)
  214. listeners[i](e, this);
  215. };
  216. EventEmitter.once = function(eventName, callback) {
  217. var _self = this;
  218. callback && this.addEventListener(eventName, function newCallback() {
  219. _self.removeEventListener(eventName, newCallback);
  220. callback.apply(null, arguments);
  221. });
  222. };
  223. EventEmitter.setDefaultHandler = function(eventName, callback) {
  224. var handlers = this._defaultHandlers
  225. if (!handlers)
  226. handlers = this._defaultHandlers = {_disabled_: {}};
  227. if (handlers[eventName]) {
  228. var old = handlers[eventName];
  229. var disabled = handlers._disabled_[eventName];
  230. if (!disabled)
  231. handlers._disabled_[eventName] = disabled = [];
  232. disabled.push(old);
  233. var i = disabled.indexOf(callback);
  234. if (i != -1)
  235. disabled.splice(i, 1);
  236. }
  237. handlers[eventName] = callback;
  238. };
  239. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  240. var handlers = this._defaultHandlers
  241. if (!handlers)
  242. return;
  243. var disabled = handlers._disabled_[eventName];
  244. if (handlers[eventName] == callback) {
  245. var old = handlers[eventName];
  246. if (disabled)
  247. this.setDefaultHandler(eventName, disabled.pop());
  248. } else if (disabled) {
  249. var i = disabled.indexOf(callback);
  250. if (i != -1)
  251. disabled.splice(i, 1);
  252. }
  253. };
  254. EventEmitter.on =
  255. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  256. this._eventRegistry = this._eventRegistry || {};
  257. var listeners = this._eventRegistry[eventName];
  258. if (!listeners)
  259. listeners = this._eventRegistry[eventName] = [];
  260. if (listeners.indexOf(callback) == -1)
  261. listeners[capturing ? "unshift" : "push"](callback);
  262. return callback;
  263. };
  264. EventEmitter.off =
  265. EventEmitter.removeListener =
  266. EventEmitter.removeEventListener = function(eventName, callback) {
  267. this._eventRegistry = this._eventRegistry || {};
  268. var listeners = this._eventRegistry[eventName];
  269. if (!listeners)
  270. return;
  271. var index = listeners.indexOf(callback);
  272. if (index !== -1)
  273. listeners.splice(index, 1);
  274. };
  275. EventEmitter.removeAllListeners = function(eventName) {
  276. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  277. };
  278. exports.EventEmitter = EventEmitter;
  279. });
  280. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  281. "use strict";
  282. var comparePoints = function(p1, p2) {
  283. return p1.row - p2.row || p1.column - p2.column;
  284. };
  285. var Range = function(startRow, startColumn, endRow, endColumn) {
  286. this.start = {
  287. row: startRow,
  288. column: startColumn
  289. };
  290. this.end = {
  291. row: endRow,
  292. column: endColumn
  293. };
  294. };
  295. (function() {
  296. this.isEqual = function(range) {
  297. return this.start.row === range.start.row &&
  298. this.end.row === range.end.row &&
  299. this.start.column === range.start.column &&
  300. this.end.column === range.end.column;
  301. };
  302. this.toString = function() {
  303. return ("Range: [" + this.start.row + "/" + this.start.column +
  304. "] -> [" + this.end.row + "/" + this.end.column + "]");
  305. };
  306. this.contains = function(row, column) {
  307. return this.compare(row, column) == 0;
  308. };
  309. this.compareRange = function(range) {
  310. var cmp,
  311. end = range.end,
  312. start = range.start;
  313. cmp = this.compare(end.row, end.column);
  314. if (cmp == 1) {
  315. cmp = this.compare(start.row, start.column);
  316. if (cmp == 1) {
  317. return 2;
  318. } else if (cmp == 0) {
  319. return 1;
  320. } else {
  321. return 0;
  322. }
  323. } else if (cmp == -1) {
  324. return -2;
  325. } else {
  326. cmp = this.compare(start.row, start.column);
  327. if (cmp == -1) {
  328. return -1;
  329. } else if (cmp == 1) {
  330. return 42;
  331. } else {
  332. return 0;
  333. }
  334. }
  335. };
  336. this.comparePoint = function(p) {
  337. return this.compare(p.row, p.column);
  338. };
  339. this.containsRange = function(range) {
  340. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  341. };
  342. this.intersects = function(range) {
  343. var cmp = this.compareRange(range);
  344. return (cmp == -1 || cmp == 0 || cmp == 1);
  345. };
  346. this.isEnd = function(row, column) {
  347. return this.end.row == row && this.end.column == column;
  348. };
  349. this.isStart = function(row, column) {
  350. return this.start.row == row && this.start.column == column;
  351. };
  352. this.setStart = function(row, column) {
  353. if (typeof row == "object") {
  354. this.start.column = row.column;
  355. this.start.row = row.row;
  356. } else {
  357. this.start.row = row;
  358. this.start.column = column;
  359. }
  360. };
  361. this.setEnd = function(row, column) {
  362. if (typeof row == "object") {
  363. this.end.column = row.column;
  364. this.end.row = row.row;
  365. } else {
  366. this.end.row = row;
  367. this.end.column = column;
  368. }
  369. };
  370. this.inside = function(row, column) {
  371. if (this.compare(row, column) == 0) {
  372. if (this.isEnd(row, column) || this.isStart(row, column)) {
  373. return false;
  374. } else {
  375. return true;
  376. }
  377. }
  378. return false;
  379. };
  380. this.insideStart = function(row, column) {
  381. if (this.compare(row, column) == 0) {
  382. if (this.isEnd(row, column)) {
  383. return false;
  384. } else {
  385. return true;
  386. }
  387. }
  388. return false;
  389. };
  390. this.insideEnd = function(row, column) {
  391. if (this.compare(row, column) == 0) {
  392. if (this.isStart(row, column)) {
  393. return false;
  394. } else {
  395. return true;
  396. }
  397. }
  398. return false;
  399. };
  400. this.compare = function(row, column) {
  401. if (!this.isMultiLine()) {
  402. if (row === this.start.row) {
  403. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  404. };
  405. }
  406. if (row < this.start.row)
  407. return -1;
  408. if (row > this.end.row)
  409. return 1;
  410. if (this.start.row === row)
  411. return column >= this.start.column ? 0 : -1;
  412. if (this.end.row === row)
  413. return column <= this.end.column ? 0 : 1;
  414. return 0;
  415. };
  416. this.compareStart = function(row, column) {
  417. if (this.start.row == row && this.start.column == column) {
  418. return -1;
  419. } else {
  420. return this.compare(row, column);
  421. }
  422. };
  423. this.compareEnd = function(row, column) {
  424. if (this.end.row == row && this.end.column == column) {
  425. return 1;
  426. } else {
  427. return this.compare(row, column);
  428. }
  429. };
  430. this.compareInside = function(row, column) {
  431. if (this.end.row == row && this.end.column == column) {
  432. return 1;
  433. } else if (this.start.row == row && this.start.column == column) {
  434. return -1;
  435. } else {
  436. return this.compare(row, column);
  437. }
  438. };
  439. this.clipRows = function(firstRow, lastRow) {
  440. if (this.end.row > lastRow)
  441. var end = {row: lastRow + 1, column: 0};
  442. else if (this.end.row < firstRow)
  443. var end = {row: firstRow, column: 0};
  444. if (this.start.row > lastRow)
  445. var start = {row: lastRow + 1, column: 0};
  446. else if (this.start.row < firstRow)
  447. var start = {row: firstRow, column: 0};
  448. return Range.fromPoints(start || this.start, end || this.end);
  449. };
  450. this.extend = function(row, column) {
  451. var cmp = this.compare(row, column);
  452. if (cmp == 0)
  453. return this;
  454. else if (cmp == -1)
  455. var start = {row: row, column: column};
  456. else
  457. var end = {row: row, column: column};
  458. return Range.fromPoints(start || this.start, end || this.end);
  459. };
  460. this.isEmpty = function() {
  461. return (this.start.row === this.end.row && this.start.column === this.end.column);
  462. };
  463. this.isMultiLine = function() {
  464. return (this.start.row !== this.end.row);
  465. };
  466. this.clone = function() {
  467. return Range.fromPoints(this.start, this.end);
  468. };
  469. this.collapseRows = function() {
  470. if (this.end.column == 0)
  471. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  472. else
  473. return new Range(this.start.row, 0, this.end.row, 0)
  474. };
  475. this.toScreenRange = function(session) {
  476. var screenPosStart = session.documentToScreenPosition(this.start);
  477. var screenPosEnd = session.documentToScreenPosition(this.end);
  478. return new Range(
  479. screenPosStart.row, screenPosStart.column,
  480. screenPosEnd.row, screenPosEnd.column
  481. );
  482. };
  483. this.moveBy = function(row, column) {
  484. this.start.row += row;
  485. this.start.column += column;
  486. this.end.row += row;
  487. this.end.column += column;
  488. };
  489. }).call(Range.prototype);
  490. Range.fromPoints = function(start, end) {
  491. return new Range(start.row, start.column, end.row, end.column);
  492. };
  493. Range.comparePoints = comparePoints;
  494. Range.comparePoints = function(p1, p2) {
  495. return p1.row - p2.row || p1.column - p2.column;
  496. };
  497. exports.Range = Range;
  498. });
  499. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  500. "use strict";
  501. var oop = require("./lib/oop");
  502. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  503. var Anchor = exports.Anchor = function(doc, row, column) {
  504. this.$onChange = this.onChange.bind(this);
  505. this.attach(doc);
  506. if (typeof column == "undefined")
  507. this.setPosition(row.row, row.column);
  508. else
  509. this.setPosition(row, column);
  510. };
  511. (function() {
  512. oop.implement(this, EventEmitter);
  513. this.getPosition = function() {
  514. return this.$clipPositionToDocument(this.row, this.column);
  515. };
  516. this.getDocument = function() {
  517. return this.document;
  518. };
  519. this.$insertRight = false;
  520. this.onChange = function(e) {
  521. var delta = e.data;
  522. var range = delta.range;
  523. if (range.start.row == range.end.row && range.start.row != this.row)
  524. return;
  525. if (range.start.row > this.row)
  526. return;
  527. if (range.start.row == this.row && range.start.column > this.column)
  528. return;
  529. var row = this.row;
  530. var column = this.column;
  531. var start = range.start;
  532. var end = range.end;
  533. if (delta.action === "insertText") {
  534. if (start.row === row && start.column <= column) {
  535. if (start.column === column && this.$insertRight) {
  536. } else if (start.row === end.row) {
  537. column += end.column - start.column;
  538. } else {
  539. column -= start.column;
  540. row += end.row - start.row;
  541. }
  542. } else if (start.row !== end.row && start.row < row) {
  543. row += end.row - start.row;
  544. }
  545. } else if (delta.action === "insertLines") {
  546. if (start.row === row && column === 0 && this.$insertRight) {
  547. }
  548. else if (start.row <= row) {
  549. row += end.row - start.row;
  550. }
  551. } else if (delta.action === "removeText") {
  552. if (start.row === row && start.column < column) {
  553. if (end.column >= column)
  554. column = start.column;
  555. else
  556. column = Math.max(0, column - (end.column - start.column));
  557. } else if (start.row !== end.row && start.row < row) {
  558. if (end.row === row)
  559. column = Math.max(0, column - end.column) + start.column;
  560. row -= (end.row - start.row);
  561. } else if (end.row === row) {
  562. row -= end.row - start.row;
  563. column = Math.max(0, column - end.column) + start.column;
  564. }
  565. } else if (delta.action == "removeLines") {
  566. if (start.row <= row) {
  567. if (end.row <= row)
  568. row -= end.row - start.row;
  569. else {
  570. row = start.row;
  571. column = 0;
  572. }
  573. }
  574. }
  575. this.setPosition(row, column, true);
  576. };
  577. this.setPosition = function(row, column, noClip) {
  578. var pos;
  579. if (noClip) {
  580. pos = {
  581. row: row,
  582. column: column
  583. };
  584. } else {
  585. pos = this.$clipPositionToDocument(row, column);
  586. }
  587. if (this.row == pos.row && this.column == pos.column)
  588. return;
  589. var old = {
  590. row: this.row,
  591. column: this.column
  592. };
  593. this.row = pos.row;
  594. this.column = pos.column;
  595. this._signal("change", {
  596. old: old,
  597. value: pos
  598. });
  599. };
  600. this.detach = function() {
  601. this.document.removeEventListener("change", this.$onChange);
  602. };
  603. this.attach = function(doc) {
  604. this.document = doc || this.document;
  605. this.document.on("change", this.$onChange);
  606. };
  607. this.$clipPositionToDocument = function(row, column) {
  608. var pos = {};
  609. if (row >= this.document.getLength()) {
  610. pos.row = Math.max(0, this.document.getLength() - 1);
  611. pos.column = this.document.getLine(pos.row).length;
  612. }
  613. else if (row < 0) {
  614. pos.row = 0;
  615. pos.column = 0;
  616. }
  617. else {
  618. pos.row = row;
  619. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  620. }
  621. if (column < 0)
  622. pos.column = 0;
  623. return pos;
  624. };
  625. }).call(Anchor.prototype);
  626. });
  627. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  628. "use strict";
  629. var oop = require("./lib/oop");
  630. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  631. var Range = require("./range").Range;
  632. var Anchor = require("./anchor").Anchor;
  633. var Document = function(text) {
  634. this.$lines = [];
  635. if (text.length === 0) {
  636. this.$lines = [""];
  637. } else if (Array.isArray(text)) {
  638. this._insertLines(0, text);
  639. } else {
  640. this.insert({row: 0, column:0}, text);
  641. }
  642. };
  643. (function() {
  644. oop.implement(this, EventEmitter);
  645. this.setValue = function(text) {
  646. var len = this.getLength();
  647. this.remove(new Range(0, 0, len, this.getLine(len-1).length));
  648. this.insert({row: 0, column:0}, text);
  649. };
  650. this.getValue = function() {
  651. return this.getAllLines().join(this.getNewLineCharacter());
  652. };
  653. this.createAnchor = function(row, column) {
  654. return new Anchor(this, row, column);
  655. };
  656. if ("aaa".split(/a/).length === 0)
  657. this.$split = function(text) {
  658. return text.replace(/\r\n|\r/g, "\n").split("\n");
  659. };
  660. else
  661. this.$split = function(text) {
  662. return text.split(/\r\n|\r|\n/);
  663. };
  664. this.$detectNewLine = function(text) {
  665. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  666. this.$autoNewLine = match ? match[1] : "\n";
  667. this._signal("changeNewLineMode");
  668. };
  669. this.getNewLineCharacter = function() {
  670. switch (this.$newLineMode) {
  671. case "windows":
  672. return "\r\n";
  673. case "unix":
  674. return "\n";
  675. default:
  676. return this.$autoNewLine || "\n";
  677. }
  678. };
  679. this.$autoNewLine = "";
  680. this.$newLineMode = "auto";
  681. this.setNewLineMode = function(newLineMode) {
  682. if (this.$newLineMode === newLineMode)
  683. return;
  684. this.$newLineMode = newLineMode;
  685. this._signal("changeNewLineMode");
  686. };
  687. this.getNewLineMode = function() {
  688. return this.$newLineMode;
  689. };
  690. this.isNewLine = function(text) {
  691. return (text == "\r\n" || text == "\r" || text == "\n");
  692. };
  693. this.getLine = function(row) {
  694. return this.$lines[row] || "";
  695. };
  696. this.getLines = function(firstRow, lastRow) {
  697. return this.$lines.slice(firstRow, lastRow + 1);
  698. };
  699. this.getAllLines = function() {
  700. return this.getLines(0, this.getLength());
  701. };
  702. this.getLength = function() {
  703. return this.$lines.length;
  704. };
  705. this.getTextRange = function(range) {
  706. if (range.start.row == range.end.row) {
  707. return this.getLine(range.start.row)
  708. .substring(range.start.column, range.end.column);
  709. }
  710. var lines = this.getLines(range.start.row, range.end.row);
  711. lines[0] = (lines[0] || "").substring(range.start.column);
  712. var l = lines.length - 1;
  713. if (range.end.row - range.start.row == l)
  714. lines[l] = lines[l].substring(0, range.end.column);
  715. return lines.join(this.getNewLineCharacter());
  716. };
  717. this.$clipPosition = function(position) {
  718. var length = this.getLength();
  719. if (position.row >= length) {
  720. position.row = Math.max(0, length - 1);
  721. position.column = this.getLine(length-1).length;
  722. } else if (position.row < 0)
  723. position.row = 0;
  724. return position;
  725. };
  726. this.insert = function(position, text) {
  727. if (!text || text.length === 0)
  728. return position;
  729. position = this.$clipPosition(position);
  730. if (this.getLength() <= 1)
  731. this.$detectNewLine(text);
  732. var lines = this.$split(text);
  733. var firstLine = lines.splice(0, 1)[0];
  734. var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
  735. position = this.insertInLine(position, firstLine);
  736. if (lastLine !== null) {
  737. position = this.insertNewLine(position); // terminate first line
  738. position = this._insertLines(position.row, lines);
  739. position = this.insertInLine(position, lastLine || "");
  740. }
  741. return position;
  742. };
  743. this.insertLines = function(row, lines) {
  744. if (row >= this.getLength())
  745. return this.insert({row: row, column: 0}, "\n" + lines.join("\n"));
  746. return this._insertLines(Math.max(row, 0), lines);
  747. };
  748. this._insertLines = function(row, lines) {
  749. if (lines.length == 0)
  750. return {row: row, column: 0};
  751. while (lines.length > 0xF000) {
  752. var end = this._insertLines(row, lines.slice(0, 0xF000));
  753. lines = lines.slice(0xF000);
  754. row = end.row;
  755. }
  756. var args = [row, 0];
  757. args.push.apply(args, lines);
  758. this.$lines.splice.apply(this.$lines, args);
  759. var range = new Range(row, 0, row + lines.length, 0);
  760. var delta = {
  761. action: "insertLines",
  762. range: range,
  763. lines: lines
  764. };
  765. this._signal("change", { data: delta });
  766. return range.end;
  767. };
  768. this.insertNewLine = function(position) {
  769. position = this.$clipPosition(position);
  770. var line = this.$lines[position.row] || "";
  771. this.$lines[position.row] = line.substring(0, position.column);
  772. this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
  773. var end = {
  774. row : position.row + 1,
  775. column : 0
  776. };
  777. var delta = {
  778. action: "insertText",
  779. range: Range.fromPoints(position, end),
  780. text: this.getNewLineCharacter()
  781. };
  782. this._signal("change", { data: delta });
  783. return end;
  784. };
  785. this.insertInLine = function(position, text) {
  786. if (text.length == 0)
  787. return position;
  788. var line = this.$lines[position.row] || "";
  789. this.$lines[position.row] = line.substring(0, position.column) + text
  790. + line.substring(position.column);
  791. var end = {
  792. row : position.row,
  793. column : position.column + text.length
  794. };
  795. var delta = {
  796. action: "insertText",
  797. range: Range.fromPoints(position, end),
  798. text: text
  799. };
  800. this._signal("change", { data: delta });
  801. return end;
  802. };
  803. this.remove = function(range) {
  804. if (!(range instanceof Range))
  805. range = Range.fromPoints(range.start, range.end);
  806. range.start = this.$clipPosition(range.start);
  807. range.end = this.$clipPosition(range.end);
  808. if (range.isEmpty())
  809. return range.start;
  810. var firstRow = range.start.row;
  811. var lastRow = range.end.row;
  812. if (range.isMultiLine()) {
  813. var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
  814. var lastFullRow = lastRow - 1;
  815. if (range.end.column > 0)
  816. this.removeInLine(lastRow, 0, range.end.column);
  817. if (lastFullRow >= firstFullRow)
  818. this._removeLines(firstFullRow, lastFullRow);
  819. if (firstFullRow != firstRow) {
  820. this.removeInLine(firstRow, range.start.column, this.getLine(firstRow).length);
  821. this.removeNewLine(range.start.row);
  822. }
  823. }
  824. else {
  825. this.removeInLine(firstRow, range.start.column, range.end.column);
  826. }
  827. return range.start;
  828. };
  829. this.removeInLine = function(row, startColumn, endColumn) {
  830. if (startColumn == endColumn)
  831. return;
  832. var range = new Range(row, startColumn, row, endColumn);
  833. var line = this.getLine(row);
  834. var removed = line.substring(startColumn, endColumn);
  835. var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
  836. this.$lines.splice(row, 1, newLine);
  837. var delta = {
  838. action: "removeText",
  839. range: range,
  840. text: removed
  841. };
  842. this._signal("change", { data: delta });
  843. return range.start;
  844. };
  845. this.removeLines = function(firstRow, lastRow) {
  846. if (firstRow < 0 || lastRow >= this.getLength())
  847. return this.remove(new Range(firstRow, 0, lastRow + 1, 0));
  848. return this._removeLines(firstRow, lastRow);
  849. };
  850. this._removeLines = function(firstRow, lastRow) {
  851. var range = new Range(firstRow, 0, lastRow + 1, 0);
  852. var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
  853. var delta = {
  854. action: "removeLines",
  855. range: range,
  856. nl: this.getNewLineCharacter(),
  857. lines: removed
  858. };
  859. this._signal("change", { data: delta });
  860. return removed;
  861. };
  862. this.removeNewLine = function(row) {
  863. var firstLine = this.getLine(row);
  864. var secondLine = this.getLine(row+1);
  865. var range = new Range(row, firstLine.length, row+1, 0);
  866. var line = firstLine + secondLine;
  867. this.$lines.splice(row, 2, line);
  868. var delta = {
  869. action: "removeText",
  870. range: range,
  871. text: this.getNewLineCharacter()
  872. };
  873. this._signal("change", { data: delta });
  874. };
  875. this.replace = function(range, text) {
  876. if (!(range instanceof Range))
  877. range = Range.fromPoints(range.start, range.end);
  878. if (text.length == 0 && range.isEmpty())
  879. return range.start;
  880. if (text == this.getTextRange(range))
  881. return range.end;
  882. this.remove(range);
  883. if (text) {
  884. var end = this.insert(range.start, text);
  885. }
  886. else {
  887. end = range.start;
  888. }
  889. return end;
  890. };
  891. this.applyDeltas = function(deltas) {
  892. for (var i=0; i<deltas.length; i++) {
  893. var delta = deltas[i];
  894. var range = Range.fromPoints(delta.range.start, delta.range.end);
  895. if (delta.action == "insertLines")
  896. this.insertLines(range.start.row, delta.lines);
  897. else if (delta.action == "insertText")
  898. this.insert(range.start, delta.text);
  899. else if (delta.action == "removeLines")
  900. this._removeLines(range.start.row, range.end.row - 1);
  901. else if (delta.action == "removeText")
  902. this.remove(range);
  903. }
  904. };
  905. this.revertDeltas = function(deltas) {
  906. for (var i=deltas.length-1; i>=0; i--) {
  907. var delta = deltas[i];
  908. var range = Range.fromPoints(delta.range.start, delta.range.end);
  909. if (delta.action == "insertLines")
  910. this._removeLines(range.start.row, range.end.row - 1);
  911. else if (delta.action == "insertText")
  912. this.remove(range);
  913. else if (delta.action == "removeLines")
  914. this._insertLines(range.start.row, delta.lines);
  915. else if (delta.action == "removeText")
  916. this.insert(range.start, delta.text);
  917. }
  918. };
  919. this.indexToPosition = function(index, startRow) {
  920. var lines = this.$lines || this.getAllLines();
  921. var newlineLength = this.getNewLineCharacter().length;
  922. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  923. index -= lines[i].length + newlineLength;
  924. if (index < 0)
  925. return {row: i, column: index + lines[i].length + newlineLength};
  926. }
  927. return {row: l-1, column: lines[l-1].length};
  928. };
  929. this.positionToIndex = function(pos, startRow) {
  930. var lines = this.$lines || this.getAllLines();
  931. var newlineLength = this.getNewLineCharacter().length;
  932. var index = 0;
  933. var row = Math.min(pos.row, lines.length);
  934. for (var i = startRow || 0; i < row; ++i)
  935. index += lines[i].length + newlineLength;
  936. return index + pos.column;
  937. };
  938. }).call(Document.prototype);
  939. exports.Document = Document;
  940. });
  941. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  942. "use strict";
  943. exports.last = function(a) {
  944. return a[a.length - 1];
  945. };
  946. exports.stringReverse = function(string) {
  947. return string.split("").reverse().join("");
  948. };
  949. exports.stringRepeat = function (string, count) {
  950. var result = '';
  951. while (count > 0) {
  952. if (count & 1)
  953. result += string;
  954. if (count >>= 1)
  955. string += string;
  956. }
  957. return result;
  958. };
  959. var trimBeginRegexp = /^\s\s*/;
  960. var trimEndRegexp = /\s\s*$/;
  961. exports.stringTrimLeft = function (string) {
  962. return string.replace(trimBeginRegexp, '');
  963. };
  964. exports.stringTrimRight = function (string) {
  965. return string.replace(trimEndRegexp, '');
  966. };
  967. exports.copyObject = function(obj) {
  968. var copy = {};
  969. for (var key in obj) {
  970. copy[key] = obj[key];
  971. }
  972. return copy;
  973. };
  974. exports.copyArray = function(array){
  975. var copy = [];
  976. for (var i=0, l=array.length; i<l; i++) {
  977. if (array[i] && typeof array[i] == "object")
  978. copy[i] = this.copyObject( array[i] );
  979. else
  980. copy[i] = array[i];
  981. }
  982. return copy;
  983. };
  984. exports.deepCopy = function (obj) {
  985. if (typeof obj !== "object" || !obj)
  986. return obj;
  987. var cons = obj.constructor;
  988. if (cons === RegExp)
  989. return obj;
  990. var copy = cons();
  991. for (var key in obj) {
  992. if (typeof obj[key] === "object") {
  993. copy[key] = exports.deepCopy(obj[key]);
  994. } else {
  995. copy[key] = obj[key];
  996. }
  997. }
  998. return copy;
  999. };
  1000. exports.arrayToMap = function(arr) {
  1001. var map = {};
  1002. for (var i=0; i<arr.length; i++) {
  1003. map[arr[i]] = 1;
  1004. }
  1005. return map;
  1006. };
  1007. exports.createMap = function(props) {
  1008. var map = Object.create(null);
  1009. for (var i in props) {
  1010. map[i] = props[i];
  1011. }
  1012. return map;
  1013. };
  1014. exports.arrayRemove = function(array, value) {
  1015. for (var i = 0; i <= array.length; i++) {
  1016. if (value === array[i]) {
  1017. array.splice(i, 1);
  1018. }
  1019. }
  1020. };
  1021. exports.escapeRegExp = function(str) {
  1022. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1023. };
  1024. exports.escapeHTML = function(str) {
  1025. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1026. };
  1027. exports.getMatchOffsets = function(string, regExp) {
  1028. var matches = [];
  1029. string.replace(regExp, function(str) {
  1030. matches.push({
  1031. offset: arguments[arguments.length-2],
  1032. length: str.length
  1033. });
  1034. });
  1035. return matches;
  1036. };
  1037. exports.deferredCall = function(fcn) {
  1038. var timer = null;
  1039. var callback = function() {
  1040. timer = null;
  1041. fcn();
  1042. };
  1043. var deferred = function(timeout) {
  1044. deferred.cancel();
  1045. timer = setTimeout(callback, timeout || 0);
  1046. return deferred;
  1047. };
  1048. deferred.schedule = deferred;
  1049. deferred.call = function() {
  1050. this.cancel();
  1051. fcn();
  1052. return deferred;
  1053. };
  1054. deferred.cancel = function() {
  1055. clearTimeout(timer);
  1056. timer = null;
  1057. return deferred;
  1058. };
  1059. deferred.isPending = function() {
  1060. return timer;
  1061. };
  1062. return deferred;
  1063. };
  1064. exports.delayedCall = function(fcn, defaultTimeout) {
  1065. var timer = null;
  1066. var callback = function() {
  1067. timer = null;
  1068. fcn();
  1069. };
  1070. var _self = function(timeout) {
  1071. if (timer == null)
  1072. timer = setTimeout(callback, timeout || defaultTimeout);
  1073. };
  1074. _self.delay = function(timeout) {
  1075. timer && clearTimeout(timer);
  1076. timer = setTimeout(callback, timeout || defaultTimeout);
  1077. };
  1078. _self.schedule = _self;
  1079. _self.call = function() {
  1080. this.cancel();
  1081. fcn();
  1082. };
  1083. _self.cancel = function() {
  1084. timer && clearTimeout(timer);
  1085. timer = null;
  1086. };
  1087. _self.isPending = function() {
  1088. return timer;
  1089. };
  1090. return _self;
  1091. };
  1092. });
  1093. ace.define("ace/worker/mirror",["require","exports","module","ace/document","ace/lib/lang"], function(require, exports, module) {
  1094. "use strict";
  1095. var Document = require("../document").Document;
  1096. var lang = require("../lib/lang");
  1097. var Mirror = exports.Mirror = function(sender) {
  1098. this.sender = sender;
  1099. var doc = this.doc = new Document("");
  1100. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1101. var _self = this;
  1102. sender.on("change", function(e) {
  1103. doc.applyDeltas(e.data);
  1104. if (_self.$timeout)
  1105. return deferredUpdate.schedule(_self.$timeout);
  1106. _self.onUpdate();
  1107. });
  1108. };
  1109. (function() {
  1110. this.$timeout = 500;
  1111. this.setTimeout = function(timeout) {
  1112. this.$timeout = timeout;
  1113. };
  1114. this.setValue = function(value) {
  1115. this.doc.setValue(value);
  1116. this.deferredUpdate.schedule(this.$timeout);
  1117. };
  1118. this.getValue = function(callbackId) {
  1119. this.sender.callback(this.doc.getValue(), callbackId);
  1120. };
  1121. this.onUpdate = function() {
  1122. };
  1123. this.isPending = function() {
  1124. return this.deferredUpdate.isPending();
  1125. };
  1126. }).call(Mirror.prototype);
  1127. });
  1128. ace.define("ace/mode/javascript/jshint",["require","exports","module"], function(require, exports, module) {
  1129. module.exports = (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({
  1130. 1:[function(_dereq_,module,exports){
  1131. var identifierStartTable = [];
  1132. for (var i = 0; i < 128; i++) {
  1133. identifierStartTable[i] =
  1134. i === 36 || // $
  1135. i >= 65 && i <= 90 || // A-Z
  1136. i === 95 || // _
  1137. i >= 97 && i <= 122; // a-z
  1138. }
  1139. var identifierPartTable = [];
  1140. for (var i = 0; i < 128; i++) {
  1141. identifierPartTable[i] =
  1142. identifierStartTable[i] || // $, _, A-Z, a-z
  1143. i >= 48 && i <= 57; // 0-9
  1144. }
  1145. module.exports = {
  1146. asciiIdentifierStartTable: identifierStartTable,
  1147. asciiIdentifierPartTable: identifierPartTable
  1148. };
  1149. },
  1150. {}],
  1151. 2:[function(_dereq_,module,exports){
  1152. (function() {
  1153. var root = this;
  1154. var previousUnderscore = root._;
  1155. var breaker = {};
  1156. var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
  1157. var
  1158. push = ArrayProto.push,
  1159. slice = ArrayProto.slice,
  1160. concat = ArrayProto.concat,
  1161. toString = ObjProto.toString,
  1162. hasOwnProperty = ObjProto.hasOwnProperty;
  1163. var
  1164. nativeForEach = ArrayProto.forEach,
  1165. nativeMap = ArrayProto.map,
  1166. nativeReduce = ArrayProto.reduce,
  1167. nativeReduceRight = ArrayProto.reduceRight,
  1168. nativeFilter = ArrayProto.filter,
  1169. nativeEvery = ArrayProto.every,
  1170. nativeSome = ArrayProto.some,
  1171. nativeIndexOf = ArrayProto.indexOf,
  1172. nativeLastIndexOf = ArrayProto.lastIndexOf,
  1173. nativeIsArray = Array.isArray,
  1174. nativeKeys = Object.keys,
  1175. nativeBind = FuncProto.bind;
  1176. var _ = function(obj) {
  1177. if (obj instanceof _) return obj;
  1178. if (!(this instanceof _)) return new _(obj);
  1179. this._wrapped = obj;
  1180. };
  1181. if (typeof exports !== 'undefined') {
  1182. if (typeof module !== 'undefined' && module.exports) {
  1183. exports = module.exports = _;
  1184. }
  1185. exports._ = _;
  1186. } else {
  1187. root._ = _;
  1188. }
  1189. _.VERSION = '1.6.0';
  1190. var each = _.each = _.forEach = function(obj, iterator, context) {
  1191. if (obj == null) return obj;
  1192. if (nativeForEach && obj.forEach === nativeForEach) {
  1193. obj.forEach(iterator, context);
  1194. } else if (obj.length === +obj.length) {
  1195. for (var i = 0, length = obj.length; i < length; i++) {
  1196. if (iterator.call(context, obj[i], i, obj) === breaker) return;
  1197. }
  1198. } else {
  1199. var keys = _.keys(obj);
  1200. for (var i = 0, length = keys.length; i < length; i++) {
  1201. if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
  1202. }
  1203. }
  1204. return obj;
  1205. };
  1206. _.map = _.collect = function(obj, iterator, context) {
  1207. var results = [];
  1208. if (obj == null) return results;
  1209. if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
  1210. each(obj, function(value, index, list) {
  1211. results.push(iterator.call(context, value, index, list));
  1212. });
  1213. return results;
  1214. };
  1215. var reduceError = 'Reduce of empty array with no initial value';
  1216. _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
  1217. var initial = arguments.length > 2;
  1218. if (obj == null) obj = [];
  1219. if (nativeReduce && obj.reduce === nativeReduce) {
  1220. if (context) iterator = _.bind(iterator, context);
  1221. return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
  1222. }
  1223. each(obj, function(value, index, list) {
  1224. if (!initial) {
  1225. memo = value;
  1226. initial = true;
  1227. } else {
  1228. memo = iterator.call(context, memo, value, index, list);
  1229. }
  1230. });
  1231. if (!initial) throw new TypeError(reduceError);
  1232. return memo;
  1233. };
  1234. _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
  1235. var initial = arguments.length > 2;
  1236. if (obj == null) obj = [];
  1237. if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
  1238. if (context) iterator = _.bind(iterator, context);
  1239. return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
  1240. }
  1241. var length = obj.length;
  1242. if (length !== +length) {
  1243. var keys = _.keys(obj);
  1244. length = keys.length;
  1245. }
  1246. each(obj, function(value, index, list) {
  1247. index = keys ? keys[--length] : --length;
  1248. if (!initial) {
  1249. memo = obj[index];
  1250. initial = true;
  1251. } else {
  1252. memo = iterator.call(context, memo, obj[index], index, list);
  1253. }
  1254. });
  1255. if (!initial) throw new TypeError(reduceError);
  1256. return memo;
  1257. };
  1258. _.find = _.detect = function(obj, predicate, context) {
  1259. var result;
  1260. any(obj, function(value, index, list) {
  1261. if (predicate.call(context, value, index, list)) {
  1262. result = value;
  1263. return true;
  1264. }
  1265. });
  1266. return result;
  1267. };
  1268. _.filter = _.select = function(obj, predicate, context) {
  1269. var results = [];
  1270. if (obj == null) return results;
  1271. if (nativeFilter && obj.filter === nativeFilter) return obj.filter(predicate, context);
  1272. each(obj, function(value, index, list) {
  1273. if (predicate.call(context, value, index, list)) results.push(value);
  1274. });
  1275. return results;
  1276. };
  1277. _.reject = function(obj, predicate, context) {
  1278. return _.filter(obj, function(value, index, list) {
  1279. return !predicate.call(context, value, index, list);
  1280. }, context);
  1281. };
  1282. _.every = _.all = function(obj, predicate, context) {
  1283. predicate || (predicate = _.identity);
  1284. var result = true;
  1285. if (obj == null) return result;
  1286. if (nativeEvery && obj.every === nativeEvery) return obj.every(predicate, context);
  1287. each(obj, function(value, index, list) {
  1288. if (!(result = result && predicate.call(context, value, index, list))) return breaker;
  1289. });
  1290. return !!result;
  1291. };
  1292. var any = _.some = _.any = function(obj, predicate, context) {
  1293. predicate || (predicate = _.identity);
  1294. var result = false;
  1295. if (obj == null) return result;
  1296. if (nativeSome && obj.some === nativeSome) return obj.some(predicate, context);
  1297. each(obj, function(value, index, list) {
  1298. if (result || (result = predicate.call(context, value, index, list))) return breaker;
  1299. });
  1300. return !!result;
  1301. };
  1302. _.contains = _.include = function(obj, target) {
  1303. if (obj == null) return false;
  1304. if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
  1305. return any(obj, function(value) {
  1306. return value === target;
  1307. });
  1308. };
  1309. _.invoke = function(obj, method) {
  1310. var args = slice.call(arguments, 2);
  1311. var isFunc = _.isFunction(method);
  1312. return _.map(obj, function(value) {
  1313. return (isFunc ? method : value[method]).apply(value, args);
  1314. });
  1315. };
  1316. _.pluck = function(obj, key) {
  1317. return _.map(obj, _.property(key));
  1318. };
  1319. _.where = function(obj, attrs) {
  1320. return _.filter(obj, _.matches(attrs));
  1321. };
  1322. _.findWhere = function(obj, attrs) {
  1323. return _.find(obj, _.matches(attrs));
  1324. };
  1325. _.max = function(obj, iterator, context) {
  1326. if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
  1327. return Math.max.apply(Math, obj);
  1328. }
  1329. var result = -Infinity, lastComputed = -Infinity;
  1330. each(obj, function(value, index, list) {
  1331. var computed = iterator ? iterator.call(context, value, index, list) : value;
  1332. if (computed > lastComputed) {
  1333. result = value;
  1334. lastComputed = computed;
  1335. }
  1336. });
  1337. return result;
  1338. };
  1339. _.min = function(obj, iterator, context) {
  1340. if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
  1341. return Math.min.apply(Math, obj);
  1342. }
  1343. var result = Infinity, lastComputed = Infinity;
  1344. each(obj, function(value, index, list) {
  1345. var computed = iterator ? iterator.call(context, value, index, list) : value;
  1346. if (computed < lastComputed) {
  1347. result = value;
  1348. lastComputed = computed;
  1349. }
  1350. });
  1351. return result;
  1352. };
  1353. _.shuffle = function(obj) {
  1354. var rand;
  1355. var index = 0;
  1356. var shuffled = [];
  1357. each(obj, function(value) {
  1358. rand = _.random(index++);
  1359. shuffled[index - 1] = shuffled[rand];
  1360. shuffled[rand] = value;
  1361. });
  1362. return shuffled;
  1363. };
  1364. _.sample = function(obj, n, guard) {
  1365. if (n == null || guard) {
  1366. if (obj.length !== +obj.length) obj = _.values(obj);
  1367. return obj[_.random(obj.length - 1)];
  1368. }
  1369. return _.shuffle(obj).slice(0, Math.max(0, n));
  1370. };
  1371. var lookupIterator = function(value) {
  1372. if (value == null) return _.identity;
  1373. if (_.isFunction(value)) return value;
  1374. return _.property(value);
  1375. };
  1376. _.sortBy = function(obj, iterator, context) {
  1377. iterator = lookupIterator(iterator);
  1378. return _.pluck(_.map(obj, function(value, index, list) {
  1379. return {
  1380. value: value,
  1381. index: index,
  1382. criteria: iterator.call(context, value, index, list)
  1383. };
  1384. }).sort(function(left, right) {
  1385. var a = left.criteria;
  1386. var b = right.criteria;
  1387. if (a !== b) {
  1388. if (a > b || a === void 0) return 1;
  1389. if (a < b || b === void 0) return -1;
  1390. }
  1391. return left.index - right.index;
  1392. }), 'value');
  1393. };
  1394. var group = function(behavior) {
  1395. return function(obj, iterator, context) {
  1396. var result = {};
  1397. iterator = lookupIterator(iterator);
  1398. each(obj, function(value, index) {
  1399. var key = iterator.call(context, value, index, obj);
  1400. behavior(result, key, value);
  1401. });
  1402. return result;
  1403. };
  1404. };
  1405. _.groupBy = group(function(result, key, value) {
  1406. _.has(result, key) ? result[key].push(value) : result[key] = [value];
  1407. });
  1408. _.indexBy = group(function(result, key, value) {
  1409. result[key] = value;
  1410. });
  1411. _.countBy = group(function(result, key) {
  1412. _.has(result, key) ? result[key]++ : result[key] = 1;
  1413. });
  1414. _.sortedIndex = function(array, obj, iterator, context) {
  1415. iterator = lookupIterator(iterator);
  1416. var value = iterator.call(context, obj);
  1417. var low = 0, high = array.length;
  1418. while (low < high) {
  1419. var mid = (low + high) >>> 1;
  1420. iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
  1421. }
  1422. return low;
  1423. };
  1424. _.toArray = function(obj) {
  1425. if (!obj) return [];
  1426. if (_.isArray(obj)) return slice.call(obj);
  1427. if (obj.length === +obj.length) return _.map(obj, _.identity);
  1428. return _.values(obj);
  1429. };
  1430. _.size = function(obj) {
  1431. if (obj == null) return 0;
  1432. return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
  1433. };
  1434. _.first = _.head = _.take = function(array, n, guard) {
  1435. if (array == null) return void 0;
  1436. if ((n == null) || guard) return array[0];
  1437. if (n < 0) return [];
  1438. return slice.call(array, 0, n);
  1439. };
  1440. _.initial = function(array, n, guard) {
  1441. return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
  1442. };
  1443. _.last = function(array, n, guard) {
  1444. if (array == null) return void 0;
  1445. if ((n == null) || guard) return array[array.length - 1];
  1446. return slice.call(array, Math.max(array.length - n, 0));
  1447. };
  1448. _.rest = _.tail = _.drop = function(array, n, guard) {
  1449. return slice.call(array, (n == null) || guard ? 1 : n);
  1450. };
  1451. _.compact = function(array) {
  1452. return _.filter(array, _.identity);
  1453. };
  1454. var flatten = function(input, shallow, output) {
  1455. if (shallow && _.every(input, _.isArray)) {
  1456. return concat.apply(output, input);
  1457. }
  1458. each(input, function(value) {
  1459. if (_.isArray(value) || _.isArguments(value)) {
  1460. shallow ? push.apply(output, value) : flatten(value, shallow, output);
  1461. } else {
  1462. output.push(value);
  1463. }
  1464. });
  1465. return output;
  1466. };
  1467. _.flatten = function(array, shallow) {
  1468. return flatten(array, shallow, []);
  1469. };
  1470. _.without = function(array) {
  1471. return _.difference(array, slice.call(arguments, 1));
  1472. };
  1473. _.partition = function(array, predicate) {
  1474. var pass = [], fail = [];
  1475. each(array, function(elem) {
  1476. (predicate(elem) ? pass : fail).push(elem);
  1477. });
  1478. return [pass, fail];
  1479. };
  1480. _.uniq = _.unique = function(array, isSorted, iterator, context) {
  1481. if (_.isFunction(isSorted)) {
  1482. context = iterator;
  1483. iterator = isSorted;
  1484. isSorted = false;
  1485. }
  1486. var initial = iterator ? _.map(array, iterator, context) : array;
  1487. var results = [];
  1488. var seen = [];
  1489. each(initial, function(value, index) {
  1490. if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
  1491. seen.push(value);
  1492. results.push(array[index]);
  1493. }
  1494. });
  1495. return results;
  1496. };
  1497. _.union = function() {
  1498. return _.uniq(_.flatten(arguments, true));
  1499. };
  1500. _.intersection = function(array) {
  1501. var rest = slice.call(arguments, 1);
  1502. return _.filter(_.uniq(array), function(item) {
  1503. return _.every(rest, function(other) {
  1504. return _.contains(other, item);
  1505. });
  1506. });
  1507. };
  1508. _.difference = function(array) {
  1509. var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
  1510. return _.filter(array, function(value){ return !_.contains(rest, value); });
  1511. };
  1512. _.zip = function() {
  1513. var length = _.max(_.pluck(arguments, 'length').concat(0));
  1514. var results = new Array(length);
  1515. for (var i = 0; i < length; i++) {
  1516. results[i] = _.pluck(arguments, '' + i);
  1517. }
  1518. return results;
  1519. };
  1520. _.object = function(list, values) {
  1521. if (list == null) return {};
  1522. var result = {};
  1523. for (var i = 0, length = list.length; i < length; i++) {
  1524. if (values) {
  1525. result[list[i]] = values[i];
  1526. } else {
  1527. result[list[i][0]] = list[i][1];
  1528. }
  1529. }
  1530. return result;
  1531. };
  1532. _.indexOf = function(array, item, isSorted) {
  1533. if (array == null) return -1;
  1534. var i = 0, length = array.length;
  1535. if (isSorted) {
  1536. if (typeof isSorted == 'number') {
  1537. i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
  1538. } else {
  1539. i = _.sortedIndex(array, item);
  1540. return array[i] === item ? i : -1;
  1541. }
  1542. }
  1543. if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
  1544. for (; i < length; i++) if (array[i] === item) return i;
  1545. return -1;
  1546. };
  1547. _.lastIndexOf = function(array, item, from) {
  1548. if (array == null) return -1;
  1549. var hasIndex = from != null;
  1550. if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
  1551. return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
  1552. }
  1553. var i = (hasIndex ? from : array.length);
  1554. while (i--) if (array[i] === item) return i;
  1555. return -1;
  1556. };
  1557. _.range = function(start, stop, step) {
  1558. if (arguments.length <= 1) {
  1559. stop = start || 0;
  1560. start = 0;
  1561. }
  1562. step = arguments[2] || 1;
  1563. var length = Math.max(Math.ceil((stop - start) / step), 0);
  1564. var idx = 0;
  1565. var range = new Array(length);
  1566. while(idx < length) {
  1567. range[idx++] = start;
  1568. start += step;
  1569. }
  1570. return range;
  1571. };
  1572. var ctor = function(){};
  1573. _.bind = function(func, context) {
  1574. var args, bound;
  1575. if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
  1576. if (!_.isFunction(func)) throw new TypeError;
  1577. args = slice.call(arguments, 2);
  1578. return bound = function() {
  1579. if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
  1580. ctor.prototype = func.prototype;
  1581. var self = new ctor;
  1582. ctor.prototype = null;
  1583. var result = func.apply(self, args.concat(slice.call(arguments)));
  1584. if (Object(result) === result) return result;
  1585. return self;
  1586. };
  1587. };
  1588. _.partial = function(func) {
  1589. var boundArgs = slice.call(arguments, 1);
  1590. return function() {
  1591. var position = 0;
  1592. var args = boundArgs.slice();
  1593. for (var i = 0, length = args.length; i < length; i++) {
  1594. if (args[i] === _) args[i] = arguments[position++];
  1595. }
  1596. while (position < arguments.length) args.push(arguments[position++]);
  1597. return func.apply(this, args);
  1598. };
  1599. };
  1600. _.bindAll = function(obj) {
  1601. var funcs = slice.call(arguments, 1);
  1602. if (funcs.length === 0) throw new Error('bindAll must be passed function names');
  1603. each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
  1604. return obj;
  1605. };
  1606. _.memoize = function(func, hasher) {
  1607. var memo = {};
  1608. hasher || (hasher = _.identity);
  1609. return function() {
  1610. var key = hasher.apply(this, arguments);
  1611. return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
  1612. };
  1613. };
  1614. _.delay = function(func, wait) {
  1615. var args = slice.call(arguments, 2);
  1616. return setTimeout(function(){ return func.apply(null, args); }, wait);
  1617. };
  1618. _.defer = function(func) {
  1619. return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
  1620. };
  1621. _.throttle = function(func, wait, options) {
  1622. var context, args, result;
  1623. var timeout = null;
  1624. var previous = 0;
  1625. options || (options = {});
  1626. var later = function() {
  1627. previous = options.leading === false ? 0 : _.now();
  1628. timeout = null;
  1629. result = func.apply(context, args);
  1630. context = args = null;
  1631. };
  1632. return function() {
  1633. var now = _.now();
  1634. if (!previous && options.leading === false) previous = now;
  1635. var remaining = wait - (now - previous);
  1636. context = this;
  1637. args = arguments;
  1638. if (remaining <= 0) {
  1639. clearTimeout(timeout);
  1640. timeout = null;
  1641. previous = now;
  1642. result = func.apply(context, args);
  1643. context = args = null;
  1644. } else if (!timeout && options.trailing !== false) {
  1645. timeout = setTimeout(later, remaining);
  1646. }
  1647. return result;
  1648. };
  1649. };
  1650. _.debounce = function(func, wait, immediate) {
  1651. var timeout, args, context, timestamp, result;
  1652. var later = function() {
  1653. var last = _.now() - timestamp;
  1654. if (last < wait) {
  1655. timeout = setTimeout(later, wait - last);
  1656. } else {
  1657. timeout = null;
  1658. if (!immediate) {
  1659. result = func.apply(context, args);
  1660. context = args = null;
  1661. }
  1662. }
  1663. };
  1664. return function() {
  1665. context = this;
  1666. args = arguments;
  1667. timestamp = _.now();
  1668. var callNow = immediate && !timeout;
  1669. if (!timeout) {
  1670. timeout = setTimeout(later, wait);
  1671. }
  1672. if (callNow) {
  1673. result = func.apply(context, args);
  1674. context = args = null;
  1675. }
  1676. return result;
  1677. };
  1678. };
  1679. _.once = function(func) {
  1680. var ran = false, memo;
  1681. return function() {
  1682. if (ran) return memo;
  1683. ran = true;
  1684. memo = func.apply(this, arguments);
  1685. func = null;
  1686. return memo;
  1687. };
  1688. };
  1689. _.wrap = function(func, wrapper) {
  1690. return _.partial(wrapper, func);
  1691. };
  1692. _.compose = function() {
  1693. var funcs = arguments;
  1694. return function() {
  1695. var args = arguments;
  1696. for (var i = funcs.length - 1; i >= 0; i--) {
  1697. args = [funcs[i].apply(this, args)];
  1698. }
  1699. return args[0];
  1700. };
  1701. };
  1702. _.after = function(times, func) {
  1703. return function() {
  1704. if (--times < 1) {
  1705. return func.apply(this, arguments);
  1706. }
  1707. };
  1708. };
  1709. _.keys = function(obj) {
  1710. if (!_.isObject(obj)) return [];
  1711. if (nativeKeys) return nativeKeys(obj);
  1712. var keys = [];
  1713. for (var key in obj) if (_.has(obj, key)) keys.push(key);
  1714. return keys;
  1715. };
  1716. _.values = function(obj) {
  1717. var keys = _.keys(obj);
  1718. var length = keys.length;
  1719. var values = new Array(length);
  1720. for (var i = 0; i < length; i++) {
  1721. values[i] = obj[keys[i]];
  1722. }
  1723. return values;
  1724. };
  1725. _.pairs = function(obj) {
  1726. var keys = _.keys(obj);
  1727. var length = keys.length;
  1728. var pairs = new Array(length);
  1729. for (var i = 0; i < length; i++) {
  1730. pairs[i] = [keys[i], obj[keys[i]]];
  1731. }
  1732. return pairs;
  1733. };
  1734. _.invert = function(obj) {
  1735. var result = {};
  1736. var keys = _.keys(obj);
  1737. for (var i = 0, length = keys.length; i < length; i++) {
  1738. result[obj[keys[i]]] = keys[i];
  1739. }
  1740. return result;
  1741. };
  1742. _.functions = _.methods = function(obj) {
  1743. var names = [];
  1744. for (var key in obj) {
  1745. if (_.isFunction(obj[key])) names.push(key);
  1746. }
  1747. return names.sort();
  1748. };
  1749. _.extend = function(obj) {
  1750. each(slice.call(arguments, 1), function(source) {
  1751. if (source) {
  1752. for (var prop in source) {
  1753. obj[prop] = source[prop];
  1754. }
  1755. }
  1756. });
  1757. return obj;
  1758. };
  1759. _.pick = function(obj) {
  1760. var copy = {};
  1761. var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
  1762. each(keys, function(key) {
  1763. if (key in obj) copy[key] = obj[key];
  1764. });
  1765. return copy;
  1766. };
  1767. _.omit = function(obj) {
  1768. var copy = {};
  1769. var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
  1770. for (var key in obj) {
  1771. if (!_.contains(keys, key)) copy[key] = obj[key];
  1772. }
  1773. return copy;
  1774. };
  1775. _.defaults = function(obj) {
  1776. each(slice.call(arguments, 1), function(source) {
  1777. if (source) {
  1778. for (var prop in source) {
  1779. if (obj[prop] === void 0) obj[prop] = source[prop];
  1780. }
  1781. }
  1782. });
  1783. return obj;
  1784. };
  1785. _.clone = function(obj) {
  1786. if (!_.isObject(obj)) return obj;
  1787. return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
  1788. };
  1789. _.tap = function(obj, interceptor) {
  1790. interceptor(obj);
  1791. return obj;
  1792. };
  1793. var eq = function(a, b, aStack, bStack) {
  1794. if (a === b) return a !== 0 || 1 / a == 1 / b;
  1795. if (a == null || b == null) return a === b;
  1796. if (a instanceof _) a = a._wrapped;
  1797. if (b instanceof _) b = b._wrapped;
  1798. var className = toString.call(a);
  1799. if (className != toString.call(b)) return false;
  1800. switch (className) {
  1801. case '[object String]':
  1802. return a == String(b);
  1803. case '[object Number]':
  1804. return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
  1805. case '[object Date]':
  1806. case '[object Boolean]':
  1807. return +a == +b;
  1808. case '[object RegExp]':
  1809. return a.source == b.source &&
  1810. a.global == b.global &&
  1811. a.multiline == b.multiline &&
  1812. a.ignoreCase == b.ignoreCase;
  1813. }
  1814. if (typeof a != 'object' || typeof b != 'object') return false;
  1815. var length = aStack.length;
  1816. while (length--) {
  1817. if (aStack[length] == a) return bStack[length] == b;
  1818. }
  1819. var aCtor = a.constructor, bCtor = b.constructor;
  1820. if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
  1821. _.isFunction(bCtor) && (bCtor instanceof bCtor))
  1822. && ('constructor' in a && 'constructor' in b)) {
  1823. return false;
  1824. }
  1825. aStack.push(a);
  1826. bStack.push(b);
  1827. var size = 0, result = true;
  1828. if (className == '[object Array]') {
  1829. size = a.length;
  1830. result = size == b.length;
  1831. if (result) {
  1832. while (size--) {
  1833. if (!(result = eq(a[size], b[size], aStack, bStack))) break;
  1834. }
  1835. }
  1836. } else {
  1837. for (var key in a) {
  1838. if (_.has(a, key)) {
  1839. size++;
  1840. if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
  1841. }
  1842. }
  1843. if (result) {
  1844. for (key in b) {
  1845. if (_.has(b, key) && !(size--)) break;
  1846. }
  1847. result = !size;
  1848. }
  1849. }
  1850. aStack.pop();
  1851. bStack.pop();
  1852. return result;
  1853. };
  1854. _.isEqual = function(a, b) {
  1855. return eq(a, b, [], []);
  1856. };
  1857. _.isEmpty = function(obj) {
  1858. if (obj == null) return true;
  1859. if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
  1860. for (var key in obj) if (_.has(obj, key)) return false;
  1861. return true;
  1862. };
  1863. _.isElement = function(obj) {
  1864. return !!(obj && obj.nodeType === 1);
  1865. };
  1866. _.isArray = nativeIsArray || function(obj) {
  1867. return toString.call(obj) == '[object Array]';
  1868. };
  1869. _.isObject = function(obj) {
  1870. return obj === Object(obj);
  1871. };
  1872. each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
  1873. _['is' + name] = function(obj) {
  1874. return toString.call(obj) == '[object ' + name + ']';
  1875. };
  1876. });
  1877. if (!_.isArguments(arguments)) {
  1878. _.isArguments = function(obj) {
  1879. return !!(obj && _.has(obj, 'callee'));
  1880. };
  1881. }
  1882. if (typeof (/./) !== 'function') {
  1883. _.isFunction = function(obj) {
  1884. return typeof obj === 'function';
  1885. };
  1886. }
  1887. _.isFinite = function(obj) {
  1888. return isFinite(obj) && !isNaN(parseFloat(obj));
  1889. };
  1890. _.isNaN = function(obj) {
  1891. return _.isNumber(obj) && obj != +obj;
  1892. };
  1893. _.isBoolean = function(obj) {
  1894. return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
  1895. };
  1896. _.isNull = function(obj) {
  1897. return obj === null;
  1898. };
  1899. _.isUndefined = function(obj) {
  1900. return obj === void 0;
  1901. };
  1902. _.has = function(obj, key) {
  1903. return hasOwnProperty.call(obj, key);
  1904. };
  1905. _.noConflict = function() {
  1906. root._ = previousUnderscore;
  1907. return this;
  1908. };
  1909. _.identity = function(value) {
  1910. return value;
  1911. };
  1912. _.constant = function(value) {
  1913. return function () {
  1914. return value;
  1915. };
  1916. };
  1917. _.property = function(key) {
  1918. return function(obj) {
  1919. return obj[key];
  1920. };
  1921. };
  1922. _.matches = function(attrs) {
  1923. return function(obj) {
  1924. if (obj === attrs) return true; //avoid comparing an object to itself.
  1925. for (var key in attrs) {
  1926. if (attrs[key] !== obj[key])
  1927. return false;
  1928. }
  1929. return true;
  1930. }
  1931. };
  1932. _.times = function(n, iterator, context) {
  1933. var accum = Array(Math.max(0, n));
  1934. for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
  1935. return accum;
  1936. };
  1937. _.random = function(min, max) {
  1938. if (max == null) {
  1939. max = min;
  1940. min = 0;
  1941. }
  1942. return min + Math.floor(Math.random() * (max - min + 1));
  1943. };
  1944. _.now = Date.now || function() { return new Date().getTime(); };
  1945. var entityMap = {
  1946. escape: {
  1947. '&': '&amp;',
  1948. '<': '&lt;',
  1949. '>': '&gt;',
  1950. '"': '&quot;',
  1951. "'": '&#x27;'
  1952. }
  1953. };
  1954. entityMap.unescape = _.invert(entityMap.escape);
  1955. var entityRegexes = {
  1956. escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
  1957. unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
  1958. };
  1959. _.each(['escape', 'unescape'], function(method) {
  1960. _[method] = function(string) {
  1961. if (string == null) return '';
  1962. return ('' + string).replace(entityRegexes[method], function(match) {
  1963. return entityMap[method][match];
  1964. });
  1965. };
  1966. });
  1967. _.result = function(object, property) {
  1968. if (object == null) return void 0;
  1969. var value = object[property];
  1970. return _.isFunction(value) ? value.call(object) : value;
  1971. };
  1972. _.mixin = function(obj) {
  1973. each(_.functions(obj), function(name) {
  1974. var func = _[name] = obj[name];
  1975. _.prototype[name] = function() {
  1976. var args = [this._wrapped];
  1977. push.apply(args, arguments);
  1978. return result.call(this, func.apply(_, args));
  1979. };
  1980. });
  1981. };
  1982. var idCounter = 0;
  1983. _.uniqueId = function(prefix) {
  1984. var id = ++idCounter + '';
  1985. return prefix ? prefix + id : id;
  1986. };
  1987. _.templateSettings = {
  1988. evaluate : /<%([\s\S]+?)%>/g,
  1989. interpolate : /<%=([\s\S]+?)%>/g,
  1990. escape : /<%-([\s\S]+?)%>/g
  1991. };
  1992. var noMatch = /(.)^/;
  1993. var escapes = {
  1994. "'": "'",
  1995. '\\': '\\',
  1996. '\r': 'r',
  1997. '\n': 'n',
  1998. '\t': 't',
  1999. '\u2028': 'u2028',
  2000. '\u2029': 'u2029'
  2001. };
  2002. var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
  2003. _.template = function(text, data, settings) {
  2004. var render;
  2005. settings = _.defaults({}, settings, _.templateSettings);
  2006. var matcher = new RegExp([
  2007. (settings.escape || noMatch).source,
  2008. (settings.interpolate || noMatch).source,
  2009. (settings.evaluate || noMatch).source
  2010. ].join('|') + '|$', 'g');
  2011. var index = 0;
  2012. var source = "__p+='";
  2013. text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  2014. source += text.slice(index, offset)
  2015. .replace(escaper, function(match) { return '\\' + escapes[match]; });
  2016. if (escape) {
  2017. source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  2018. }
  2019. if (interpolate) {
  2020. source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
  2021. }
  2022. if (evaluate) {
  2023. source += "';\n" + evaluate + "\n__p+='";
  2024. }
  2025. index = offset + match.length;
  2026. return match;
  2027. });
  2028. source += "';\n";
  2029. if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  2030. source = "var __t,__p='',__j=Array.prototype.join," +
  2031. "print=function(){__p+=__j.call(arguments,'');};\n" +
  2032. source + "return __p;\n";
  2033. try {
  2034. render = new Function(settings.variable || 'obj', '_', source);
  2035. } catch (e) {
  2036. e.source = source;
  2037. throw e;
  2038. }
  2039. if (data) return render(data, _);
  2040. var template = function(data) {
  2041. return render.call(this, data, _);
  2042. };
  2043. template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
  2044. return template;
  2045. };
  2046. _.chain = function(obj) {
  2047. return _(obj).chain();
  2048. };
  2049. var result = function(obj) {
  2050. return this._chain ? _(obj).chain() : obj;
  2051. };
  2052. _.mixin(_);
  2053. each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  2054. var method = ArrayProto[name];
  2055. _.prototype[name] = function() {
  2056. var obj = this._wrapped;
  2057. method.apply(obj, arguments);
  2058. if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
  2059. return result.call(this, obj);
  2060. };
  2061. });
  2062. each(['concat', 'join', 'slice'], function(name) {
  2063. var method = ArrayProto[name];
  2064. _.prototype[name] = function() {
  2065. return result.call(this, method.apply(this._wrapped, arguments));
  2066. };
  2067. });
  2068. _.extend(_.prototype, {
  2069. chain: function() {
  2070. this._chain = true;
  2071. return this;
  2072. },
  2073. value: function() {
  2074. return this._wrapped;
  2075. }
  2076. });
  2077. if (typeof define === 'function' && define.amd) {
  2078. ace.define('underscore', [], function() {
  2079. return _;
  2080. });
  2081. }
  2082. }).call(this);
  2083. },
  2084. {}],
  2085. 3:[function(_dereq_,module,exports){
  2086. var _ = _dereq_("underscore");
  2087. var events = _dereq_("events");
  2088. var vars = _dereq_("./vars.js");
  2089. var messages = _dereq_("./messages.js");
  2090. var Lexer = _dereq_("./lex.js").Lexer;
  2091. var reg = _dereq_("./reg.js");
  2092. var state = _dereq_("./state.js").state;
  2093. var style = _dereq_("./style.js");
  2094. var JSHINT = (function () {
  2095. "use strict";
  2096. var anonname, // The guessed name for anonymous functions.
  2097. api, // Extension API
  2098. bang = {
  2099. "<" : true,
  2100. "<=" : true,
  2101. "==" : true,
  2102. "===": true,
  2103. "!==": true,
  2104. "!=" : true,
  2105. ">" : true,
  2106. ">=" : true,
  2107. "+" : true,
  2108. "-" : true,
  2109. "*" : true,
  2110. "/" : true,
  2111. "%" : true
  2112. },
  2113. boolOptions = {
  2114. asi : true, // if automatic semicolon insertion should be tolerated
  2115. bitwise : true, // if bitwise operators should not be allowed
  2116. boss : true, // if advanced usage of assignments should be allowed
  2117. browser : true, // if the standard browser globals should be predefined
  2118. camelcase : true, // if identifiers should be required in camel case
  2119. couch : true, // if CouchDB globals should be predefined
  2120. curly : true, // if curly braces around all blocks should be required
  2121. debug : true, // if debugger statements should be allowed
  2122. devel : true, // if logging globals should be predefined (console, alert, etc.)
  2123. dojo : true, // if Dojo Toolkit globals should be predefined
  2124. eqeqeq : true, // if === should be required
  2125. eqnull : true, // if == null comparisons should be tolerated
  2126. notypeof : true, // if should report typos in typeof comparisons
  2127. es3 : true, // if ES3 syntax should be allowed
  2128. es5 : true, // if ES5 syntax should be allowed (is now set per default)
  2129. esnext : true, // if es.next specific syntax should be allowed
  2130. moz : true, // if mozilla specific syntax should be allowed
  2131. evil : true, // if eval should be allowed
  2132. expr : true, // if ExpressionStatement should be allowed as Programs
  2133. forin : true, // if for in statements must filter
  2134. funcscope : true, // if only function scope should be used for scope tests
  2135. globalstrict: true, // if global "use strict"; should be allowed (also enables 'strict')
  2136. immed : true, // if immediate invocations must be wrapped in parens
  2137. iterator : true, // if the `__iterator__` property should be allowed
  2138. jasmine : true, // Jasmine functions should be predefined
  2139. jquery : true, // if jQuery globals should be predefined
  2140. lastsemic : true, // if semicolons may be ommitted for the trailing
  2141. laxbreak : true, // if line breaks should not be checked
  2142. laxcomma : true, // if line breaks should not be checked around commas
  2143. loopfunc : true, // if functions should be allowed to be defined within
  2144. mootools : true, // if MooTools globals should be predefined
  2145. multistr : true, // allow multiline strings
  2146. freeze : true, // if modifying native object prototypes should be disallowed
  2147. newcap : true, // if constructor names must be capitalized
  2148. noarg : true, // if arguments.caller and arguments.callee should be
  2149. node : true, // if the Node.js environment globals should be
  2150. noempty : true, // if empty blocks should be disallowed
  2151. nonbsp : true, // if non-breaking spaces should be disallowed
  2152. nonew : true, // if using `new` for side-effects should be disallowed
  2153. nonstandard : true, // if non-standard (but widely adopted) globals should
  2154. phantom : true, // if PhantomJS symbols should be allowed
  2155. plusplus : true, // if increment/decrement should not be allowed
  2156. proto : true, // if the `__proto__` property should be allowed
  2157. prototypejs : true, // if Prototype and Scriptaculous globals should be
  2158. qunit : true, // if the QUnit environment globals should be predefined
  2159. rhino : true, // if the Rhino environment globals should be predefined
  2160. shelljs : true, // if ShellJS globals should be predefined
  2161. typed : true, // if typed array globals should be predefined
  2162. undef : true, // if variables should be declared before used
  2163. scripturl : true, // if script-targeted URLs should be tolerated
  2164. strict : true, // require the "use strict"; pragma
  2165. sub : true, // if all forms of subscript notation are tolerated
  2166. supernew : true, // if `new function () { ... };` and `new Object;`
  2167. validthis : true, // if 'this' inside a non-constructor function is valid.
  2168. withstmt : true, // if with statements should be allowed
  2169. worker : true, // if Web Worker script symbols should be allowed
  2170. wsh : true, // if the Windows Scripting Host environment globals
  2171. yui : true, // YUI variables should be predefined
  2172. mocha : true, // Mocha functions should be predefined
  2173. noyield : true, // allow generators without a yield
  2174. onecase : true, // if one case switch statements should be allowed
  2175. regexp : true, // if the . should not be allowed in regexp literals
  2176. regexdash : true // if unescaped first/last dash (-) inside brackets
  2177. },
  2178. valOptions = {
  2179. maxlen : false,
  2180. indent : false,
  2181. maxerr : false,
  2182. predef : false, // predef is deprecated and being replaced by globals
  2183. globals : false,
  2184. quotmark : false, // 'single'|'double'|true
  2185. scope : false,
  2186. maxstatements: false, // {int} max statements per function
  2187. maxdepth : false, // {int} max nested block depth per function
  2188. maxparams : false, // {int} max params per function
  2189. maxcomplexity: false, // {int} max cyclomatic complexity per function
  2190. shadow : false, // if variable shadowing should be tolerated
  2191. unused : true, // warn if variables are unused. Available options:
  2192. latedef : false, // warn if the variable is used before its definition
  2193. ignore : false // start/end ignoring lines of code, bypassing the lexer
  2194. },
  2195. invertedOptions = {
  2196. bitwise : true,
  2197. forin : true,
  2198. newcap : true,
  2199. plusplus: true,
  2200. regexp : true,
  2201. undef : true,
  2202. eqeqeq : true,
  2203. strict : true
  2204. },
  2205. renamedOptions = {
  2206. eqeq : "eqeqeq",
  2207. windows: "wsh",
  2208. sloppy : "strict"
  2209. },
  2210. removedOptions = {
  2211. nomen: true,
  2212. onevar: true,
  2213. passfail: true,
  2214. white: true,
  2215. gcl: true,
  2216. smarttabs: true,
  2217. trailing: true
  2218. },
  2219. declared, // Globals that were declared using /*global ... */ syntax.
  2220. exported, // Variables that are used outside of the current file.
  2221. functionicity = [
  2222. "closure", "exception", "global", "label",
  2223. "outer", "unused", "var"
  2224. ],
  2225. funct, // The current function
  2226. functions, // All of the functions
  2227. global, // The global scope
  2228. implied, // Implied globals
  2229. inblock,
  2230. indent,
  2231. lookahead,
  2232. lex,
  2233. member,
  2234. membersOnly,
  2235. noreach,
  2236. predefined, // Global variables defined by option
  2237. scope, // The current scope
  2238. stack,
  2239. unuseds,
  2240. urls,
  2241. extraModules = [],
  2242. emitter = new events.EventEmitter();
  2243. function checkOption(name, t) {
  2244. name = name.trim();
  2245. if (/^[+-]W\d{3}$/g.test(name)) {
  2246. return true;
  2247. }
  2248. if (valOptions[name] === undefined && boolOptions[name] === undefined) {
  2249. if (t.type !== "jslint" && !removedOptions[name]) {
  2250. error("E001", t, name);
  2251. return false;
  2252. }
  2253. }
  2254. return true;
  2255. }
  2256. function isString(obj) {
  2257. return Object.prototype.toString.call(obj) === "[object String]";
  2258. }
  2259. function isIdentifier(tkn, value) {
  2260. if (!tkn)
  2261. return false;
  2262. if (!tkn.identifier || tkn.value !== value)
  2263. return false;
  2264. return true;
  2265. }
  2266. function isReserved(token) {
  2267. if (!token.reserved) {
  2268. return false;
  2269. }
  2270. var meta = token.meta;
  2271. if (meta && meta.isFutureReservedWord && state.option.inES5()) {
  2272. if (!meta.es5) {
  2273. return false;
  2274. }
  2275. if (meta.strictOnly) {
  2276. if (!state.option.strict && !state.directive["use strict"]) {
  2277. return false;
  2278. }
  2279. }
  2280. if (token.isProperty) {
  2281. return false;
  2282. }
  2283. }
  2284. return true;
  2285. }
  2286. function supplant(str, data) {
  2287. return str.replace(/\{([^{}]*)\}/g, function (a, b) {
  2288. var r = data[b];
  2289. return typeof r === "string" || typeof r === "number" ? r : a;
  2290. });
  2291. }
  2292. function combine(dest, src) {
  2293. Object.keys(src).forEach(function (name) {
  2294. if (_.has(JSHINT.blacklist, name)) return;
  2295. dest[name] = src[name];
  2296. });
  2297. }
  2298. function assume() {
  2299. if (state.option.esnext) {
  2300. combine(predefined, vars.newEcmaIdentifiers);
  2301. }
  2302. if (state.option.couch) {
  2303. combine(predefined, vars.couch);
  2304. }
  2305. if (state.option.qunit) {
  2306. combine(predefined, vars.qunit);
  2307. }
  2308. if (state.option.rhino) {
  2309. combine(predefined, vars.rhino);
  2310. }
  2311. if (state.option.shelljs) {
  2312. combine(predefined, vars.shelljs);
  2313. combine(predefined, vars.node);
  2314. }
  2315. if (state.option.typed) {
  2316. combine(predefined, vars.typed);
  2317. }
  2318. if (state.option.phantom) {
  2319. combine(predefined, vars.phantom);
  2320. }
  2321. if (state.option.prototypejs) {
  2322. combine(predefined, vars.prototypejs);
  2323. }
  2324. if (state.option.node) {
  2325. combine(predefined, vars.node);
  2326. combine(predefined, vars.typed);
  2327. }
  2328. if (state.option.devel) {
  2329. combine(predefined, vars.devel);
  2330. }
  2331. if (state.option.dojo) {
  2332. combine(predefined, vars.dojo);
  2333. }
  2334. if (state.option.browser) {
  2335. combine(predefined, vars.browser);
  2336. combine(predefined, vars.typed);
  2337. }
  2338. if (state.option.nonstandard) {
  2339. combine(predefined, vars.nonstandard);
  2340. }
  2341. if (state.option.jasmine) {
  2342. combine(predefined, vars.jasmine);
  2343. }
  2344. if (state.option.jquery) {
  2345. combine(predefined, vars.jquery);
  2346. }
  2347. if (state.option.mootools) {
  2348. combine(predefined, vars.mootools);
  2349. }
  2350. if (state.option.worker) {
  2351. combine(predefined, vars.worker);
  2352. }
  2353. if (state.option.wsh) {
  2354. combine(predefined, vars.wsh);
  2355. }
  2356. if (state.option.globalstrict && state.option.strict !== false) {
  2357. state.option.strict = true;
  2358. }
  2359. if (state.option.yui) {
  2360. combine(predefined, vars.yui);
  2361. }
  2362. if (state.option.mocha) {
  2363. combine(predefined, vars.mocha);
  2364. }
  2365. state.option.inMoz = function (strict) {
  2366. return state.option.moz;
  2367. };
  2368. state.option.inESNext = function (strict) {
  2369. return state.option.moz || state.option.esnext;
  2370. };
  2371. state.option.inES5 = function (/* strict */) {
  2372. return !state.option.es3;
  2373. };
  2374. state.option.inES3 = function (strict) {
  2375. if (strict) {
  2376. return !state.option.moz && !state.option.esnext && state.option.es3;
  2377. }
  2378. return state.option.es3;
  2379. };
  2380. }
  2381. function quit(code, line, chr) {
  2382. var percentage = Math.floor((line / state.lines.length) * 100);
  2383. var message = messages.errors[code].desc;
  2384. throw {
  2385. name: "JSHintError",
  2386. line: line,
  2387. character: chr,
  2388. message: message + " (" + percentage + "% scanned).",
  2389. raw: message,
  2390. code: code
  2391. };
  2392. }
  2393. function isundef(scope, code, token, a) {
  2394. return JSHINT.undefs.push([scope, code, token, a]);
  2395. }
  2396. function removeIgnoredMessages() {
  2397. var ignored = state.ignoredLines;
  2398. if (_.isEmpty(ignored)) return;
  2399. JSHINT.errors = _.reject(JSHINT.errors, function (err) { return ignored[err.line] });
  2400. }
  2401. function warning(code, t, a, b, c, d) {
  2402. var ch, l, w, msg;
  2403. if (/^W\d{3}$/.test(code)) {
  2404. if (state.ignored[code])
  2405. return;
  2406. msg = messages.warnings[code];
  2407. } else if (/E\d{3}/.test(code)) {
  2408. msg = messages.errors[code];
  2409. } else if (/I\d{3}/.test(code)) {
  2410. msg = messages.info[code];
  2411. }
  2412. t = t || state.tokens.next;
  2413. if (t.id === "(end)") { // `~
  2414. t = state.tokens.curr;
  2415. }
  2416. l = t.line || 0;
  2417. ch = t.from || 0;
  2418. w = {
  2419. id: "(error)",
  2420. raw: msg.desc,
  2421. code: msg.code,
  2422. evidence: state.lines[l - 1] || "",
  2423. line: l,
  2424. character: ch,
  2425. scope: JSHINT.scope,
  2426. a: a,
  2427. b: b,
  2428. c: c,
  2429. d: d
  2430. };
  2431. w.reason = supplant(msg.desc, w);
  2432. JSHINT.errors.push(w);
  2433. removeIgnoredMessages();
  2434. if (JSHINT.errors.length >= state.option.maxerr)
  2435. quit("E043", l, ch);
  2436. return w;
  2437. }
  2438. function warningAt(m, l, ch, a, b, c, d) {
  2439. return warning(m, {
  2440. line: l,
  2441. from: ch
  2442. }, a, b, c, d);
  2443. }
  2444. function error(m, t, a, b, c, d) {
  2445. warning(m, t, a, b, c, d);
  2446. }
  2447. function errorAt(m, l, ch, a, b, c, d) {
  2448. return error(m, {
  2449. line: l,
  2450. from: ch
  2451. }, a, b, c, d);
  2452. }
  2453. function addInternalSrc(elem, src) {
  2454. var i;
  2455. i = {
  2456. id: "(internal)",
  2457. elem: elem,
  2458. value: src
  2459. };
  2460. JSHINT.internals.push(i);
  2461. return i;
  2462. }
  2463. function addlabel(name, opts) {
  2464. opts = opts || {};
  2465. var type = opts.type;
  2466. var token = opts.token;
  2467. var islet = opts.islet;
  2468. if (type === "exception") {
  2469. if (_.has(funct["(context)"], name)) {
  2470. if (funct[name] !== true && !state.option.node) {
  2471. warning("W002", state.tokens.next, name);
  2472. }
  2473. }
  2474. }
  2475. if (_.has(funct, name) && !funct["(global)"]) {
  2476. if (funct[name] === true) {
  2477. if (state.option.latedef) {
  2478. if ((state.option.latedef === true && _.contains([funct[name], type], "unction")) ||
  2479. !_.contains([funct[name], type], "unction")) {
  2480. warning("W003", state.tokens.next, name);
  2481. }
  2482. }
  2483. } else {
  2484. if ((!state.option.shadow || _.contains([ "inner", "outer" ], state.option.shadow)) &&
  2485. type !== "exception" || funct["(blockscope)"].getlabel(name)) {
  2486. warning("W004", state.tokens.next, name);
  2487. }
  2488. }
  2489. }
  2490. if (funct["(context)"] && _.has(funct["(context)"], name) && type !== "function") {
  2491. if (state.option.shadow === "outer") {
  2492. warning("W123", state.tokens.next, name);
  2493. }
  2494. }
  2495. if (islet) {
  2496. funct["(blockscope)"].current.add(name, type, state.tokens.curr);
  2497. } else {
  2498. funct["(blockscope)"].shadow(name);
  2499. funct[name] = type;
  2500. if (token) {
  2501. funct["(tokens)"][name] = token;
  2502. }
  2503. setprop(funct, name, { unused: opts.unused || false });
  2504. if (funct["(global)"]) {
  2505. global[name] = funct;
  2506. if (_.has(implied, name)) {
  2507. if (state.option.latedef) {
  2508. if ((state.option.latedef === true && _.contains([funct[name], type], "unction")) ||
  2509. !_.contains([funct[name], type], "unction")) {
  2510. warning("W003", state.tokens.next, name);
  2511. }
  2512. }
  2513. delete implied[name];
  2514. }
  2515. } else {
  2516. scope[name] = funct;
  2517. }
  2518. }
  2519. }
  2520. function doOption() {
  2521. var nt = state.tokens.next;
  2522. var body = nt.body.match(/(-\s+)?[^\s,:]+(?:\s*:\s*(-\s+)?[^\s,]+)?/g);
  2523. var predef = {};
  2524. if (nt.type === "globals") {
  2525. body.forEach(function (g) {
  2526. g = g.split(":");
  2527. var key = (g[0] || "").trim();
  2528. var val = (g[1] || "").trim();
  2529. if (key.charAt(0) === "-") {
  2530. key = key.slice(1);
  2531. val = false;
  2532. JSHINT.blacklist[key] = key;
  2533. delete predefined[key];
  2534. } else {
  2535. predef[key] = (val === "true");
  2536. }
  2537. });
  2538. combine(predefined, predef);
  2539. for (var key in predef) {
  2540. if (_.has(predef, key)) {
  2541. declared[key] = nt;
  2542. }
  2543. }
  2544. }
  2545. if (nt.type === "exported") {
  2546. body.forEach(function (e) {
  2547. exported[e] = true;
  2548. });
  2549. }
  2550. if (nt.type === "members") {
  2551. membersOnly = membersOnly || {};
  2552. body.forEach(function (m) {
  2553. var ch1 = m.charAt(0);
  2554. var ch2 = m.charAt(m.length - 1);
  2555. if (ch1 === ch2 && (ch1 === "\"" || ch1 === "'")) {
  2556. m = m
  2557. .substr(1, m.length - 2)
  2558. .replace("\\\"", "\"");
  2559. }
  2560. membersOnly[m] = false;
  2561. });
  2562. }
  2563. var numvals = [
  2564. "maxstatements",
  2565. "maxparams",
  2566. "maxdepth",
  2567. "maxcomplexity",
  2568. "maxerr",
  2569. "maxlen",
  2570. "indent"
  2571. ];
  2572. if (nt.type === "jshint" || nt.type === "jslint") {
  2573. body.forEach(function (g) {
  2574. g = g.split(":");
  2575. var key = (g[0] || "").trim();
  2576. var val = (g[1] || "").trim();
  2577. if (!checkOption(key, nt)) {
  2578. return;
  2579. }
  2580. if (numvals.indexOf(key) >= 0) {
  2581. if (val !== "false") {
  2582. val = +val;
  2583. if (typeof val !== "number" || !isFinite(val) || val <= 0 || Math.floor(val) !== val) {
  2584. error("E032", nt, g[1].trim());
  2585. return;
  2586. }
  2587. state.option[key] = val;
  2588. } else {
  2589. state.option[key] = key === "indent" ? 4 : false;
  2590. }
  2591. return;
  2592. }
  2593. if (key === "validthis") {
  2594. if (funct["(global)"])
  2595. return void error("E009");
  2596. if (val !== "true" && val !== "false")
  2597. return void error("E002", nt);
  2598. state.option.validthis = (val === "true");
  2599. return;
  2600. }
  2601. if (key === "quotmark") {
  2602. switch (val) {
  2603. case "true":
  2604. case "false":
  2605. state.option.quotmark = (val === "true");
  2606. break;
  2607. case "double":
  2608. case "single":
  2609. state.option.quotmark = val;
  2610. break;
  2611. default:
  2612. error("E002", nt);
  2613. }
  2614. return;
  2615. }
  2616. if (key === "shadow") {
  2617. switch (val) {
  2618. case "true":
  2619. state.option.shadow = true;
  2620. break;
  2621. case "outer":
  2622. state.option.shadow = "outer";
  2623. break;
  2624. case "false":
  2625. case "inner":
  2626. state.option.shadow = "inner";
  2627. break;
  2628. default:
  2629. error("E002", nt);
  2630. }
  2631. return;
  2632. }
  2633. if (key === "unused") {
  2634. switch (val) {
  2635. case "true":
  2636. state.option.unused = true;
  2637. break;
  2638. case "false":
  2639. state.option.unused = false;
  2640. break;
  2641. case "vars":
  2642. case "strict":
  2643. state.option.unused = val;
  2644. break;
  2645. default:
  2646. error("E002", nt);
  2647. }
  2648. return;
  2649. }
  2650. if (key === "latedef") {
  2651. switch (val) {
  2652. case "true":
  2653. state.option.latedef = true;
  2654. break;
  2655. case "false":
  2656. state.option.latedef = false;
  2657. break;
  2658. case "nofunc":
  2659. state.option.latedef = "nofunc";
  2660. break;
  2661. default:
  2662. error("E002", nt);
  2663. }
  2664. return;
  2665. }
  2666. if (key === "ignore") {
  2667. switch (val) {
  2668. case "start":
  2669. state.ignoreLinterErrors = true;
  2670. break;
  2671. case "end":
  2672. state.ignoreLinterErrors = false;
  2673. break;
  2674. case "line":
  2675. state.ignoredLines[nt.line] = true;
  2676. removeIgnoredMessages();
  2677. break;
  2678. default:
  2679. error("E002", nt);
  2680. }
  2681. return;
  2682. }
  2683. var match = /^([+-])(W\d{3})$/g.exec(key);
  2684. if (match) {
  2685. state.ignored[match[2]] = (match[1] === "-");
  2686. return;
  2687. }
  2688. var tn;
  2689. if (val === "true" || val === "false") {
  2690. if (nt.type === "jslint") {
  2691. tn = renamedOptions[key] || key;
  2692. state.option[tn] = (val === "true");
  2693. if (invertedOptions[tn] !== undefined) {
  2694. state.option[tn] = !state.option[tn];
  2695. }
  2696. } else {
  2697. state.option[key] = (val === "true");
  2698. }
  2699. if (key === "newcap") {
  2700. state.option["(explicitNewcap)"] = true;
  2701. }
  2702. return;
  2703. }
  2704. error("E002", nt);
  2705. });
  2706. assume();
  2707. }
  2708. }
  2709. function peek(p) {
  2710. var i = p || 0, j = 0, t;
  2711. while (j <= i) {
  2712. t = lookahead[j];
  2713. if (!t) {
  2714. t = lookahead[j] = lex.token();
  2715. }
  2716. j += 1;
  2717. }
  2718. return t;
  2719. }
  2720. function advance(id, t) {
  2721. switch (state.tokens.curr.id) {
  2722. case "(number)":
  2723. if (state.tokens.next.id === ".") {
  2724. warning("W005", state.tokens.curr);
  2725. }
  2726. break;
  2727. case "-":
  2728. if (state.tokens.next.id === "-" || state.tokens.next.id === "--") {
  2729. warning("W006");
  2730. }
  2731. break;
  2732. case "+":
  2733. if (state.tokens.next.id === "+" || state.tokens.next.id === "++") {
  2734. warning("W007");
  2735. }
  2736. break;
  2737. }
  2738. if (state.tokens.curr.type === "(string)" || state.tokens.curr.identifier) {
  2739. anonname = state.tokens.curr.value;
  2740. }
  2741. if (id && state.tokens.next.id !== id) {
  2742. if (t) {
  2743. if (state.tokens.next.id === "(end)") {
  2744. error("E019", t, t.id);
  2745. } else {
  2746. error("E020", state.tokens.next, id, t.id, t.line, state.tokens.next.value);
  2747. }
  2748. } else if (state.tokens.next.type !== "(identifier)" || state.tokens.next.value !== id) {
  2749. warning("W116", state.tokens.next, id, state.tokens.next.value);
  2750. }
  2751. }
  2752. state.tokens.prev = state.tokens.curr;
  2753. state.tokens.curr = state.tokens.next;
  2754. for (;;) {
  2755. state.tokens.next = lookahead.shift() || lex.token();
  2756. if (!state.tokens.next) { // No more tokens left, give up
  2757. quit("E041", state.tokens.curr.line);
  2758. }
  2759. if (state.tokens.next.id === "(end)" || state.tokens.next.id === "(error)") {
  2760. return;
  2761. }
  2762. if (state.tokens.next.check) {
  2763. state.tokens.next.check();
  2764. }
  2765. if (state.tokens.next.isSpecial) {
  2766. doOption();
  2767. } else {
  2768. if (state.tokens.next.id !== "(endline)") {
  2769. break;
  2770. }
  2771. }
  2772. }
  2773. }
  2774. function isInfix(token) {
  2775. return token.infix || (!token.identifier && !!token.led);
  2776. }
  2777. function isEndOfExpr() {
  2778. var curr = state.tokens.curr;
  2779. var next = state.tokens.next;
  2780. if (next.id === ";" || next.id === "}" || next.id === ":") {
  2781. return true;
  2782. }
  2783. if (isInfix(next) === isInfix(curr) || (curr.id === "yield" && state.option.inMoz(true))) {
  2784. return curr.line !== next.line;
  2785. }
  2786. return false;
  2787. }
  2788. function expression(rbp, initial) {
  2789. var left, isArray = false, isObject = false, isLetExpr = false;
  2790. if (!initial && state.tokens.next.value === "let" && peek(0).value === "(") {
  2791. if (!state.option.inMoz(true)) {
  2792. warning("W118", state.tokens.next, "let expressions");
  2793. }
  2794. isLetExpr = true;
  2795. funct["(blockscope)"].stack();
  2796. advance("let");
  2797. advance("(");
  2798. state.syntax["let"].fud.call(state.syntax["let"].fud, false);
  2799. advance(")");
  2800. }
  2801. if (state.tokens.next.id === "(end)")
  2802. error("E006", state.tokens.curr);
  2803. var isDangerous =
  2804. state.option.asi &&
  2805. state.tokens.prev.line < state.tokens.curr.line &&
  2806. _.contains(["]", ")"], state.tokens.prev.id) &&
  2807. _.contains(["[", "("], state.tokens.curr.id);
  2808. if (isDangerous)
  2809. warning("W014", state.tokens.curr, state.tokens.curr.id);
  2810. advance();
  2811. if (initial) {
  2812. anonname = "anonymous";
  2813. funct["(verb)"] = state.tokens.curr.value;
  2814. }
  2815. if (initial === true && state.tokens.curr.fud) {
  2816. left = state.tokens.curr.fud();
  2817. } else {
  2818. if (state.tokens.curr.nud) {
  2819. left = state.tokens.curr.nud();
  2820. } else {
  2821. error("E030", state.tokens.curr, state.tokens.curr.id);
  2822. }
  2823. while (rbp < state.tokens.next.lbp && !isEndOfExpr()) {
  2824. isArray = state.tokens.curr.value === "Array";
  2825. isObject = state.tokens.curr.value === "Object";
  2826. if (left && (left.value || (left.first && left.first.value))) {
  2827. if (left.value !== "new" ||
  2828. (left.first && left.first.value && left.first.value === ".")) {
  2829. isArray = false;
  2830. if (left.value !== state.tokens.curr.value) {
  2831. isObject = false;
  2832. }
  2833. }
  2834. }
  2835. advance();
  2836. if (isArray && state.tokens.curr.id === "(" && state.tokens.next.id === ")") {
  2837. warning("W009", state.tokens.curr);
  2838. }
  2839. if (isObject && state.tokens.curr.id === "(" && state.tokens.next.id === ")") {
  2840. warning("W010", state.tokens.curr);
  2841. }
  2842. if (left && state.tokens.curr.led) {
  2843. left = state.tokens.curr.led(left);
  2844. } else {
  2845. error("E033", state.tokens.curr, state.tokens.curr.id);
  2846. }
  2847. }
  2848. }
  2849. if (isLetExpr) {
  2850. funct["(blockscope)"].unstack();
  2851. }
  2852. return left;
  2853. }
  2854. function nobreaknonadjacent(left, right) {
  2855. left = left || state.tokens.curr;
  2856. right = right || state.tokens.next;
  2857. if (!state.option.laxbreak && left.line !== right.line) {
  2858. warning("W014", right, right.value);
  2859. }
  2860. }
  2861. function nolinebreak(t) {
  2862. t = t || state.tokens.curr;
  2863. if (t.line !== state.tokens.next.line) {
  2864. warning("E022", t, t.value);
  2865. }
  2866. }
  2867. function nobreakcomma(left, right) {
  2868. if (left.line !== right.line) {
  2869. if (!state.option.laxcomma) {
  2870. if (comma.first) {
  2871. warning("I001");
  2872. comma.first = false;
  2873. }
  2874. warning("W014", left, right.value);
  2875. }
  2876. }
  2877. }
  2878. function comma(opts) {
  2879. opts = opts || {};
  2880. if (!opts.peek) {
  2881. nobreakcomma(state.tokens.curr, state.tokens.next);
  2882. advance(",");
  2883. } else {
  2884. nobreakcomma(state.tokens.prev, state.tokens.curr);
  2885. }
  2886. if (state.tokens.next.identifier && !(opts.property && state.option.inES5())) {
  2887. switch (state.tokens.next.value) {
  2888. case "break":
  2889. case "case":
  2890. case "catch":
  2891. case "continue":
  2892. case "default":
  2893. case "do":
  2894. case "else":
  2895. case "finally":
  2896. case "for":
  2897. case "if":
  2898. case "in":
  2899. case "instanceof":
  2900. case "return":
  2901. case "switch":
  2902. case "throw":
  2903. case "try":
  2904. case "var":
  2905. case "let":
  2906. case "while":
  2907. case "with":
  2908. error("E024", state.tokens.next, state.tokens.next.value);
  2909. return false;
  2910. }
  2911. }
  2912. if (state.tokens.next.type === "(punctuator)") {
  2913. switch (state.tokens.next.value) {
  2914. case "}":
  2915. case "]":
  2916. case ",":
  2917. if (opts.allowTrailing) {
  2918. return true;
  2919. }
  2920. case ")":
  2921. error("E024", state.tokens.next, state.tokens.next.value);
  2922. return false;
  2923. }
  2924. }
  2925. return true;
  2926. }
  2927. function symbol(s, p) {
  2928. var x = state.syntax[s];
  2929. if (!x || typeof x !== "object") {
  2930. state.syntax[s] = x = {
  2931. id: s,
  2932. lbp: p,
  2933. value: s
  2934. };
  2935. }
  2936. return x;
  2937. }
  2938. function delim(s) {
  2939. return symbol(s, 0);
  2940. }
  2941. function stmt(s, f) {
  2942. var x = delim(s);
  2943. x.identifier = x.reserved = true;
  2944. x.fud = f;
  2945. return x;
  2946. }
  2947. function blockstmt(s, f) {
  2948. var x = stmt(s, f);
  2949. x.block = true;
  2950. return x;
  2951. }
  2952. function reserveName(x) {
  2953. var c = x.id.charAt(0);
  2954. if ((c >= "a" && c <= "z") || (c >= "A" && c <= "Z")) {
  2955. x.identifier = x.reserved = true;
  2956. }
  2957. return x;
  2958. }
  2959. function prefix(s, f) {
  2960. var x = symbol(s, 150);
  2961. reserveName(x);
  2962. x.nud = (typeof f === "function") ? f : function () {
  2963. this.right = expression(150);
  2964. this.arity = "unary";
  2965. if (this.id === "++" || this.id === "--") {
  2966. if (state.option.plusplus) {
  2967. warning("W016", this, this.id);
  2968. } else if (this.right && (!this.right.identifier || isReserved(this.right)) &&
  2969. this.right.id !== "." && this.right.id !== "[") {
  2970. warning("W017", this);
  2971. }
  2972. }
  2973. return this;
  2974. };
  2975. return x;
  2976. }
  2977. function type(s, f) {
  2978. var x = delim(s);
  2979. x.type = s;
  2980. x.nud = f;
  2981. return x;
  2982. }
  2983. function reserve(name, func) {
  2984. var x = type(name, func);
  2985. x.identifier = true;
  2986. x.reserved = true;
  2987. return x;
  2988. }
  2989. function FutureReservedWord(name, meta) {
  2990. var x = type(name, (meta && meta.nud) || function () {
  2991. return this;
  2992. });
  2993. meta = meta || {};
  2994. meta.isFutureReservedWord = true;
  2995. x.value = name;
  2996. x.identifier = true;
  2997. x.reserved = true;
  2998. x.meta = meta;
  2999. return x;
  3000. }
  3001. function reservevar(s, v) {
  3002. return reserve(s, function () {
  3003. if (typeof v === "function") {
  3004. v(this);
  3005. }
  3006. return this;
  3007. });
  3008. }
  3009. function infix(s, f, p, w) {
  3010. var x = symbol(s, p);
  3011. reserveName(x);
  3012. x.infix = true;
  3013. x.led = function (left) {
  3014. if (!w) {
  3015. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  3016. }
  3017. if (s === "in" && left.id === "!") {
  3018. warning("W018", left, "!");
  3019. }
  3020. if (typeof f === "function") {
  3021. return f(left, this);
  3022. } else {
  3023. this.left = left;
  3024. this.right = expression(p);
  3025. return this;
  3026. }
  3027. };
  3028. return x;
  3029. }
  3030. function application(s) {
  3031. var x = symbol(s, 42);
  3032. x.led = function (left) {
  3033. if (!state.option.inESNext()) {
  3034. warning("W104", state.tokens.curr, "arrow function syntax (=>)");
  3035. }
  3036. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  3037. this.left = left;
  3038. this.right = doFunction(undefined, undefined, false, left);
  3039. return this;
  3040. };
  3041. return x;
  3042. }
  3043. function relation(s, f) {
  3044. var x = symbol(s, 100);
  3045. x.led = function (left) {
  3046. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  3047. var right = expression(100);
  3048. if (isIdentifier(left, "NaN") || isIdentifier(right, "NaN")) {
  3049. warning("W019", this);
  3050. } else if (f) {
  3051. f.apply(this, [left, right]);
  3052. }
  3053. if (!left || !right) {
  3054. quit("E041", state.tokens.curr.line);
  3055. }
  3056. if (left.id === "!") {
  3057. warning("W018", left, "!");
  3058. }
  3059. if (right.id === "!") {
  3060. warning("W018", right, "!");
  3061. }
  3062. this.left = left;
  3063. this.right = right;
  3064. return this;
  3065. };
  3066. return x;
  3067. }
  3068. function isPoorRelation(node) {
  3069. return node &&
  3070. ((node.type === "(number)" && +node.value === 0) ||
  3071. (node.type === "(string)" && node.value === "") ||
  3072. (node.type === "null" && !state.option.eqnull) ||
  3073. node.type === "true" ||
  3074. node.type === "false" ||
  3075. node.type === "undefined");
  3076. }
  3077. function isTypoTypeof(left, right) {
  3078. if (state.option.notypeof)
  3079. return false;
  3080. if (!left || !right)
  3081. return false;
  3082. var values = [
  3083. "undefined", "object", "boolean", "number",
  3084. "string", "function", "xml", "object", "unknown"
  3085. ];
  3086. if (right.type === "(identifier)" && right.value === "typeof" && left.type === "(string)")
  3087. return !_.contains(values, left.value);
  3088. return false;
  3089. }
  3090. function findNativePrototype(left) {
  3091. var natives = [
  3092. "Array", "ArrayBuffer", "Boolean", "Collator", "DataView", "Date",
  3093. "DateTimeFormat", "Error", "EvalError", "Float32Array", "Float64Array",
  3094. "Function", "Infinity", "Intl", "Int16Array", "Int32Array", "Int8Array",
  3095. "Iterator", "Number", "NumberFormat", "Object", "RangeError",
  3096. "ReferenceError", "RegExp", "StopIteration", "String", "SyntaxError",
  3097. "TypeError", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray",
  3098. "URIError"
  3099. ];
  3100. function walkPrototype(obj) {
  3101. if (typeof obj !== "object") return;
  3102. return obj.right === "prototype" ? obj : walkPrototype(obj.left);
  3103. }
  3104. function walkNative(obj) {
  3105. while (!obj.identifier && typeof obj.left === "object")
  3106. obj = obj.left;
  3107. if (obj.identifier && natives.indexOf(obj.value) >= 0)
  3108. return obj.value;
  3109. }
  3110. var prototype = walkPrototype(left);
  3111. if (prototype) return walkNative(prototype);
  3112. }
  3113. function assignop(s, f, p) {
  3114. var x = infix(s, typeof f === "function" ? f : function (left, that) {
  3115. that.left = left;
  3116. if (left) {
  3117. if (state.option.freeze) {
  3118. var nativeObject = findNativePrototype(left);
  3119. if (nativeObject)
  3120. warning("W121", left, nativeObject);
  3121. }
  3122. if (predefined[left.value] === false &&
  3123. scope[left.value]["(global)"] === true) {
  3124. warning("W020", left);
  3125. } else if (left["function"]) {
  3126. warning("W021", left, left.value);
  3127. }
  3128. if (funct[left.value] === "const") {
  3129. error("E013", left, left.value);
  3130. }
  3131. if (left.id === ".") {
  3132. if (!left.left) {
  3133. warning("E031", that);
  3134. } else if (left.left.value === "arguments" && !state.directive["use strict"]) {
  3135. warning("E031", that);
  3136. }
  3137. that.right = expression(10);
  3138. return that;
  3139. } else if (left.id === "[") {
  3140. if (state.tokens.curr.left.first) {
  3141. state.tokens.curr.left.first.forEach(function (t) {
  3142. if (t && funct[t.value] === "const") {
  3143. error("E013", t, t.value);
  3144. }
  3145. });
  3146. } else if (!left.left) {
  3147. warning("E031", that);
  3148. } else if (left.left.value === "arguments" && !state.directive["use strict"]) {
  3149. warning("E031", that);
  3150. }
  3151. that.right = expression(10);
  3152. return that;
  3153. } else if (left.identifier && !isReserved(left)) {
  3154. if (funct[left.value] === "exception") {
  3155. warning("W022", left);
  3156. }
  3157. that.right = expression(10);
  3158. return that;
  3159. }
  3160. if (left === state.syntax["function"]) {
  3161. warning("W023", state.tokens.curr);
  3162. }
  3163. }
  3164. error("E031", that);
  3165. }, p);
  3166. x.exps = true;
  3167. x.assign = true;
  3168. return x;
  3169. }
  3170. function bitwise(s, f, p) {
  3171. var x = symbol(s, p);
  3172. reserveName(x);
  3173. x.led = (typeof f === "function") ? f : function (left) {
  3174. if (state.option.bitwise) {
  3175. warning("W016", this, this.id);
  3176. }
  3177. this.left = left;
  3178. this.right = expression(p);
  3179. return this;
  3180. };
  3181. return x;
  3182. }
  3183. function bitwiseassignop(s) {
  3184. return assignop(s, function (left, that) {
  3185. if (state.option.bitwise) {
  3186. warning("W016", that, that.id);
  3187. }
  3188. if (left) {
  3189. if (left.id === "." || left.id === "[" ||
  3190. (left.identifier && !isReserved(left))) {
  3191. expression(10);
  3192. return that;
  3193. }
  3194. if (left === state.syntax["function"]) {
  3195. warning("W023", state.tokens.curr);
  3196. }
  3197. return that;
  3198. }
  3199. error("E031", that);
  3200. }, 20);
  3201. }
  3202. function suffix(s) {
  3203. var x = symbol(s, 150);
  3204. x.led = function (left) {
  3205. if (state.option.plusplus) {
  3206. warning("W016", this, this.id);
  3207. } else if ((!left.identifier || isReserved(left)) && left.id !== "." && left.id !== "[") {
  3208. warning("W017", this);
  3209. }
  3210. this.left = left;
  3211. return this;
  3212. };
  3213. return x;
  3214. }
  3215. function optionalidentifier(fnparam, prop) {
  3216. if (!state.tokens.next.identifier) {
  3217. return;
  3218. }
  3219. advance();
  3220. var curr = state.tokens.curr;
  3221. var val = state.tokens.curr.value;
  3222. if (!isReserved(curr)) {
  3223. return val;
  3224. }
  3225. if (prop) {
  3226. if (state.option.inES5()) {
  3227. return val;
  3228. }
  3229. }
  3230. if (fnparam && val === "undefined") {
  3231. return val;
  3232. }
  3233. warning("W024", state.tokens.curr, state.tokens.curr.id);
  3234. return val;
  3235. }
  3236. function identifier(fnparam, prop) {
  3237. var i = optionalidentifier(fnparam, prop);
  3238. if (i) {
  3239. return i;
  3240. }
  3241. if (state.tokens.curr.id === "function" && state.tokens.next.id === "(") {
  3242. warning("W025");
  3243. } else {
  3244. error("E030", state.tokens.next, state.tokens.next.value);
  3245. }
  3246. }
  3247. function reachable(s) {
  3248. var i = 0, t;
  3249. if (state.tokens.next.id !== ";" || noreach) {
  3250. return;
  3251. }
  3252. for (;;) {
  3253. do {
  3254. t = peek(i);
  3255. i += 1;
  3256. } while (t.id != "(end)" && t.id === "(comment)");
  3257. if (t.reach) {
  3258. return;
  3259. }
  3260. if (t.id !== "(endline)") {
  3261. if (t.id === "function") {
  3262. if (state.option.latedef === true) {
  3263. warning("W026", t);
  3264. }
  3265. break;
  3266. }
  3267. warning("W027", t, t.value, s);
  3268. break;
  3269. }
  3270. }
  3271. }
  3272. function parseFinalSemicolon() {
  3273. if (state.tokens.next.id !== ";") {
  3274. if (!state.option.asi) {
  3275. if (!state.option.lastsemic || state.tokens.next.id !== "}" ||
  3276. state.tokens.next.line !== state.tokens.curr.line) {
  3277. warningAt("W033", state.tokens.curr.line, state.tokens.curr.character);
  3278. }
  3279. }
  3280. } else {
  3281. advance(";");
  3282. }
  3283. }
  3284. function statement() {
  3285. var values;
  3286. var i = indent, r, s = scope, t = state.tokens.next;
  3287. if (t.id === ";") {
  3288. advance(";");
  3289. return;
  3290. }
  3291. var res = isReserved(t);
  3292. if (res && t.meta && t.meta.isFutureReservedWord && peek().id === ":") {
  3293. warning("W024", t, t.id);
  3294. res = false;
  3295. }
  3296. if (t.value === "module" && t.type === "(identifier)") {
  3297. if (peek().type === "(identifier)") {
  3298. if (!state.option.inESNext()) {
  3299. warning("W119", state.tokens.curr, "module");
  3300. }
  3301. advance("module");
  3302. var name = identifier();
  3303. addlabel(name, { type: "unused", token: state.tokens.curr });
  3304. advance("from");
  3305. advance("(string)");
  3306. parseFinalSemicolon();
  3307. return;
  3308. }
  3309. }
  3310. if (_.has(["[", "{"], t.value)) {
  3311. if (lookupBlockType().isDestAssign) {
  3312. if (!state.option.inESNext()) {
  3313. warning("W104", state.tokens.curr, "destructuring expression");
  3314. }
  3315. values = destructuringExpression();
  3316. values.forEach(function (tok) {
  3317. isundef(funct, "W117", tok.token, tok.id);
  3318. });
  3319. advance("=");
  3320. destructuringExpressionMatch(values, expression(10, true));
  3321. advance(";");
  3322. return;
  3323. }
  3324. }
  3325. if (t.identifier && !res && peek().id === ":") {
  3326. advance();
  3327. advance(":");
  3328. scope = Object.create(s);
  3329. addlabel(t.value, { type: "label" });
  3330. if (!state.tokens.next.labelled && state.tokens.next.value !== "{") {
  3331. warning("W028", state.tokens.next, t.value, state.tokens.next.value);
  3332. }
  3333. state.tokens.next.label = t.value;
  3334. t = state.tokens.next;
  3335. }
  3336. if (t.id === "{") {
  3337. var iscase = (funct["(verb)"] === "case" && state.tokens.curr.value === ":");
  3338. block(true, true, false, false, iscase);
  3339. return;
  3340. }
  3341. r = expression(0, true);
  3342. if (r && (!r.identifier || r.value !== "function") && (r.type !== "(punctuator)")) {
  3343. if (!state.directive["use strict"] &&
  3344. state.option.globalstrict &&
  3345. state.option.strict) {
  3346. warning("E007");
  3347. }
  3348. }
  3349. if (!t.block) {
  3350. if (!state.option.expr && (!r || !r.exps)) {
  3351. warning("W030", state.tokens.curr);
  3352. } else if (state.option.nonew && r && r.left && r.id === "(" && r.left.id === "new") {
  3353. warning("W031", t);
  3354. }
  3355. parseFinalSemicolon();
  3356. }
  3357. indent = i;
  3358. scope = s;
  3359. return r;
  3360. }
  3361. function statements(startLine) {
  3362. var a = [], p;
  3363. while (!state.tokens.next.reach && state.tokens.next.id !== "(end)") {
  3364. if (state.tokens.next.id === ";") {
  3365. p = peek();
  3366. if (!p || (p.id !== "(" && p.id !== "[")) {
  3367. warning("W032");
  3368. }
  3369. advance(";");
  3370. } else {
  3371. a.push(statement(startLine === state.tokens.next.line));
  3372. }
  3373. }
  3374. return a;
  3375. }
  3376. function directives() {
  3377. var i, p, pn;
  3378. for (;;) {
  3379. if (state.tokens.next.id === "(string)") {
  3380. p = peek(0);
  3381. if (p.id === "(endline)") {
  3382. i = 1;
  3383. do {
  3384. pn = peek(i);
  3385. i = i + 1;
  3386. } while (pn.id === "(endline)");
  3387. if (pn.id !== ";") {
  3388. if (pn.id !== "(string)" && pn.id !== "(number)" &&
  3389. pn.id !== "(regexp)" && pn.identifier !== true &&
  3390. pn.id !== "}") {
  3391. break;
  3392. }
  3393. warning("W033", state.tokens.next);
  3394. } else {
  3395. p = pn;
  3396. }
  3397. } else if (p.id === "}") {
  3398. warning("W033", p);
  3399. } else if (p.id !== ";") {
  3400. break;
  3401. }
  3402. advance();
  3403. if (state.directive[state.tokens.curr.value]) {
  3404. warning("W034", state.tokens.curr, state.tokens.curr.value);
  3405. }
  3406. if (state.tokens.curr.value === "use strict") {
  3407. if (!state.option["(explicitNewcap)"])
  3408. state.option.newcap = true;
  3409. state.option.undef = true;
  3410. }
  3411. state.directive[state.tokens.curr.value] = true;
  3412. if (p.id === ";") {
  3413. advance(";");
  3414. }
  3415. continue;
  3416. }
  3417. break;
  3418. }
  3419. }
  3420. function block(ordinary, stmt, isfunc, isfatarrow, iscase) {
  3421. var a,
  3422. b = inblock,
  3423. old_indent = indent,
  3424. m,
  3425. s = scope,
  3426. t,
  3427. line,
  3428. d;
  3429. inblock = ordinary;
  3430. if (!ordinary || !state.option.funcscope)
  3431. scope = Object.create(scope);
  3432. t = state.tokens.next;
  3433. var metrics = funct["(metrics)"];
  3434. metrics.nestedBlockDepth += 1;
  3435. metrics.verifyMaxNestedBlockDepthPerFunction();
  3436. if (state.tokens.next.id === "{") {
  3437. advance("{");
  3438. funct["(blockscope)"].stack();
  3439. line = state.tokens.curr.line;
  3440. if (state.tokens.next.id !== "}") {
  3441. indent += state.option.indent;
  3442. while (!ordinary && state.tokens.next.from > indent) {
  3443. indent += state.option.indent;
  3444. }
  3445. if (isfunc) {
  3446. m = {};
  3447. for (d in state.directive) {
  3448. if (_.has(state.directive, d)) {
  3449. m[d] = state.directive[d];
  3450. }
  3451. }
  3452. directives();
  3453. if (state.option.strict && funct["(context)"]["(global)"]) {
  3454. if (!m["use strict"] && !state.directive["use strict"]) {
  3455. warning("E007");
  3456. }
  3457. }
  3458. }
  3459. a = statements(line);
  3460. metrics.statementCount += a.length;
  3461. if (isfunc) {
  3462. state.directive = m;
  3463. }
  3464. indent -= state.option.indent;
  3465. }
  3466. advance("}", t);
  3467. funct["(blockscope)"].unstack();
  3468. indent = old_indent;
  3469. } else if (!ordinary) {
  3470. if (isfunc) {
  3471. m = {};
  3472. if (stmt && !isfatarrow && !state.option.inMoz(true)) {
  3473. error("W118", state.tokens.curr, "function closure expressions");
  3474. }
  3475. if (!stmt) {
  3476. for (d in state.directive) {
  3477. if (_.has(state.directive, d)) {
  3478. m[d] = state.directive[d];
  3479. }
  3480. }
  3481. }
  3482. expression(10);
  3483. if (state.option.strict && funct["(context)"]["(global)"]) {
  3484. if (!m["use strict"] && !state.directive["use strict"]) {
  3485. warning("E007");
  3486. }
  3487. }
  3488. } else {
  3489. error("E021", state.tokens.next, "{", state.tokens.next.value);
  3490. }
  3491. } else {
  3492. funct["(nolet)"] = true;
  3493. if (!stmt || state.option.curly) {
  3494. warning("W116", state.tokens.next, "{", state.tokens.next.value);
  3495. }
  3496. noreach = true;
  3497. indent += state.option.indent;
  3498. a = [statement()];
  3499. indent -= state.option.indent;
  3500. noreach = false;
  3501. delete funct["(nolet)"];
  3502. }
  3503. switch (funct["(verb)"]) {
  3504. case "break":
  3505. case "continue":
  3506. case "return":
  3507. case "throw":
  3508. if (iscase) {
  3509. break;
  3510. }
  3511. default:
  3512. funct["(verb)"] = null;
  3513. }
  3514. if (!ordinary || !state.option.funcscope) scope = s;
  3515. inblock = b;
  3516. if (ordinary && state.option.noempty && (!a || a.length === 0)) {
  3517. warning("W035");
  3518. }
  3519. metrics.nestedBlockDepth -= 1;
  3520. return a;
  3521. }
  3522. function countMember(m) {
  3523. if (membersOnly && typeof membersOnly[m] !== "boolean") {
  3524. warning("W036", state.tokens.curr, m);
  3525. }
  3526. if (typeof member[m] === "number") {
  3527. member[m] += 1;
  3528. } else {
  3529. member[m] = 1;
  3530. }
  3531. }
  3532. function note_implied(tkn) {
  3533. var name = tkn.value;
  3534. var desc = Object.getOwnPropertyDescriptor(implied, name);
  3535. if (!desc)
  3536. implied[name] = [tkn.line];
  3537. else
  3538. desc.value.push(tkn.line);
  3539. }
  3540. type("(number)", function () {
  3541. return this;
  3542. });
  3543. type("(string)", function () {
  3544. return this;
  3545. });
  3546. type("(template)", function () {
  3547. return this;
  3548. });
  3549. state.syntax["(identifier)"] = {
  3550. type: "(identifier)",
  3551. lbp: 0,
  3552. identifier: true,
  3553. nud: function () {
  3554. var v = this.value;
  3555. var s = scope[v];
  3556. var f;
  3557. var block;
  3558. if (typeof s === "function") {
  3559. s = undefined;
  3560. } else if (!funct["(blockscope)"].current.has(v) && typeof s === "boolean") {
  3561. f = funct;
  3562. funct = functions[0];
  3563. addlabel(v, { type: "var" });
  3564. s = funct;
  3565. funct = f;
  3566. }
  3567. block = funct["(blockscope)"].getlabel(v);
  3568. if (funct === s || block) {
  3569. switch (block ? block[v]["(type)"] : funct[v]) {
  3570. case "unused":
  3571. if (block) block[v]["(type)"] = "var";
  3572. else funct[v] = "var";
  3573. break;
  3574. case "unction":
  3575. if (block) block[v]["(type)"] = "function";
  3576. else funct[v] = "function";
  3577. this["function"] = true;
  3578. break;
  3579. case "const":
  3580. setprop(funct, v, { unused: false });
  3581. break;
  3582. case "function":
  3583. this["function"] = true;
  3584. break;
  3585. case "label":
  3586. warning("W037", state.tokens.curr, v);
  3587. break;
  3588. }
  3589. } else if (funct["(global)"]) {
  3590. if (typeof predefined[v] !== "boolean") {
  3591. if (!(anonname === "typeof" || anonname === "delete") ||
  3592. (state.tokens.next && (state.tokens.next.value === "." ||
  3593. state.tokens.next.value === "["))) {
  3594. if (!funct["(comparray)"].check(v)) {
  3595. isundef(funct, "W117", state.tokens.curr, v);
  3596. }
  3597. }
  3598. }
  3599. note_implied(state.tokens.curr);
  3600. } else {
  3601. switch (funct[v]) {
  3602. case "closure":
  3603. case "function":
  3604. case "var":
  3605. case "unused":
  3606. warning("W038", state.tokens.curr, v);
  3607. break;
  3608. case "label":
  3609. warning("W037", state.tokens.curr, v);
  3610. break;
  3611. case "outer":
  3612. case "global":
  3613. break;
  3614. default:
  3615. if (s === true) {
  3616. funct[v] = true;
  3617. } else if (s === null) {
  3618. warning("W039", state.tokens.curr, v);
  3619. note_implied(state.tokens.curr);
  3620. } else if (typeof s !== "object") {
  3621. if (!(anonname === "typeof" || anonname === "delete") ||
  3622. (state.tokens.next &&
  3623. (state.tokens.next.value === "." || state.tokens.next.value === "["))) {
  3624. isundef(funct, "W117", state.tokens.curr, v);
  3625. }
  3626. funct[v] = true;
  3627. note_implied(state.tokens.curr);
  3628. } else {
  3629. switch (s[v]) {
  3630. case "function":
  3631. case "unction":
  3632. this["function"] = true;
  3633. s[v] = "closure";
  3634. funct[v] = s["(global)"] ? "global" : "outer";
  3635. break;
  3636. case "var":
  3637. case "unused":
  3638. s[v] = "closure";
  3639. funct[v] = s["(global)"] ? "global" : "outer";
  3640. break;
  3641. case "const":
  3642. setprop(s, v, { unused: false });
  3643. break;
  3644. case "closure":
  3645. funct[v] = s["(global)"] ? "global" : "outer";
  3646. break;
  3647. case "label":
  3648. warning("W037", state.tokens.curr, v);
  3649. }
  3650. }
  3651. }
  3652. }
  3653. return this;
  3654. },
  3655. led: function () {
  3656. error("E033", state.tokens.next, state.tokens.next.value);
  3657. }
  3658. };
  3659. type("(regexp)", function () {
  3660. return this;
  3661. });
  3662. delim("(endline)");
  3663. delim("(begin)");
  3664. delim("(end)").reach = true;
  3665. delim("(error)").reach = true;
  3666. delim("}").reach = true;
  3667. delim(")");
  3668. delim("]");
  3669. delim("\"").reach = true;
  3670. delim("'").reach = true;
  3671. delim(";");
  3672. delim(":").reach = true;
  3673. delim("#");
  3674. reserve("else");
  3675. reserve("case").reach = true;
  3676. reserve("catch");
  3677. reserve("default").reach = true;
  3678. reserve("finally");
  3679. reservevar("arguments", function (x) {
  3680. if (state.directive["use strict"] && funct["(global)"]) {
  3681. warning("E008", x);
  3682. }
  3683. });
  3684. reservevar("eval");
  3685. reservevar("false");
  3686. reservevar("Infinity");
  3687. reservevar("null");
  3688. reservevar("this", function (x) {
  3689. if (state.directive["use strict"] && !state.option.validthis && ((funct["(statement)"] &&
  3690. funct["(name)"].charAt(0) > "Z") || funct["(global)"])) {
  3691. warning("W040", x);
  3692. }
  3693. });
  3694. reservevar("true");
  3695. reservevar("undefined");
  3696. assignop("=", "assign", 20);
  3697. assignop("+=", "assignadd", 20);
  3698. assignop("-=", "assignsub", 20);
  3699. assignop("*=", "assignmult", 20);
  3700. assignop("/=", "assigndiv", 20).nud = function () {
  3701. error("E014");
  3702. };
  3703. assignop("%=", "assignmod", 20);
  3704. bitwiseassignop("&=", "assignbitand", 20);
  3705. bitwiseassignop("|=", "assignbitor", 20);
  3706. bitwiseassignop("^=", "assignbitxor", 20);
  3707. bitwiseassignop("<<=", "assignshiftleft", 20);
  3708. bitwiseassignop(">>=", "assignshiftright", 20);
  3709. bitwiseassignop(">>>=", "assignshiftrightunsigned", 20);
  3710. infix(",", function (left, that) {
  3711. var expr;
  3712. that.exprs = [left];
  3713. if (!comma({peek: true})) {
  3714. return that;
  3715. }
  3716. while (true) {
  3717. if (!(expr = expression(10))) {
  3718. break;
  3719. }
  3720. that.exprs.push(expr);
  3721. if (state.tokens.next.value !== "," || !comma()) {
  3722. break;
  3723. }
  3724. }
  3725. return that;
  3726. }, 10, true);
  3727. infix("?", function (left, that) {
  3728. increaseComplexityCount();
  3729. that.left = left;
  3730. that.right = expression(10);
  3731. advance(":");
  3732. that["else"] = expression(10);
  3733. return that;
  3734. }, 30);
  3735. var orPrecendence = 40;
  3736. infix("||", function (left, that) {
  3737. increaseComplexityCount();
  3738. that.left = left;
  3739. that.right = expression(orPrecendence);
  3740. return that;
  3741. }, orPrecendence);
  3742. infix("&&", "and", 50);
  3743. bitwise("|", "bitor", 70);
  3744. bitwise("^", "bitxor", 80);
  3745. bitwise("&", "bitand", 90);
  3746. relation("==", function (left, right) {
  3747. var eqnull = state.option.eqnull && (left.value === "null" || right.value === "null");
  3748. switch (true) {
  3749. case !eqnull && state.option.eqeqeq:
  3750. this.from = this.character;
  3751. warning("W116", this, "===", "==");
  3752. break;
  3753. case isPoorRelation(left):
  3754. warning("W041", this, "===", left.value);
  3755. break;
  3756. case isPoorRelation(right):
  3757. warning("W041", this, "===", right.value);
  3758. break;
  3759. case isTypoTypeof(right, left):
  3760. warning("W122", this, right.value);
  3761. break;
  3762. case isTypoTypeof(left, right):
  3763. warning("W122", this, left.value);
  3764. break;
  3765. }
  3766. return this;
  3767. });
  3768. relation("===", function (left, right) {
  3769. if (isTypoTypeof(right, left)) {
  3770. warning("W122", this, right.value);
  3771. } else if (isTypoTypeof(left, right)) {
  3772. warning("W122", this, left.value);
  3773. }
  3774. return this;
  3775. });
  3776. relation("!=", function (left, right) {
  3777. var eqnull = state.option.eqnull &&
  3778. (left.value === "null" || right.value === "null");
  3779. if (!eqnull && state.option.eqeqeq) {
  3780. this.from = this.character;
  3781. warning("W116", this, "!==", "!=");
  3782. } else if (isPoorRelation(left)) {
  3783. warning("W041", this, "!==", left.value);
  3784. } else if (isPoorRelation(right)) {
  3785. warning("W041", this, "!==", right.value);
  3786. } else if (isTypoTypeof(right, left)) {
  3787. warning("W122", this, right.value);
  3788. } else if (isTypoTypeof(left, right)) {
  3789. warning("W122", this, left.value);
  3790. }
  3791. return this;
  3792. });
  3793. relation("!==", function (left, right) {
  3794. if (isTypoTypeof(right, left)) {
  3795. warning("W122", this, right.value);
  3796. } else if (isTypoTypeof(left, right)) {
  3797. warning("W122", this, left.value);
  3798. }
  3799. return this;
  3800. });
  3801. relation("<");
  3802. relation(">");
  3803. relation("<=");
  3804. relation(">=");
  3805. bitwise("<<", "shiftleft", 120);
  3806. bitwise(">>", "shiftright", 120);
  3807. bitwise(">>>", "shiftrightunsigned", 120);
  3808. infix("in", "in", 120);
  3809. infix("instanceof", "instanceof", 120);
  3810. infix("+", function (left, that) {
  3811. var right = expression(130);
  3812. if (left && right && left.id === "(string)" && right.id === "(string)") {
  3813. left.value += right.value;
  3814. left.character = right.character;
  3815. if (!state.option.scripturl && reg.javascriptURL.test(left.value)) {
  3816. warning("W050", left);
  3817. }
  3818. return left;
  3819. }
  3820. that.left = left;
  3821. that.right = right;
  3822. return that;
  3823. }, 130);
  3824. prefix("+", "num");
  3825. prefix("+++", function () {
  3826. warning("W007");
  3827. this.right = expression(150);
  3828. this.arity = "unary";
  3829. return this;
  3830. });
  3831. infix("+++", function (left) {
  3832. warning("W007");
  3833. this.left = left;
  3834. this.right = expression(130);
  3835. return this;
  3836. }, 130);
  3837. infix("-", "sub", 130);
  3838. prefix("-", "neg");
  3839. prefix("---", function () {
  3840. warning("W006");
  3841. this.right = expression(150);
  3842. this.arity = "unary";
  3843. return this;
  3844. });
  3845. infix("---", function (left) {
  3846. warning("W006");
  3847. this.left = left;
  3848. this.right = expression(130);
  3849. return this;
  3850. }, 130);
  3851. infix("*", "mult", 140);
  3852. infix("/", "div", 140);
  3853. infix("%", "mod", 140);
  3854. suffix("++", "postinc");
  3855. prefix("++", "preinc");
  3856. state.syntax["++"].exps = true;
  3857. suffix("--", "postdec");
  3858. prefix("--", "predec");
  3859. state.syntax["--"].exps = true;
  3860. prefix("delete", function () {
  3861. var p = expression(10);
  3862. if (!p || (p.id !== "." && p.id !== "[")) {
  3863. warning("W051");
  3864. }
  3865. this.first = p;
  3866. return this;
  3867. }).exps = true;
  3868. prefix("~", function () {
  3869. if (state.option.bitwise) {
  3870. warning("W052", this, "~");
  3871. }
  3872. expression(150);
  3873. return this;
  3874. });
  3875. prefix("...", function () {
  3876. if (!state.option.inESNext()) {
  3877. warning("W104", this, "spread/rest operator");
  3878. }
  3879. if (!state.tokens.next.identifier) {
  3880. error("E030", state.tokens.next, state.tokens.next.value);
  3881. }
  3882. expression(150);
  3883. return this;
  3884. });
  3885. prefix("!", function () {
  3886. this.right = expression(150);
  3887. this.arity = "unary";
  3888. if (!this.right) { // '!' followed by nothing? Give up.
  3889. quit("E041", this.line || 0);
  3890. }
  3891. if (bang[this.right.id] === true) {
  3892. warning("W018", this, "!");
  3893. }
  3894. return this;
  3895. });
  3896. prefix("typeof", "typeof");
  3897. prefix("new", function () {
  3898. var c = expression(155), i;
  3899. if (c && c.id !== "function") {
  3900. if (c.identifier) {
  3901. c["new"] = true;
  3902. switch (c.value) {
  3903. case "Number":
  3904. case "String":
  3905. case "Boolean":
  3906. case "Math":
  3907. case "JSON":
  3908. warning("W053", state.tokens.prev, c.value);
  3909. break;
  3910. case "Function":
  3911. if (!state.option.evil) {
  3912. warning("W054");
  3913. }
  3914. break;
  3915. case "Date":
  3916. case "RegExp":
  3917. case "this":
  3918. break;
  3919. default:
  3920. if (c.id !== "function") {
  3921. i = c.value.substr(0, 1);
  3922. if (state.option.newcap && (i < "A" || i > "Z") && !_.has(global, c.value)) {
  3923. warning("W055", state.tokens.curr);
  3924. }
  3925. }
  3926. }
  3927. } else {
  3928. if (c.id !== "." && c.id !== "[" && c.id !== "(") {
  3929. warning("W056", state.tokens.curr);
  3930. }
  3931. }
  3932. } else {
  3933. if (!state.option.supernew)
  3934. warning("W057", this);
  3935. }
  3936. if (state.tokens.next.id !== "(" && !state.option.supernew) {
  3937. warning("W058", state.tokens.curr, state.tokens.curr.value);
  3938. }
  3939. this.first = c;
  3940. return this;
  3941. });
  3942. state.syntax["new"].exps = true;
  3943. prefix("void").exps = true;
  3944. infix(".", function (left, that) {
  3945. var m = identifier(false, true);
  3946. if (typeof m === "string") {
  3947. countMember(m);
  3948. }
  3949. that.left = left;
  3950. that.right = m;
  3951. if (m && m === "hasOwnProperty" && state.tokens.next.value === "=") {
  3952. warning("W001");
  3953. }
  3954. if (left && left.value === "arguments" && (m === "callee" || m === "caller")) {
  3955. if (state.option.noarg)
  3956. warning("W059", left, m);
  3957. else if (state.directive["use strict"])
  3958. error("E008");
  3959. } else if (!state.option.evil && left && left.value === "document" &&
  3960. (m === "write" || m === "writeln")) {
  3961. warning("W060", left);
  3962. }
  3963. if (!state.option.evil && (m === "eval" || m === "execScript")) {
  3964. warning("W061");
  3965. }
  3966. return that;
  3967. }, 160, true);
  3968. infix("(", function (left, that) {
  3969. if (state.option.immed && left && !left.immed && left.id === "function") {
  3970. warning("W062");
  3971. }
  3972. var n = 0;
  3973. var p = [];
  3974. if (left) {
  3975. if (left.type === "(identifier)") {
  3976. if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) {
  3977. if ("Number String Boolean Date Object Error".indexOf(left.value) === -1) {
  3978. if (left.value === "Math") {
  3979. warning("W063", left);
  3980. } else if (state.option.newcap) {
  3981. warning("W064", left);
  3982. }
  3983. }
  3984. }
  3985. }
  3986. }
  3987. if (state.tokens.next.id !== ")") {
  3988. for (;;) {
  3989. p[p.length] = expression(10);
  3990. n += 1;
  3991. if (state.tokens.next.id !== ",") {
  3992. break;
  3993. }
  3994. comma();
  3995. }
  3996. }
  3997. advance(")");
  3998. if (typeof left === "object") {
  3999. if (state.option.inES3() && left.value === "parseInt" && n === 1) {
  4000. warning("W065", state.tokens.curr);
  4001. }
  4002. if (!state.option.evil) {
  4003. if (left.value === "eval" || left.value === "Function" ||
  4004. left.value === "execScript") {
  4005. warning("W061", left);
  4006. if (p[0] && [0].id === "(string)") {
  4007. addInternalSrc(left, p[0].value);
  4008. }
  4009. } else if (p[0] && p[0].id === "(string)" &&
  4010. (left.value === "setTimeout" ||
  4011. left.value === "setInterval")) {
  4012. warning("W066", left);
  4013. addInternalSrc(left, p[0].value);
  4014. } else if (p[0] && p[0].id === "(string)" &&
  4015. left.value === "." &&
  4016. left.left.value === "window" &&
  4017. (left.right === "setTimeout" ||
  4018. left.right === "setInterval")) {
  4019. warning("W066", left);
  4020. addInternalSrc(left, p[0].value);
  4021. }
  4022. }
  4023. if (!left.identifier && left.id !== "." && left.id !== "[" &&
  4024. left.id !== "(" && left.id !== "&&" && left.id !== "||" &&
  4025. left.id !== "?") {
  4026. warning("W067", left);
  4027. }
  4028. }
  4029. that.left = left;
  4030. return that;
  4031. }, 155, true).exps = true;
  4032. prefix("(", function () {
  4033. var bracket, brackets = [];
  4034. var pn, pn1, i = 0;
  4035. var ret;
  4036. var parens = 1;
  4037. do {
  4038. pn = peek(i);
  4039. if (pn.value === "(") {
  4040. parens += 1;
  4041. } else if (pn.value === ")") {
  4042. parens -= 1;
  4043. }
  4044. i += 1;
  4045. pn1 = peek(i);
  4046. } while (!(parens === 0 && pn.value === ")") &&
  4047. pn1.value !== "=>" && pn1.value !== ";" && pn1.type !== "(end)");
  4048. if (state.tokens.next.id === "function") {
  4049. state.tokens.next.immed = true;
  4050. }
  4051. var exprs = [];
  4052. if (state.tokens.next.id !== ")") {
  4053. for (;;) {
  4054. if (pn1.value === "=>" && _.contains(["{", "["], state.tokens.next.value)) {
  4055. bracket = state.tokens.next;
  4056. bracket.left = destructuringExpression();
  4057. brackets.push(bracket);
  4058. for (var t in bracket.left) {
  4059. exprs.push(bracket.left[t].token);
  4060. }
  4061. } else {
  4062. exprs.push(expression(10));
  4063. }
  4064. if (state.tokens.next.id !== ",") {
  4065. break;
  4066. }
  4067. comma();
  4068. }
  4069. }
  4070. advance(")", this);
  4071. if (state.option.immed && exprs[0] && exprs[0].id === "function") {
  4072. if (state.tokens.next.id !== "(" &&
  4073. (state.tokens.next.id !== "." || (peek().value !== "call" && peek().value !== "apply"))) {
  4074. warning("W068", this);
  4075. }
  4076. }
  4077. if (state.tokens.next.value === "=>") {
  4078. return exprs;
  4079. }
  4080. if (!exprs.length) {
  4081. return;
  4082. }
  4083. if (exprs.length > 1) {
  4084. ret = Object.create(state.syntax[","]);
  4085. ret.exprs = exprs;
  4086. } else {
  4087. ret = exprs[0];
  4088. }
  4089. if (ret) {
  4090. ret.paren = true;
  4091. }
  4092. return ret;
  4093. });
  4094. application("=>");
  4095. infix("[", function (left, that) {
  4096. var e = expression(10), s;
  4097. if (e && e.type === "(string)") {
  4098. if (!state.option.evil && (e.value === "eval" || e.value === "execScript")) {
  4099. warning("W061", that);
  4100. }
  4101. countMember(e.value);
  4102. if (!state.option.sub && reg.identifier.test(e.value)) {
  4103. s = state.syntax[e.value];
  4104. if (!s || !isReserved(s)) {
  4105. warning("W069", state.tokens.prev, e.value);
  4106. }
  4107. }
  4108. }
  4109. advance("]", that);
  4110. if (e && e.value === "hasOwnProperty" && state.tokens.next.value === "=") {
  4111. warning("W001");
  4112. }
  4113. that.left = left;
  4114. that.right = e;
  4115. return that;
  4116. }, 160, true);
  4117. function comprehensiveArrayExpression() {
  4118. var res = {};
  4119. res.exps = true;
  4120. funct["(comparray)"].stack();
  4121. var reversed = false;
  4122. if (state.tokens.next.value !== "for") {
  4123. reversed = true;
  4124. if (!state.option.inMoz(true)) {
  4125. warning("W116", state.tokens.next, "for", state.tokens.next.value);
  4126. }
  4127. funct["(comparray)"].setState("use");
  4128. res.right = expression(10);
  4129. }
  4130. advance("for");
  4131. if (state.tokens.next.value === "each") {
  4132. advance("each");
  4133. if (!state.option.inMoz(true)) {
  4134. warning("W118", state.tokens.curr, "for each");
  4135. }
  4136. }
  4137. advance("(");
  4138. funct["(comparray)"].setState("define");
  4139. res.left = expression(130);
  4140. if (_.contains(["in", "of"], state.tokens.next.value)) {
  4141. advance();
  4142. } else {
  4143. error("E045", state.tokens.curr);
  4144. }
  4145. funct["(comparray)"].setState("generate");
  4146. expression(10);
  4147. advance(")");
  4148. if (state.tokens.next.value === "if") {
  4149. advance("if");
  4150. advance("(");
  4151. funct["(comparray)"].setState("filter");
  4152. res.filter = expression(10);
  4153. advance(")");
  4154. }
  4155. if (!reversed) {
  4156. funct["(comparray)"].setState("use");
  4157. res.right = expression(10);
  4158. }
  4159. advance("]");
  4160. funct["(comparray)"].unstack();
  4161. return res;
  4162. }
  4163. prefix("[", function () {
  4164. var blocktype = lookupBlockType(true);
  4165. if (blocktype.isCompArray) {
  4166. if (!state.option.inESNext()) {
  4167. warning("W119", state.tokens.curr, "array comprehension");
  4168. }
  4169. return comprehensiveArrayExpression();
  4170. } else if (blocktype.isDestAssign && !state.option.inESNext()) {
  4171. warning("W104", state.tokens.curr, "destructuring assignment");
  4172. }
  4173. var b = state.tokens.curr.line !== state.tokens.next.line;
  4174. this.first = [];
  4175. if (b) {
  4176. indent += state.option.indent;
  4177. if (state.tokens.next.from === indent + state.option.indent) {
  4178. indent += state.option.indent;
  4179. }
  4180. }
  4181. while (state.tokens.next.id !== "(end)") {
  4182. while (state.tokens.next.id === ",") {
  4183. if (!state.option.inES5())
  4184. warning("W070");
  4185. advance(",");
  4186. }
  4187. if (state.tokens.next.id === "]") {
  4188. break;
  4189. }
  4190. this.first.push(expression(10));
  4191. if (state.tokens.next.id === ",") {
  4192. comma({ allowTrailing: true });
  4193. if (state.tokens.next.id === "]" && !state.option.inES5(true)) {
  4194. warning("W070", state.tokens.curr);
  4195. break;
  4196. }
  4197. } else {
  4198. break;
  4199. }
  4200. }
  4201. if (b) {
  4202. indent -= state.option.indent;
  4203. }
  4204. advance("]", this);
  4205. return this;
  4206. }, 160);
  4207. function property_name() {
  4208. var id = optionalidentifier(false, true);
  4209. if (!id) {
  4210. if (state.tokens.next.id === "(string)") {
  4211. id = state.tokens.next.value;
  4212. advance();
  4213. } else if (state.tokens.next.id === "(number)") {
  4214. id = state.tokens.next.value.toString();
  4215. advance();
  4216. }
  4217. }
  4218. if (id === "hasOwnProperty") {
  4219. warning("W001");
  4220. }
  4221. return id;
  4222. }
  4223. function functionparams(parsed) {
  4224. var curr, next;
  4225. var params = [];
  4226. var ident;
  4227. var tokens = [];
  4228. var t;
  4229. var pastDefault = false;
  4230. if (parsed) {
  4231. if (Array.isArray(parsed)) {
  4232. for (var i in parsed) {
  4233. curr = parsed[i];
  4234. if (curr.value === "...") {
  4235. if (!state.option.inESNext()) {
  4236. warning("W104", curr, "spread/rest operator");
  4237. }
  4238. continue;
  4239. } else if (curr.value !== ",") {
  4240. params.push(curr.value);
  4241. addlabel(curr.value, { type: "unused", token: curr });
  4242. }
  4243. }
  4244. return params;
  4245. } else {
  4246. if (parsed.identifier === true) {
  4247. addlabel(parsed.value, { type: "unused", token: parsed });
  4248. return [parsed];
  4249. }
  4250. }
  4251. }
  4252. next = state.tokens.next;
  4253. advance("(");
  4254. if (state.tokens.next.id === ")") {
  4255. advance(")");
  4256. return;
  4257. }
  4258. for (;;) {
  4259. if (_.contains(["{", "["], state.tokens.next.id)) {
  4260. tokens = destructuringExpression();
  4261. for (t in tokens) {
  4262. t = tokens[t];
  4263. if (t.id) {
  4264. params.push(t.id);
  4265. addlabel(t.id, { type: "unused", token: t.token });
  4266. }
  4267. }
  4268. } else if (state.tokens.next.value === "...") {
  4269. if (!state.option.inESNext()) {
  4270. warning("W104", state.tokens.next, "spread/rest operator");
  4271. }
  4272. advance("...");
  4273. ident = identifier(true);
  4274. params.push(ident);
  4275. addlabel(ident, { type: "unused", token: state.tokens.curr });
  4276. } else {
  4277. ident = identifier(true);
  4278. params.push(ident);
  4279. addlabel(ident, { type: "unused", token: state.tokens.curr });
  4280. }
  4281. if (pastDefault) {
  4282. if (state.tokens.next.id !== "=") {
  4283. error("E051", state.tokens.current);
  4284. }
  4285. }
  4286. if (state.tokens.next.id === "=") {
  4287. if (!state.option.inESNext()) {
  4288. warning("W119", state.tokens.next, "default parameters");
  4289. }
  4290. advance("=");
  4291. pastDefault = true;
  4292. expression(10);
  4293. }
  4294. if (state.tokens.next.id === ",") {
  4295. comma();
  4296. } else {
  4297. advance(")", next);
  4298. return params;
  4299. }
  4300. }
  4301. }
  4302. function setprop(funct, name, values) {
  4303. if (!funct["(properties)"][name]) {
  4304. funct["(properties)"][name] = { unused: false };
  4305. }
  4306. _.extend(funct["(properties)"][name], values);
  4307. }
  4308. function getprop(funct, name, prop) {
  4309. if (!funct["(properties)"][name])
  4310. return null;
  4311. return funct["(properties)"][name][prop] || null;
  4312. }
  4313. function functor(name, token, scope, overwrites) {
  4314. var funct = {
  4315. "(name)" : name,
  4316. "(breakage)" : 0,
  4317. "(loopage)" : 0,
  4318. "(scope)" : scope,
  4319. "(tokens)" : {},
  4320. "(properties)": {},
  4321. "(catch)" : false,
  4322. "(global)" : false,
  4323. "(line)" : null,
  4324. "(character)" : null,
  4325. "(metrics)" : null,
  4326. "(statement)" : null,
  4327. "(context)" : null,
  4328. "(blockscope)": null,
  4329. "(comparray)" : null,
  4330. "(generator)" : null,
  4331. "(params)" : null
  4332. };
  4333. if (token) {
  4334. _.extend(funct, {
  4335. "(line)" : token.line,
  4336. "(character)": token.character,
  4337. "(metrics)" : createMetrics(token)
  4338. });
  4339. }
  4340. _.extend(funct, overwrites);
  4341. if (funct["(context)"]) {
  4342. funct["(blockscope)"] = funct["(context)"]["(blockscope)"];
  4343. funct["(comparray)"] = funct["(context)"]["(comparray)"];
  4344. }
  4345. return funct;
  4346. }
  4347. function doFunction(name, statement, generator, fatarrowparams) {
  4348. var f;
  4349. var oldOption = state.option;
  4350. var oldIgnored = state.ignored;
  4351. var oldScope = scope;
  4352. state.option = Object.create(state.option);
  4353. state.ignored = Object.create(state.ignored);
  4354. scope = Object.create(scope);
  4355. funct = functor(name || "\"" + anonname + "\"", state.tokens.next, scope, {
  4356. "(statement)": statement,
  4357. "(context)": funct,
  4358. "(generator)": generator ? true : null
  4359. });
  4360. f = funct;
  4361. state.tokens.curr.funct = funct;
  4362. functions.push(funct);
  4363. if (name) {
  4364. addlabel(name, { type: "function" });
  4365. }
  4366. funct["(params)"] = functionparams(fatarrowparams);
  4367. funct["(metrics)"].verifyMaxParametersPerFunction(funct["(params)"]);
  4368. JSHINT.undefs = _.filter(JSHINT.undefs, function (item) {
  4369. return !_.contains(_.union(fatarrowparams), item[2]);
  4370. });
  4371. block(false, true, true, fatarrowparams ? true : false);
  4372. if (!state.option.noyield && generator && funct["(generator)"] !== "yielded") {
  4373. warning("W124", state.tokens.curr);
  4374. }
  4375. funct["(metrics)"].verifyMaxStatementsPerFunction();
  4376. funct["(metrics)"].verifyMaxComplexityPerFunction();
  4377. funct["(unusedOption)"] = state.option.unused;
  4378. scope = oldScope;
  4379. state.option = oldOption;
  4380. state.ignored = oldIgnored;
  4381. funct["(last)"] = state.tokens.curr.line;
  4382. funct["(lastcharacter)"] = state.tokens.curr.character;
  4383. _.map(Object.keys(funct), function (key) {
  4384. if (key[0] === "(") return;
  4385. funct["(blockscope)"].unshadow(key);
  4386. });
  4387. funct = funct["(context)"];
  4388. return f;
  4389. }
  4390. function createMetrics(functionStartToken) {
  4391. return {
  4392. statementCount: 0,
  4393. nestedBlockDepth: -1,
  4394. ComplexityCount: 1,
  4395. verifyMaxStatementsPerFunction: function () {
  4396. if (state.option.maxstatements &&
  4397. this.statementCount > state.option.maxstatements) {
  4398. warning("W071", functionStartToken, this.statementCount);
  4399. }
  4400. },
  4401. verifyMaxParametersPerFunction: function (params) {
  4402. params = params || [];
  4403. if (state.option.maxparams && params.length > state.option.maxparams) {
  4404. warning("W072", functionStartToken, params.length);
  4405. }
  4406. },
  4407. verifyMaxNestedBlockDepthPerFunction: function () {
  4408. if (state.option.maxdepth &&
  4409. this.nestedBlockDepth > 0 &&
  4410. this.nestedBlockDepth === state.option.maxdepth + 1) {
  4411. warning("W073", null, this.nestedBlockDepth);
  4412. }
  4413. },
  4414. verifyMaxComplexityPerFunction: function () {
  4415. var max = state.option.maxcomplexity;
  4416. var cc = this.ComplexityCount;
  4417. if (max && cc > max) {
  4418. warning("W074", functionStartToken, cc);
  4419. }
  4420. }
  4421. };
  4422. }
  4423. function increaseComplexityCount() {
  4424. funct["(metrics)"].ComplexityCount += 1;
  4425. }
  4426. function checkCondAssignment(expr) {
  4427. var id, paren;
  4428. if (expr) {
  4429. id = expr.id;
  4430. paren = expr.paren;
  4431. if (id === "," && (expr = expr.exprs[expr.exprs.length - 1])) {
  4432. id = expr.id;
  4433. paren = paren || expr.paren;
  4434. }
  4435. }
  4436. switch (id) {
  4437. case "=":
  4438. case "+=":
  4439. case "-=":
  4440. case "*=":
  4441. case "%=":
  4442. case "&=":
  4443. case "|=":
  4444. case "^=":
  4445. case "/=":
  4446. if (!paren && !state.option.boss) {
  4447. warning("W084");
  4448. }
  4449. }
  4450. }
  4451. (function (x) {
  4452. x.nud = function (isclassdef) {
  4453. var b, f, i, p, t, g;
  4454. var props = {}; // All properties, including accessors
  4455. var tag = "";
  4456. function saveProperty(name, tkn) {
  4457. if (props[name] && _.has(props, name))
  4458. warning("W075", state.tokens.next, i);
  4459. else
  4460. props[name] = {};
  4461. props[name].basic = true;
  4462. props[name].basictkn = tkn;
  4463. }
  4464. function saveSetter(name, tkn) {
  4465. if (props[name] && _.has(props, name)) {
  4466. if (props[name].basic || props[name].setter)
  4467. warning("W075", state.tokens.next, i);
  4468. } else {
  4469. props[name] = {};
  4470. }
  4471. props[name].setter = true;
  4472. props[name].setterToken = tkn;
  4473. }
  4474. function saveGetter(name) {
  4475. if (props[name] && _.has(props, name)) {
  4476. if (props[name].basic || props[name].getter)
  4477. warning("W075", state.tokens.next, i);
  4478. } else {
  4479. props[name] = {};
  4480. }
  4481. props[name].getter = true;
  4482. props[name].getterToken = state.tokens.curr;
  4483. }
  4484. b = state.tokens.curr.line !== state.tokens.next.line;
  4485. if (b) {
  4486. indent += state.option.indent;
  4487. if (state.tokens.next.from === indent + state.option.indent) {
  4488. indent += state.option.indent;
  4489. }
  4490. }
  4491. for (;;) {
  4492. if (state.tokens.next.id === "}") {
  4493. break;
  4494. }
  4495. if (isclassdef && state.tokens.next.value === "static") {
  4496. advance("static");
  4497. tag = "static ";
  4498. }
  4499. if (state.tokens.next.value === "get" && peek().id !== ":") {
  4500. advance("get");
  4501. if (!state.option.inES5(!isclassdef)) {
  4502. error("E034");
  4503. }
  4504. i = property_name();
  4505. if (!i && !state.option.inESNext()) {
  4506. error("E035");
  4507. }
  4508. if (isclassdef && i === "constructor") {
  4509. error("E049", state.tokens.next, "class getter method", i);
  4510. }
  4511. if (i) {
  4512. saveGetter(tag + i);
  4513. }
  4514. t = state.tokens.next;
  4515. f = doFunction();
  4516. p = f["(params)"];
  4517. if (i && p) {
  4518. warning("W076", t, p[0], i);
  4519. }
  4520. } else if (state.tokens.next.value === "set" && peek().id !== ":") {
  4521. advance("set");
  4522. if (!state.option.inES5(!isclassdef)) {
  4523. error("E034");
  4524. }
  4525. i = property_name();
  4526. if (!i && !state.option.inESNext()) {
  4527. error("E035");
  4528. }
  4529. if (isclassdef && i === "constructor") {
  4530. error("E049", state.tokens.next, "class setter method", i);
  4531. }
  4532. if (i) {
  4533. saveSetter(tag + i, state.tokens.next);
  4534. }
  4535. t = state.tokens.next;
  4536. f = doFunction();
  4537. p = f["(params)"];
  4538. if (i && (!p || p.length !== 1)) {
  4539. warning("W077", t, i);
  4540. }
  4541. } else {
  4542. g = false;
  4543. if (state.tokens.next.value === "*" && state.tokens.next.type === "(punctuator)") {
  4544. if (!state.option.inESNext()) {
  4545. warning("W104", state.tokens.next, "generator functions");
  4546. }
  4547. advance("*");
  4548. g = true;
  4549. }
  4550. i = property_name();
  4551. saveProperty(tag + i, state.tokens.next);
  4552. if (typeof i !== "string") {
  4553. break;
  4554. }
  4555. if (state.tokens.next.value === "(") {
  4556. if (!state.option.inESNext()) {
  4557. warning("W104", state.tokens.curr, "concise methods");
  4558. }
  4559. doFunction(i, undefined, g);
  4560. } else if (!isclassdef) {
  4561. advance(":");
  4562. expression(10);
  4563. }
  4564. }
  4565. if (isclassdef && i === "prototype") {
  4566. error("E049", state.tokens.next, "class method", i);
  4567. }
  4568. countMember(i);
  4569. if (isclassdef) {
  4570. tag = "";
  4571. continue;
  4572. }
  4573. if (state.tokens.next.id === ",") {
  4574. comma({ allowTrailing: true, property: true });
  4575. if (state.tokens.next.id === ",") {
  4576. warning("W070", state.tokens.curr);
  4577. } else if (state.tokens.next.id === "}" && !state.option.inES5(true)) {
  4578. warning("W070", state.tokens.curr);
  4579. }
  4580. } else {
  4581. break;
  4582. }
  4583. }
  4584. if (b) {
  4585. indent -= state.option.indent;
  4586. }
  4587. advance("}", this);
  4588. if (state.option.inES5()) {
  4589. for (var name in props) {
  4590. if (_.has(props, name) && props[name].setter && !props[name].getter) {
  4591. warning("W078", props[name].setterToken);
  4592. }
  4593. }
  4594. }
  4595. return this;
  4596. };
  4597. x.fud = function () {
  4598. error("E036", state.tokens.curr);
  4599. };
  4600. }(delim("{")));
  4601. function destructuringExpression() {
  4602. var id, ids;
  4603. var identifiers = [];
  4604. if (!state.option.inESNext()) {
  4605. warning("W104", state.tokens.curr, "destructuring expression");
  4606. }
  4607. var nextInnerDE = function () {
  4608. var ident;
  4609. if (_.contains(["[", "{"], state.tokens.next.value)) {
  4610. ids = destructuringExpression();
  4611. for (var id in ids) {
  4612. id = ids[id];
  4613. identifiers.push({ id: id.id, token: id.token });
  4614. }
  4615. } else if (state.tokens.next.value === ",") {
  4616. identifiers.push({ id: null, token: state.tokens.curr });
  4617. } else if (state.tokens.next.value === "(") {
  4618. advance("(");
  4619. nextInnerDE();
  4620. advance(")");
  4621. } else {
  4622. ident = identifier();
  4623. if (ident)
  4624. identifiers.push({ id: ident, token: state.tokens.curr });
  4625. }
  4626. };
  4627. if (state.tokens.next.value === "[") {
  4628. advance("[");
  4629. nextInnerDE();
  4630. while (state.tokens.next.value !== "]") {
  4631. advance(",");
  4632. nextInnerDE();
  4633. }
  4634. advance("]");
  4635. } else if (state.tokens.next.value === "{") {
  4636. advance("{");
  4637. id = identifier();
  4638. if (state.tokens.next.value === ":") {
  4639. advance(":");
  4640. nextInnerDE();
  4641. } else {
  4642. identifiers.push({ id: id, token: state.tokens.curr });
  4643. }
  4644. while (state.tokens.next.value !== "}") {
  4645. advance(",");
  4646. id = identifier();
  4647. if (state.tokens.next.value === ":") {
  4648. advance(":");
  4649. nextInnerDE();
  4650. } else {
  4651. identifiers.push({ id: id, token: state.tokens.curr });
  4652. }
  4653. }
  4654. advance("}");
  4655. }
  4656. return identifiers;
  4657. }
  4658. function destructuringExpressionMatch(tokens, value) {
  4659. var first = value.first;
  4660. if (!first)
  4661. return;
  4662. _.zip(tokens, Array.isArray(first) ? first : [ first ]).forEach(function (val) {
  4663. var token = val[0];
  4664. var value = val[1];
  4665. if (token && value)
  4666. token.first = value;
  4667. else if (token && token.first && !value)
  4668. warning("W080", token.first, token.first.value);
  4669. });
  4670. }
  4671. var conststatement = stmt("const", function (prefix) {
  4672. var tokens;
  4673. var value;
  4674. var lone; // State variable to know if it is a lone identifier, or a destructuring statement.
  4675. if (!state.option.inESNext())
  4676. warning("W104", state.tokens.curr, "const");
  4677. this.first = [];
  4678. for (;;) {
  4679. var names = [];
  4680. if (_.contains(["{", "["], state.tokens.next.value)) {
  4681. tokens = destructuringExpression();
  4682. lone = false;
  4683. } else {
  4684. tokens = [ { id: identifier(), token: state.tokens.curr } ];
  4685. lone = true;
  4686. }
  4687. for (var t in tokens) {
  4688. if (tokens.hasOwnProperty(t)) {
  4689. t = tokens[t];
  4690. if (funct[t.id] === "const") {
  4691. warning("E011", null, t.id);
  4692. }
  4693. if (funct["(global)"] && predefined[t.id] === false) {
  4694. warning("W079", t.token, t.id);
  4695. }
  4696. if (t.id) {
  4697. addlabel(t.id, { token: t.token, type: "const", unused: true });
  4698. names.push(t.token);
  4699. }
  4700. }
  4701. }
  4702. if (prefix) {
  4703. break;
  4704. }
  4705. this.first = this.first.concat(names);
  4706. if (state.tokens.next.id !== "=") {
  4707. warning("E012", state.tokens.curr, state.tokens.curr.value);
  4708. }
  4709. if (state.tokens.next.id === "=") {
  4710. advance("=");
  4711. if (state.tokens.next.id === "undefined") {
  4712. warning("W080", state.tokens.prev, state.tokens.prev.value);
  4713. }
  4714. if (peek(0).id === "=" && state.tokens.next.identifier) {
  4715. warning("W120", state.tokens.next, state.tokens.next.value);
  4716. }
  4717. value = expression(10);
  4718. if (lone) {
  4719. tokens[0].first = value;
  4720. } else {
  4721. destructuringExpressionMatch(names, value);
  4722. }
  4723. }
  4724. if (state.tokens.next.id !== ",") {
  4725. break;
  4726. }
  4727. comma();
  4728. }
  4729. return this;
  4730. });
  4731. conststatement.exps = true;
  4732. var varstatement = stmt("var", function (prefix) {
  4733. var tokens, lone, value;
  4734. this.first = [];
  4735. for (;;) {
  4736. var names = [];
  4737. if (_.contains(["{", "["], state.tokens.next.value)) {
  4738. tokens = destructuringExpression();
  4739. lone = false;
  4740. } else {
  4741. tokens = [ { id: identifier(), token: state.tokens.curr } ];
  4742. lone = true;
  4743. }
  4744. for (var t in tokens) {
  4745. if (tokens.hasOwnProperty(t)) {
  4746. t = tokens[t];
  4747. if (state.option.inESNext() && funct[t.id] === "const") {
  4748. warning("E011", null, t.id);
  4749. }
  4750. if (funct["(global)"] && predefined[t.id] === false) {
  4751. warning("W079", t.token, t.id);
  4752. }
  4753. if (t.id) {
  4754. addlabel(t.id, { type: "unused", token: t.token });
  4755. names.push(t.token);
  4756. }
  4757. }
  4758. }
  4759. if (prefix) {
  4760. break;
  4761. }
  4762. this.first = this.first.concat(names);
  4763. if (state.tokens.next.id === "=") {
  4764. advance("=");
  4765. if (state.tokens.next.id === "undefined") {
  4766. warning("W080", state.tokens.prev, state.tokens.prev.value);
  4767. }
  4768. if (peek(0).id === "=" && state.tokens.next.identifier) {
  4769. warning("W120", state.tokens.next, state.tokens.next.value);
  4770. }
  4771. value = expression(10);
  4772. if (lone) {
  4773. tokens[0].first = value;
  4774. } else {
  4775. destructuringExpressionMatch(names, value);
  4776. }
  4777. }
  4778. if (state.tokens.next.id !== ",") {
  4779. break;
  4780. }
  4781. comma();
  4782. }
  4783. return this;
  4784. });
  4785. varstatement.exps = true;
  4786. var letstatement = stmt("let", function (prefix) {
  4787. var tokens, lone, value, letblock;
  4788. if (!state.option.inESNext()) {
  4789. warning("W104", state.tokens.curr, "let");
  4790. }
  4791. if (state.tokens.next.value === "(") {
  4792. if (!state.option.inMoz(true)) {
  4793. warning("W118", state.tokens.next, "let block");
  4794. }
  4795. advance("(");
  4796. funct["(blockscope)"].stack();
  4797. letblock = true;
  4798. } else if (funct["(nolet)"]) {
  4799. error("E048", state.tokens.curr);
  4800. }
  4801. this.first = [];
  4802. for (;;) {
  4803. var names = [];
  4804. if (_.contains(["{", "["], state.tokens.next.value)) {
  4805. tokens = destructuringExpression();
  4806. lone = false;
  4807. } else {
  4808. tokens = [ { id: identifier(), token: state.tokens.curr.value } ];
  4809. lone = true;
  4810. }
  4811. for (var t in tokens) {
  4812. if (tokens.hasOwnProperty(t)) {
  4813. t = tokens[t];
  4814. if (state.option.inESNext() && funct[t.id] === "const") {
  4815. warning("E011", null, t.id);
  4816. }
  4817. if (funct["(global)"] && predefined[t.id] === false) {
  4818. warning("W079", t.token, t.id);
  4819. }
  4820. if (t.id && !funct["(nolet)"]) {
  4821. addlabel(t.id, { type: "unused", token: t.token, islet: true });
  4822. names.push(t.token);
  4823. }
  4824. }
  4825. }
  4826. if (prefix) {
  4827. break;
  4828. }
  4829. this.first = this.first.concat(names);
  4830. if (state.tokens.next.id === "=") {
  4831. advance("=");
  4832. if (state.tokens.next.id === "undefined") {
  4833. warning("W080", state.tokens.prev, state.tokens.prev.value);
  4834. }
  4835. if (peek(0).id === "=" && state.tokens.next.identifier) {
  4836. warning("W120", state.tokens.next, state.tokens.next.value);
  4837. }
  4838. value = expression(10);
  4839. if (lone) {
  4840. tokens[0].first = value;
  4841. } else {
  4842. destructuringExpressionMatch(names, value);
  4843. }
  4844. }
  4845. if (state.tokens.next.id !== ",") {
  4846. break;
  4847. }
  4848. comma();
  4849. }
  4850. if (letblock) {
  4851. advance(")");
  4852. block(true, true);
  4853. this.block = true;
  4854. funct["(blockscope)"].unstack();
  4855. }
  4856. return this;
  4857. });
  4858. letstatement.exps = true;
  4859. blockstmt("class", function () {
  4860. return classdef.call(this, true);
  4861. });
  4862. function classdef(stmt) {
  4863. if (!state.option.inESNext()) {
  4864. warning("W104", state.tokens.curr, "class");
  4865. }
  4866. if (stmt) {
  4867. this.name = identifier();
  4868. addlabel(this.name, { type: "unused", token: state.tokens.curr });
  4869. } else if (state.tokens.next.identifier && state.tokens.next.value !== "extends") {
  4870. this.name = identifier();
  4871. }
  4872. classtail(this);
  4873. return this;
  4874. }
  4875. function classtail(c) {
  4876. var strictness = state.directive["use strict"];
  4877. if (state.tokens.next.value === "extends") {
  4878. advance("extends");
  4879. c.heritage = expression(10);
  4880. }
  4881. state.directive["use strict"] = true;
  4882. advance("{");
  4883. c.body = state.syntax["{"].nud(true);
  4884. state.directive["use strict"] = strictness;
  4885. }
  4886. blockstmt("function", function () {
  4887. var generator = false;
  4888. if (state.tokens.next.value === "*") {
  4889. advance("*");
  4890. if (state.option.inESNext(true)) {
  4891. generator = true;
  4892. } else {
  4893. warning("W119", state.tokens.curr, "function*");
  4894. }
  4895. }
  4896. if (inblock) {
  4897. warning("W082", state.tokens.curr);
  4898. }
  4899. var i = identifier();
  4900. if (funct[i] === "const") {
  4901. warning("E011", null, i);
  4902. }
  4903. addlabel(i, { type: "unction", token: state.tokens.curr });
  4904. doFunction(i, { statement: true }, generator);
  4905. if (state.tokens.next.id === "(" && state.tokens.next.line === state.tokens.curr.line) {
  4906. error("E039");
  4907. }
  4908. return this;
  4909. });
  4910. prefix("function", function () {
  4911. var generator = false;
  4912. if (state.tokens.next.value === "*") {
  4913. if (!state.option.inESNext()) {
  4914. warning("W119", state.tokens.curr, "function*");
  4915. }
  4916. advance("*");
  4917. generator = true;
  4918. }
  4919. var i = optionalidentifier();
  4920. doFunction(i, undefined, generator);
  4921. if (!state.option.loopfunc && funct["(loopage)"]) {
  4922. warning("W083");
  4923. }
  4924. return this;
  4925. });
  4926. blockstmt("if", function () {
  4927. var t = state.tokens.next;
  4928. increaseComplexityCount();
  4929. state.condition = true;
  4930. advance("(");
  4931. checkCondAssignment(expression(0));
  4932. advance(")", t);
  4933. state.condition = false;
  4934. block(true, true);
  4935. if (state.tokens.next.id === "else") {
  4936. advance("else");
  4937. if (state.tokens.next.id === "if" || state.tokens.next.id === "switch") {
  4938. statement(true);
  4939. } else {
  4940. block(true, true);
  4941. }
  4942. }
  4943. return this;
  4944. });
  4945. blockstmt("try", function () {
  4946. var b;
  4947. function doCatch() {
  4948. var oldScope = scope;
  4949. var e;
  4950. advance("catch");
  4951. advance("(");
  4952. scope = Object.create(oldScope);
  4953. e = state.tokens.next.value;
  4954. if (state.tokens.next.type !== "(identifier)") {
  4955. e = null;
  4956. warning("E030", state.tokens.next, e);
  4957. }
  4958. advance();
  4959. funct = functor("(catch)", state.tokens.next, scope, {
  4960. "(context)" : funct,
  4961. "(breakage)" : funct["(breakage)"],
  4962. "(loopage)" : funct["(loopage)"],
  4963. "(statement)": false,
  4964. "(catch)" : true
  4965. });
  4966. if (e) {
  4967. addlabel(e, { type: "exception" });
  4968. }
  4969. if (state.tokens.next.value === "if") {
  4970. if (!state.option.inMoz(true)) {
  4971. warning("W118", state.tokens.curr, "catch filter");
  4972. }
  4973. advance("if");
  4974. expression(0);
  4975. }
  4976. advance(")");
  4977. state.tokens.curr.funct = funct;
  4978. functions.push(funct);
  4979. block(false);
  4980. scope = oldScope;
  4981. funct["(last)"] = state.tokens.curr.line;
  4982. funct["(lastcharacter)"] = state.tokens.curr.character;
  4983. funct = funct["(context)"];
  4984. }
  4985. block(true);
  4986. while (state.tokens.next.id === "catch") {
  4987. increaseComplexityCount();
  4988. if (b && (!state.option.inMoz(true))) {
  4989. warning("W118", state.tokens.next, "multiple catch blocks");
  4990. }
  4991. doCatch();
  4992. b = true;
  4993. }
  4994. if (state.tokens.next.id === "finally") {
  4995. advance("finally");
  4996. block(true);
  4997. return;
  4998. }
  4999. if (!b) {
  5000. error("E021", state.tokens.next, "catch", state.tokens.next.value);
  5001. }
  5002. return this;
  5003. });
  5004. blockstmt("while", function () {
  5005. var t = state.tokens.next;
  5006. funct["(breakage)"] += 1;
  5007. funct["(loopage)"] += 1;
  5008. increaseComplexityCount();
  5009. advance("(");
  5010. checkCondAssignment(expression(0));
  5011. advance(")", t);
  5012. block(true, true);
  5013. funct["(breakage)"] -= 1;
  5014. funct["(loopage)"] -= 1;
  5015. return this;
  5016. }).labelled = true;
  5017. blockstmt("with", function () {
  5018. var t = state.tokens.next;
  5019. if (state.directive["use strict"]) {
  5020. error("E010", state.tokens.curr);
  5021. } else if (!state.option.withstmt) {
  5022. warning("W085", state.tokens.curr);
  5023. }
  5024. advance("(");
  5025. expression(0);
  5026. advance(")", t);
  5027. block(true, true);
  5028. return this;
  5029. });
  5030. blockstmt("switch", function () {
  5031. var t = state.tokens.next;
  5032. var g = false;
  5033. var noindent = false;
  5034. funct["(breakage)"] += 1;
  5035. advance("(");
  5036. checkCondAssignment(expression(0));
  5037. advance(")", t);
  5038. t = state.tokens.next;
  5039. advance("{");
  5040. if (state.tokens.next.from === indent)
  5041. noindent = true;
  5042. if (!noindent)
  5043. indent += state.option.indent;
  5044. this.cases = [];
  5045. for (;;) {
  5046. switch (state.tokens.next.id) {
  5047. case "case":
  5048. switch (funct["(verb)"]) {
  5049. case "yield":
  5050. case "break":
  5051. case "case":
  5052. case "continue":
  5053. case "return":
  5054. case "switch":
  5055. case "throw":
  5056. break;
  5057. default:
  5058. if (!reg.fallsThrough.test(state.lines[state.tokens.next.line - 2])) {
  5059. warning("W086", state.tokens.curr, "case");
  5060. }
  5061. }
  5062. advance("case");
  5063. this.cases.push(expression(0));
  5064. increaseComplexityCount();
  5065. g = true;
  5066. advance(":");
  5067. funct["(verb)"] = "case";
  5068. break;
  5069. case "default":
  5070. switch (funct["(verb)"]) {
  5071. case "yield":
  5072. case "break":
  5073. case "continue":
  5074. case "return":
  5075. case "throw":
  5076. break;
  5077. default:
  5078. if (this.cases.length) {
  5079. if (!reg.fallsThrough.test(state.lines[state.tokens.next.line - 2])) {
  5080. warning("W086", state.tokens.curr, "default");
  5081. }
  5082. }
  5083. }
  5084. advance("default");
  5085. g = true;
  5086. advance(":");
  5087. break;
  5088. case "}":
  5089. if (!noindent)
  5090. indent -= state.option.indent;
  5091. advance("}", t);
  5092. funct["(breakage)"] -= 1;
  5093. funct["(verb)"] = undefined;
  5094. return;
  5095. case "(end)":
  5096. error("E023", state.tokens.next, "}");
  5097. return;
  5098. default:
  5099. indent += state.option.indent;
  5100. if (g) {
  5101. switch (state.tokens.curr.id) {
  5102. case ",":
  5103. error("E040");
  5104. return;
  5105. case ":":
  5106. g = false;
  5107. statements();
  5108. break;
  5109. default:
  5110. error("E025", state.tokens.curr);
  5111. return;
  5112. }
  5113. } else {
  5114. if (state.tokens.curr.id === ":") {
  5115. advance(":");
  5116. error("E024", state.tokens.curr, ":");
  5117. statements();
  5118. } else {
  5119. error("E021", state.tokens.next, "case", state.tokens.next.value);
  5120. return;
  5121. }
  5122. }
  5123. indent -= state.option.indent;
  5124. }
  5125. }
  5126. }).labelled = true;
  5127. stmt("debugger", function () {
  5128. if (!state.option.debug) {
  5129. warning("W087", this);
  5130. }
  5131. return this;
  5132. }).exps = true;
  5133. (function () {
  5134. var x = stmt("do", function () {
  5135. funct["(breakage)"] += 1;
  5136. funct["(loopage)"] += 1;
  5137. increaseComplexityCount();
  5138. this.first = block(true, true);
  5139. advance("while");
  5140. var t = state.tokens.next;
  5141. advance("(");
  5142. checkCondAssignment(expression(0));
  5143. advance(")", t);
  5144. funct["(breakage)"] -= 1;
  5145. funct["(loopage)"] -= 1;
  5146. return this;
  5147. });
  5148. x.labelled = true;
  5149. x.exps = true;
  5150. }());
  5151. blockstmt("for", function () {
  5152. var s, t = state.tokens.next;
  5153. var letscope = false;
  5154. var foreachtok = null;
  5155. if (t.value === "each") {
  5156. foreachtok = t;
  5157. advance("each");
  5158. if (!state.option.inMoz(true)) {
  5159. warning("W118", state.tokens.curr, "for each");
  5160. }
  5161. }
  5162. funct["(breakage)"] += 1;
  5163. funct["(loopage)"] += 1;
  5164. increaseComplexityCount();
  5165. advance("(");
  5166. var nextop; // contains the token of the "in" or "of" operator
  5167. var i = 0;
  5168. var inof = ["in", "of"];
  5169. do {
  5170. nextop = peek(i);
  5171. ++i;
  5172. } while (!_.contains(inof, nextop.value) && nextop.value !== ";" &&
  5173. nextop.type !== "(end)");
  5174. if (_.contains(inof, nextop.value)) {
  5175. if (!state.option.inESNext() && nextop.value === "of") {
  5176. error("W104", nextop, "for of");
  5177. }
  5178. if (state.tokens.next.id === "var") {
  5179. advance("var");
  5180. state.syntax["var"].fud.call(state.syntax["var"].fud, true);
  5181. } else if (state.tokens.next.id === "let") {
  5182. advance("let");
  5183. letscope = true;
  5184. funct["(blockscope)"].stack();
  5185. state.syntax["let"].fud.call(state.syntax["let"].fud, true);
  5186. } else if (!state.tokens.next.identifier) {
  5187. error("E030", state.tokens.next, state.tokens.next.type);
  5188. advance();
  5189. } else {
  5190. switch (funct[state.tokens.next.value]) {
  5191. case "unused":
  5192. funct[state.tokens.next.value] = "var";
  5193. break;
  5194. case "var":
  5195. break;
  5196. default:
  5197. if (!funct["(blockscope)"].getlabel(state.tokens.next.value))
  5198. warning("W088", state.tokens.next, state.tokens.next.value);
  5199. }
  5200. advance();
  5201. }
  5202. advance(nextop.value);
  5203. expression(20);
  5204. advance(")", t);
  5205. s = block(true, true);
  5206. if (state.option.forin && s && (s.length > 1 || typeof s[0] !== "object" ||
  5207. s[0].value !== "if")) {
  5208. warning("W089", this);
  5209. }
  5210. funct["(breakage)"] -= 1;
  5211. funct["(loopage)"] -= 1;
  5212. } else {
  5213. if (foreachtok) {
  5214. error("E045", foreachtok);
  5215. }
  5216. if (state.tokens.next.id !== ";") {
  5217. if (state.tokens.next.id === "var") {
  5218. advance("var");
  5219. state.syntax["var"].fud.call(state.syntax["var"].fud);
  5220. } else if (state.tokens.next.id === "let") {
  5221. advance("let");
  5222. letscope = true;
  5223. funct["(blockscope)"].stack();
  5224. state.syntax["let"].fud.call(state.syntax["let"].fud);
  5225. } else {
  5226. for (;;) {
  5227. expression(0, "for");
  5228. if (state.tokens.next.id !== ",") {
  5229. break;
  5230. }
  5231. comma();
  5232. }
  5233. }
  5234. }
  5235. nolinebreak(state.tokens.curr);
  5236. advance(";");
  5237. if (state.tokens.next.id !== ";") {
  5238. checkCondAssignment(expression(0));
  5239. }
  5240. nolinebreak(state.tokens.curr);
  5241. advance(";");
  5242. if (state.tokens.next.id === ";") {
  5243. error("E021", state.tokens.next, ")", ";");
  5244. }
  5245. if (state.tokens.next.id !== ")") {
  5246. for (;;) {
  5247. expression(0, "for");
  5248. if (state.tokens.next.id !== ",") {
  5249. break;
  5250. }
  5251. comma();
  5252. }
  5253. }
  5254. advance(")", t);
  5255. block(true, true);
  5256. funct["(breakage)"] -= 1;
  5257. funct["(loopage)"] -= 1;
  5258. }
  5259. if (letscope) {
  5260. funct["(blockscope)"].unstack();
  5261. }
  5262. return this;
  5263. }).labelled = true;
  5264. stmt("break", function () {
  5265. var v = state.tokens.next.value;
  5266. if (funct["(breakage)"] === 0)
  5267. warning("W052", state.tokens.next, this.value);
  5268. if (!state.option.asi)
  5269. nolinebreak(this);
  5270. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  5271. if (state.tokens.curr.line === state.tokens.next.line) {
  5272. if (funct[v] !== "label") {
  5273. warning("W090", state.tokens.next, v);
  5274. } else if (scope[v] !== funct) {
  5275. warning("W091", state.tokens.next, v);
  5276. }
  5277. this.first = state.tokens.next;
  5278. advance();
  5279. }
  5280. }
  5281. reachable("break");
  5282. return this;
  5283. }).exps = true;
  5284. stmt("continue", function () {
  5285. var v = state.tokens.next.value;
  5286. if (funct["(breakage)"] === 0)
  5287. warning("W052", state.tokens.next, this.value);
  5288. if (!state.option.asi)
  5289. nolinebreak(this);
  5290. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  5291. if (state.tokens.curr.line === state.tokens.next.line) {
  5292. if (funct[v] !== "label") {
  5293. warning("W090", state.tokens.next, v);
  5294. } else if (scope[v] !== funct) {
  5295. warning("W091", state.tokens.next, v);
  5296. }
  5297. this.first = state.tokens.next;
  5298. advance();
  5299. }
  5300. } else if (!funct["(loopage)"]) {
  5301. warning("W052", state.tokens.next, this.value);
  5302. }
  5303. reachable("continue");
  5304. return this;
  5305. }).exps = true;
  5306. stmt("return", function () {
  5307. if (this.line === state.tokens.next.line) {
  5308. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  5309. this.first = expression(0);
  5310. if (this.first &&
  5311. this.first.type === "(punctuator)" && this.first.value === "=" &&
  5312. !this.first.paren && !state.option.boss) {
  5313. warningAt("W093", this.first.line, this.first.character);
  5314. }
  5315. }
  5316. } else {
  5317. if (state.tokens.next.type === "(punctuator)" &&
  5318. ["[", "{", "+", "-"].indexOf(state.tokens.next.value) > -1) {
  5319. nolinebreak(this); // always warn (Line breaking error)
  5320. }
  5321. }
  5322. reachable("return");
  5323. return this;
  5324. }).exps = true;
  5325. (function (x) {
  5326. x.exps = true;
  5327. x.lbp = 25;
  5328. }(prefix("yield", function () {
  5329. var prev = state.tokens.prev;
  5330. if (state.option.inESNext(true) && !funct["(generator)"]) {
  5331. if (!("(catch)" === funct["(name)"] && funct["(context)"]["(generator)"])) {
  5332. error("E046", state.tokens.curr, "yield");
  5333. }
  5334. } else if (!state.option.inESNext()) {
  5335. warning("W104", state.tokens.curr, "yield");
  5336. }
  5337. funct["(generator)"] = "yielded";
  5338. if (this.line === state.tokens.next.line || !state.option.inMoz(true)) {
  5339. if (state.tokens.next.id !== ";" && !state.tokens.next.reach && state.tokens.next.nud) {
  5340. nobreaknonadjacent(state.tokens.curr, state.tokens.next);
  5341. this.first = expression(10);
  5342. if (this.first.type === "(punctuator)" && this.first.value === "=" &&
  5343. !this.first.paren && !state.option.boss) {
  5344. warningAt("W093", this.first.line, this.first.character);
  5345. }
  5346. }
  5347. if (state.option.inMoz(true) && state.tokens.next.id !== ")" &&
  5348. (prev.lbp > 30 || (!prev.assign && !isEndOfExpr()) || prev.id === "yield")) {
  5349. error("E050", this);
  5350. }
  5351. } else if (!state.option.asi) {
  5352. nolinebreak(this); // always warn (Line breaking error)
  5353. }
  5354. return this;
  5355. })));
  5356. stmt("throw", function () {
  5357. nolinebreak(this);
  5358. this.first = expression(20);
  5359. reachable("throw");
  5360. return this;
  5361. }).exps = true;
  5362. stmt("import", function () {
  5363. if (!state.option.inESNext()) {
  5364. warning("W119", state.tokens.curr, "import");
  5365. }
  5366. if (state.tokens.next.type === "(string)") {
  5367. advance("(string)");
  5368. return this;
  5369. }
  5370. if (state.tokens.next.identifier) {
  5371. this.name = identifier();
  5372. addlabel(this.name, { type: "unused", token: state.tokens.curr });
  5373. } else {
  5374. advance("{");
  5375. for (;;) {
  5376. if (state.tokens.next.value === "}") {
  5377. advance("}");
  5378. break;
  5379. }
  5380. var importName;
  5381. if (state.tokens.next.type === "default") {
  5382. importName = "default";
  5383. advance("default");
  5384. } else {
  5385. importName = identifier();
  5386. }
  5387. if (state.tokens.next.value === "as") {
  5388. advance("as");
  5389. importName = identifier();
  5390. }
  5391. addlabel(importName, { type: "unused", token: state.tokens.curr });
  5392. if (state.tokens.next.value === ",") {
  5393. advance(",");
  5394. } else if (state.tokens.next.value === "}") {
  5395. advance("}");
  5396. break;
  5397. } else {
  5398. error("E024", state.tokens.next, state.tokens.next.value);
  5399. break;
  5400. }
  5401. }
  5402. }
  5403. advance("from");
  5404. advance("(string)");
  5405. return this;
  5406. }).exps = true;
  5407. stmt("export", function () {
  5408. if (!state.option.inESNext()) {
  5409. warning("W119", state.tokens.curr, "export");
  5410. }
  5411. if (state.tokens.next.type === "default") {
  5412. advance("default");
  5413. if (state.tokens.next.id === "function" || state.tokens.next.id === "class") {
  5414. this.block = true;
  5415. }
  5416. this.exportee = expression(10);
  5417. return this;
  5418. }
  5419. if (state.tokens.next.value === "{") {
  5420. advance("{");
  5421. for (;;) {
  5422. exported[identifier()] = true;
  5423. if (state.tokens.next.value === ",") {
  5424. advance(",");
  5425. } else if (state.tokens.next.value === "}") {
  5426. advance("}");
  5427. break;
  5428. } else {
  5429. error("E024", state.tokens.next, state.tokens.next.value);
  5430. break;
  5431. }
  5432. }
  5433. return this;
  5434. }
  5435. if (state.tokens.next.id === "var") {
  5436. advance("var");
  5437. exported[state.tokens.next.value] = true;
  5438. state.syntax["var"].fud.call(state.syntax["var"].fud);
  5439. } else if (state.tokens.next.id === "let") {
  5440. advance("let");
  5441. exported[state.tokens.next.value] = true;
  5442. state.syntax["let"].fud.call(state.syntax["let"].fud);
  5443. } else if (state.tokens.next.id === "const") {
  5444. advance("const");
  5445. exported[state.tokens.next.value] = true;
  5446. state.syntax["const"].fud.call(state.syntax["const"].fud);
  5447. } else if (state.tokens.next.id === "function") {
  5448. this.block = true;
  5449. advance("function");
  5450. exported[state.tokens.next.value] = true;
  5451. state.syntax["function"].fud();
  5452. } else if (state.tokens.next.id === "class") {
  5453. this.block = true;
  5454. advance("class");
  5455. exported[state.tokens.next.value] = true;
  5456. state.syntax["class"].fud();
  5457. } else {
  5458. error("E024", state.tokens.next, state.tokens.next.value);
  5459. }
  5460. return this;
  5461. }).exps = true;
  5462. FutureReservedWord("abstract");
  5463. FutureReservedWord("boolean");
  5464. FutureReservedWord("byte");
  5465. FutureReservedWord("char");
  5466. FutureReservedWord("class", { es5: true, nud: classdef });
  5467. FutureReservedWord("double");
  5468. FutureReservedWord("enum", { es5: true });
  5469. FutureReservedWord("export", { es5: true });
  5470. FutureReservedWord("extends", { es5: true });
  5471. FutureReservedWord("final");
  5472. FutureReservedWord("float");
  5473. FutureReservedWord("goto");
  5474. FutureReservedWord("implements", { es5: true, strictOnly: true });
  5475. FutureReservedWord("import", { es5: true });
  5476. FutureReservedWord("int");
  5477. FutureReservedWord("interface", { es5: true, strictOnly: true });
  5478. FutureReservedWord("long");
  5479. FutureReservedWord("native");
  5480. FutureReservedWord("package", { es5: true, strictOnly: true });
  5481. FutureReservedWord("private", { es5: true, strictOnly: true });
  5482. FutureReservedWord("protected", { es5: true, strictOnly: true });
  5483. FutureReservedWord("public", { es5: true, strictOnly: true });
  5484. FutureReservedWord("short");
  5485. FutureReservedWord("static", { es5: true, strictOnly: true });
  5486. FutureReservedWord("super", { es5: true });
  5487. FutureReservedWord("synchronized");
  5488. FutureReservedWord("transient");
  5489. FutureReservedWord("volatile");
  5490. var lookupBlockType = function () {
  5491. var pn, pn1;
  5492. var i = -1;
  5493. var bracketStack = 0;
  5494. var ret = {};
  5495. if (_.contains(["[", "{"], state.tokens.curr.value))
  5496. bracketStack += 1;
  5497. do {
  5498. pn = (i === -1) ? state.tokens.next : peek(i);
  5499. pn1 = peek(i + 1);
  5500. i = i + 1;
  5501. if (_.contains(["[", "{"], pn.value)) {
  5502. bracketStack += 1;
  5503. } else if (_.contains(["]", "}"], pn.value)) {
  5504. bracketStack -= 1;
  5505. }
  5506. if (pn.identifier && pn.value === "for" && bracketStack === 1) {
  5507. ret.isCompArray = true;
  5508. ret.notJson = true;
  5509. break;
  5510. }
  5511. if (_.contains(["}", "]"], pn.value) && pn1.value === "=" && bracketStack === 0) {
  5512. ret.isDestAssign = true;
  5513. ret.notJson = true;
  5514. break;
  5515. }
  5516. if (pn.value === ";") {
  5517. ret.isBlock = true;
  5518. ret.notJson = true;
  5519. }
  5520. } while (bracketStack > 0 && pn.id !== "(end)" && i < 15);
  5521. return ret;
  5522. };
  5523. function destructuringAssignOrJsonValue() {
  5524. var block = lookupBlockType();
  5525. if (block.notJson) {
  5526. if (!state.option.inESNext() && block.isDestAssign) {
  5527. warning("W104", state.tokens.curr, "destructuring assignment");
  5528. }
  5529. statements();
  5530. } else {
  5531. state.option.laxbreak = true;
  5532. state.jsonMode = true;
  5533. jsonValue();
  5534. }
  5535. }
  5536. var arrayComprehension = function () {
  5537. var CompArray = function () {
  5538. this.mode = "use";
  5539. this.variables = [];
  5540. };
  5541. var _carrays = [];
  5542. var _current;
  5543. function declare(v) {
  5544. var l = _current.variables.filter(function (elt) {
  5545. if (elt.value === v) {
  5546. elt.undef = false;
  5547. return v;
  5548. }
  5549. }).length;
  5550. return l !== 0;
  5551. }
  5552. function use(v) {
  5553. var l = _current.variables.filter(function (elt) {
  5554. if (elt.value === v && !elt.undef) {
  5555. if (elt.unused === true) {
  5556. elt.unused = false;
  5557. }
  5558. return v;
  5559. }
  5560. }).length;
  5561. return (l === 0);
  5562. }
  5563. return {stack: function () {
  5564. _current = new CompArray();
  5565. _carrays.push(_current);
  5566. },
  5567. unstack: function () {
  5568. _current.variables.filter(function (v) {
  5569. if (v.unused)
  5570. warning("W098", v.token, v.value);
  5571. if (v.undef)
  5572. isundef(v.funct, "W117", v.token, v.value);
  5573. });
  5574. _carrays.splice(-1, 1);
  5575. _current = _carrays[_carrays.length - 1];
  5576. },
  5577. setState: function (s) {
  5578. if (_.contains(["use", "define", "generate", "filter"], s))
  5579. _current.mode = s;
  5580. },
  5581. check: function (v) {
  5582. if (!_current) {
  5583. return;
  5584. }
  5585. if (_current && _current.mode === "use") {
  5586. if (use(v)) {
  5587. _current.variables.push({
  5588. funct: funct,
  5589. token: state.tokens.curr,
  5590. value: v,
  5591. undef: true,
  5592. unused: false
  5593. });
  5594. }
  5595. return true;
  5596. } else if (_current && _current.mode === "define") {
  5597. if (!declare(v)) {
  5598. _current.variables.push({
  5599. funct: funct,
  5600. token: state.tokens.curr,
  5601. value: v,
  5602. undef: false,
  5603. unused: true
  5604. });
  5605. }
  5606. return true;
  5607. } else if (_current && _current.mode === "generate") {
  5608. isundef(funct, "W117", state.tokens.curr, v);
  5609. return true;
  5610. } else if (_current && _current.mode === "filter") {
  5611. if (use(v)) {
  5612. isundef(funct, "W117", state.tokens.curr, v);
  5613. }
  5614. return true;
  5615. }
  5616. return false;
  5617. }
  5618. };
  5619. };
  5620. function jsonValue() {
  5621. function jsonObject() {
  5622. var o = {}, t = state.tokens.next;
  5623. advance("{");
  5624. if (state.tokens.next.id !== "}") {
  5625. for (;;) {
  5626. if (state.tokens.next.id === "(end)") {
  5627. error("E026", state.tokens.next, t.line);
  5628. } else if (state.tokens.next.id === "}") {
  5629. warning("W094", state.tokens.curr);
  5630. break;
  5631. } else if (state.tokens.next.id === ",") {
  5632. error("E028", state.tokens.next);
  5633. } else if (state.tokens.next.id !== "(string)") {
  5634. warning("W095", state.tokens.next, state.tokens.next.value);
  5635. }
  5636. if (o[state.tokens.next.value] === true) {
  5637. warning("W075", state.tokens.next, state.tokens.next.value);
  5638. } else if ((state.tokens.next.value === "__proto__" &&
  5639. !state.option.proto) || (state.tokens.next.value === "__iterator__" &&
  5640. !state.option.iterator)) {
  5641. warning("W096", state.tokens.next, state.tokens.next.value);
  5642. } else {
  5643. o[state.tokens.next.value] = true;
  5644. }
  5645. advance();
  5646. advance(":");
  5647. jsonValue();
  5648. if (state.tokens.next.id !== ",") {
  5649. break;
  5650. }
  5651. advance(",");
  5652. }
  5653. }
  5654. advance("}");
  5655. }
  5656. function jsonArray() {
  5657. var t = state.tokens.next;
  5658. advance("[");
  5659. if (state.tokens.next.id !== "]") {
  5660. for (;;) {
  5661. if (state.tokens.next.id === "(end)") {
  5662. error("E027", state.tokens.next, t.line);
  5663. } else if (state.tokens.next.id === "]") {
  5664. warning("W094", state.tokens.curr);
  5665. break;
  5666. } else if (state.tokens.next.id === ",") {
  5667. error("E028", state.tokens.next);
  5668. }
  5669. jsonValue();
  5670. if (state.tokens.next.id !== ",") {
  5671. break;
  5672. }
  5673. advance(",");
  5674. }
  5675. }
  5676. advance("]");
  5677. }
  5678. switch (state.tokens.next.id) {
  5679. case "{":
  5680. jsonObject();
  5681. break;
  5682. case "[":
  5683. jsonArray();
  5684. break;
  5685. case "true":
  5686. case "false":
  5687. case "null":
  5688. case "(number)":
  5689. case "(string)":
  5690. advance();
  5691. break;
  5692. case "-":
  5693. advance("-");
  5694. advance("(number)");
  5695. break;
  5696. default:
  5697. error("E003", state.tokens.next);
  5698. }
  5699. }
  5700. var blockScope = function () {
  5701. var _current = {};
  5702. var _variables = [_current];
  5703. function _checkBlockLabels() {
  5704. for (var t in _current) {
  5705. if (_current[t]["(type)"] === "unused") {
  5706. if (state.option.unused) {
  5707. var tkn = _current[t]["(token)"];
  5708. var line = tkn.line;
  5709. var chr = tkn.character;
  5710. warningAt("W098", line, chr, t);
  5711. }
  5712. }
  5713. }
  5714. }
  5715. return {
  5716. stack: function () {
  5717. _current = {};
  5718. _variables.push(_current);
  5719. },
  5720. unstack: function () {
  5721. _checkBlockLabels();
  5722. _variables.splice(_variables.length - 1, 1);
  5723. _current = _.last(_variables);
  5724. },
  5725. getlabel: function (l) {
  5726. for (var i = _variables.length - 1 ; i >= 0; --i) {
  5727. if (_.has(_variables[i], l) && !_variables[i][l]["(shadowed)"]) {
  5728. return _variables[i];
  5729. }
  5730. }
  5731. },
  5732. shadow: function (name) {
  5733. for (var i = _variables.length - 1; i >= 0; i--) {
  5734. if (_.has(_variables[i], name)) {
  5735. _variables[i][name]["(shadowed)"] = true;
  5736. }
  5737. }
  5738. },
  5739. unshadow: function (name) {
  5740. for (var i = _variables.length - 1; i >= 0; i--) {
  5741. if (_.has(_variables[i], name)) {
  5742. _variables[i][name]["(shadowed)"] = false;
  5743. }
  5744. }
  5745. },
  5746. current: {
  5747. has: function (t) {
  5748. return _.has(_current, t);
  5749. },
  5750. add: function (t, type, tok) {
  5751. _current[t] = { "(type)" : type, "(token)": tok, "(shadowed)": false };
  5752. }
  5753. }
  5754. };
  5755. };
  5756. var itself = function (s, o, g) {
  5757. var i, k, x;
  5758. var optionKeys;
  5759. var newOptionObj = {};
  5760. var newIgnoredObj = {};
  5761. o = _.clone(o);
  5762. state.reset();
  5763. if (o && o.scope) {
  5764. JSHINT.scope = o.scope;
  5765. } else {
  5766. JSHINT.errors = [];
  5767. JSHINT.undefs = [];
  5768. JSHINT.internals = [];
  5769. JSHINT.blacklist = {};
  5770. JSHINT.scope = "(main)";
  5771. }
  5772. predefined = Object.create(null);
  5773. combine(predefined, vars.ecmaIdentifiers);
  5774. combine(predefined, vars.reservedVars);
  5775. combine(predefined, g || {});
  5776. declared = Object.create(null);
  5777. exported = Object.create(null);
  5778. function each(obj, cb) {
  5779. if (!obj)
  5780. return;
  5781. if (!Array.isArray(obj) && typeof obj === "object")
  5782. obj = Object.keys(obj);
  5783. obj.forEach(cb);
  5784. }
  5785. if (o) {
  5786. each(o.predef || null, function (item) {
  5787. var slice, prop;
  5788. if (item[0] === "-") {
  5789. slice = item.slice(1);
  5790. JSHINT.blacklist[slice] = slice;
  5791. } else {
  5792. prop = Object.getOwnPropertyDescriptor(o.predef, item);
  5793. predefined[item] = prop ? prop.value : false;
  5794. }
  5795. });
  5796. each(o.exported || null, function (item) {
  5797. exported[item] = true;
  5798. });
  5799. delete o.predef;
  5800. delete o.exported;
  5801. optionKeys = Object.keys(o);
  5802. for (x = 0; x < optionKeys.length; x++) {
  5803. if (/^-W\d{3}$/g.test(optionKeys[x])) {
  5804. newIgnoredObj[optionKeys[x].slice(1)] = true;
  5805. } else {
  5806. newOptionObj[optionKeys[x]] = o[optionKeys[x]];
  5807. if (optionKeys[x] === "newcap" && o[optionKeys[x]] === false)
  5808. newOptionObj["(explicitNewcap)"] = true;
  5809. }
  5810. }
  5811. }
  5812. state.option = newOptionObj;
  5813. state.ignored = newIgnoredObj;
  5814. state.option.indent = state.option.indent || 4;
  5815. state.option.maxerr = state.option.maxerr || 50;
  5816. indent = 1;
  5817. global = Object.create(predefined);
  5818. scope = global;
  5819. funct = functor("(global)", null, scope, {
  5820. "(global)" : true,
  5821. "(blockscope)": blockScope(),
  5822. "(comparray)" : arrayComprehension(),
  5823. "(metrics)" : createMetrics(state.tokens.next)
  5824. });
  5825. functions = [funct];
  5826. urls = [];
  5827. stack = null;
  5828. member = {};
  5829. membersOnly = null;
  5830. implied = {};
  5831. inblock = false;
  5832. lookahead = [];
  5833. unuseds = [];
  5834. if (!isString(s) && !Array.isArray(s)) {
  5835. errorAt("E004", 0);
  5836. return false;
  5837. }
  5838. api = {
  5839. get isJSON() {
  5840. return state.jsonMode;
  5841. },
  5842. getOption: function (name) {
  5843. return state.option[name] || null;
  5844. },
  5845. getCache: function (name) {
  5846. return state.cache[name];
  5847. },
  5848. setCache: function (name, value) {
  5849. state.cache[name] = value;
  5850. },
  5851. warn: function (code, data) {
  5852. warningAt.apply(null, [ code, data.line, data.char ].concat(data.data));
  5853. },
  5854. on: function (names, listener) {
  5855. names.split(" ").forEach(function (name) {
  5856. emitter.on(name, listener);
  5857. }.bind(this));
  5858. }
  5859. };
  5860. emitter.removeAllListeners();
  5861. (extraModules || []).forEach(function (func) {
  5862. func(api);
  5863. });
  5864. state.tokens.prev = state.tokens.curr = state.tokens.next = state.syntax["(begin)"];
  5865. lex = new Lexer(s);
  5866. lex.on("warning", function (ev) {
  5867. warningAt.apply(null, [ ev.code, ev.line, ev.character].concat(ev.data));
  5868. });
  5869. lex.on("error", function (ev) {
  5870. errorAt.apply(null, [ ev.code, ev.line, ev.character ].concat(ev.data));
  5871. });
  5872. lex.on("fatal", function (ev) {
  5873. quit("E041", ev.line, ev.from);
  5874. });
  5875. lex.on("Identifier", function (ev) {
  5876. emitter.emit("Identifier", ev);
  5877. });
  5878. lex.on("String", function (ev) {
  5879. emitter.emit("String", ev);
  5880. });
  5881. lex.on("Number", function (ev) {
  5882. emitter.emit("Number", ev);
  5883. });
  5884. lex.start();
  5885. for (var name in o) {
  5886. if (_.has(o, name)) {
  5887. checkOption(name, state.tokens.curr);
  5888. }
  5889. }
  5890. assume();
  5891. combine(predefined, g || {});
  5892. comma.first = true;
  5893. try {
  5894. advance();
  5895. switch (state.tokens.next.id) {
  5896. case "{":
  5897. case "[":
  5898. destructuringAssignOrJsonValue();
  5899. break;
  5900. default:
  5901. directives();
  5902. if (state.directive["use strict"]) {
  5903. if (!state.option.globalstrict && !(state.option.node || state.option.phantom)) {
  5904. warning("W097", state.tokens.prev);
  5905. }
  5906. }
  5907. statements();
  5908. }
  5909. advance((state.tokens.next && state.tokens.next.value !== ".") ? "(end)" : undefined);
  5910. funct["(blockscope)"].unstack();
  5911. var markDefined = function (name, context) {
  5912. do {
  5913. if (typeof context[name] === "string") {
  5914. if (context[name] === "unused")
  5915. context[name] = "var";
  5916. else if (context[name] === "unction")
  5917. context[name] = "closure";
  5918. return true;
  5919. }
  5920. context = context["(context)"];
  5921. } while (context);
  5922. return false;
  5923. };
  5924. var clearImplied = function (name, line) {
  5925. if (!implied[name])
  5926. return;
  5927. var newImplied = [];
  5928. for (var i = 0; i < implied[name].length; i += 1) {
  5929. if (implied[name][i] !== line)
  5930. newImplied.push(implied[name][i]);
  5931. }
  5932. if (newImplied.length === 0)
  5933. delete implied[name];
  5934. else
  5935. implied[name] = newImplied;
  5936. };
  5937. var warnUnused = function (name, tkn, type, unused_opt) {
  5938. var line = tkn.line;
  5939. var chr = tkn.character;
  5940. if (unused_opt === undefined) {
  5941. unused_opt = state.option.unused;
  5942. }
  5943. if (unused_opt === true) {
  5944. unused_opt = "last-param";
  5945. }
  5946. var warnable_types = {
  5947. "vars": ["var"],
  5948. "last-param": ["var", "param"],
  5949. "strict": ["var", "param", "last-param"]
  5950. };
  5951. if (unused_opt) {
  5952. if (warnable_types[unused_opt] && warnable_types[unused_opt].indexOf(type) !== -1) {
  5953. warningAt("W098", line, chr, name);
  5954. }
  5955. }
  5956. unuseds.push({
  5957. name: name,
  5958. line: line,
  5959. character: chr
  5960. });
  5961. };
  5962. var checkUnused = function (func, key) {
  5963. var type = func[key];
  5964. var tkn = func["(tokens)"][key];
  5965. if (key.charAt(0) === "(")
  5966. return;
  5967. if (type !== "unused" && type !== "unction" && type !== "const")
  5968. return;
  5969. if (func["(params)"] && func["(params)"].indexOf(key) !== -1)
  5970. return;
  5971. if (func["(global)"] && _.has(exported, key))
  5972. return;
  5973. if (type === "const" && !getprop(func, key, "unused"))
  5974. return;
  5975. warnUnused(key, tkn, "var");
  5976. };
  5977. for (i = 0; i < JSHINT.undefs.length; i += 1) {
  5978. k = JSHINT.undefs[i].slice(0);
  5979. if (markDefined(k[2].value, k[0])) {
  5980. clearImplied(k[2].value, k[2].line);
  5981. } else if (state.option.undef) {
  5982. warning.apply(warning, k.slice(1));
  5983. }
  5984. }
  5985. functions.forEach(function (func) {
  5986. if (func["(unusedOption)"] === false) {
  5987. return;
  5988. }
  5989. for (var key in func) {
  5990. if (_.has(func, key)) {
  5991. checkUnused(func, key);
  5992. }
  5993. }
  5994. if (!func["(params)"])
  5995. return;
  5996. var params = func["(params)"].slice();
  5997. var param = params.pop();
  5998. var type, unused_opt;
  5999. while (param) {
  6000. type = func[param];
  6001. unused_opt = func["(unusedOption)"] || state.option.unused;
  6002. unused_opt = unused_opt === true ? "last-param" : unused_opt;
  6003. if (param === "undefined")
  6004. return;
  6005. if (type === "unused" || type === "unction") {
  6006. warnUnused(param, func["(tokens)"][param], "param", func["(unusedOption)"]);
  6007. } else if (unused_opt === "last-param") {
  6008. return;
  6009. }
  6010. param = params.pop();
  6011. }
  6012. });
  6013. for (var key in declared) {
  6014. if (_.has(declared, key) && !_.has(global, key) && !_.has(exported, key)) {
  6015. warnUnused(key, declared[key], "var");
  6016. }
  6017. }
  6018. } catch (err) {
  6019. if (err && err.name === "JSHintError") {
  6020. var nt = state.tokens.next || {};
  6021. JSHINT.errors.push({
  6022. scope : "(main)",
  6023. raw : err.raw,
  6024. code : err.code,
  6025. reason : err.message,
  6026. line : err.line || nt.line,
  6027. character : err.character || nt.from
  6028. }, null);
  6029. } else {
  6030. throw err;
  6031. }
  6032. }
  6033. if (JSHINT.scope === "(main)") {
  6034. o = o || {};
  6035. for (i = 0; i < JSHINT.internals.length; i += 1) {
  6036. k = JSHINT.internals[i];
  6037. o.scope = k.elem;
  6038. itself(k.value, o, g);
  6039. }
  6040. }
  6041. return JSHINT.errors.length === 0;
  6042. };
  6043. itself.addModule = function (func) {
  6044. extraModules.push(func);
  6045. };
  6046. itself.addModule(style.register);
  6047. itself.data = function () {
  6048. var data = {
  6049. functions: [],
  6050. options: state.option
  6051. };
  6052. var implieds = [];
  6053. var members = [];
  6054. var fu, f, i, j, n, globals;
  6055. if (itself.errors.length) {
  6056. data.errors = itself.errors;
  6057. }
  6058. if (state.jsonMode) {
  6059. data.json = true;
  6060. }
  6061. for (n in implied) {
  6062. if (_.has(implied, n)) {
  6063. implieds.push({
  6064. name: n,
  6065. line: implied[n]
  6066. });
  6067. }
  6068. }
  6069. if (implieds.length > 0) {
  6070. data.implieds = implieds;
  6071. }
  6072. if (urls.length > 0) {
  6073. data.urls = urls;
  6074. }
  6075. globals = Object.keys(scope);
  6076. if (globals.length > 0) {
  6077. data.globals = globals;
  6078. }
  6079. for (i = 1; i < functions.length; i += 1) {
  6080. f = functions[i];
  6081. fu = {};
  6082. for (j = 0; j < functionicity.length; j += 1) {
  6083. fu[functionicity[j]] = [];
  6084. }
  6085. for (j = 0; j < functionicity.length; j += 1) {
  6086. if (fu[functionicity[j]].length === 0) {
  6087. delete fu[functionicity[j]];
  6088. }
  6089. }
  6090. fu.name = f["(name)"];
  6091. fu.param = f["(params)"];
  6092. fu.line = f["(line)"];
  6093. fu.character = f["(character)"];
  6094. fu.last = f["(last)"];
  6095. fu.lastcharacter = f["(lastcharacter)"];
  6096. fu.metrics = {
  6097. complexity: f["(metrics)"].ComplexityCount,
  6098. parameters: (f["(params)"] || []).length,
  6099. statements: f["(metrics)"].statementCount
  6100. };
  6101. data.functions.push(fu);
  6102. }
  6103. if (unuseds.length > 0) {
  6104. data.unused = unuseds;
  6105. }
  6106. members = [];
  6107. for (n in member) {
  6108. if (typeof member[n] === "number") {
  6109. data.member = member;
  6110. break;
  6111. }
  6112. }
  6113. return data;
  6114. };
  6115. itself.jshint = itself;
  6116. return itself;
  6117. }());
  6118. if (typeof exports === "object" && exports) {
  6119. exports.JSHINT = JSHINT;
  6120. }
  6121. },
  6122. {"./lex.js":4,"./messages.js":5,"./reg.js":6,"./state.js":7,"./style.js":8,"./vars.js":9,"events":10,"underscore":2}],
  6123. 4:[function(_dereq_,module,exports){
  6124. "use strict";
  6125. var _ = _dereq_("underscore");
  6126. var events = _dereq_("events");
  6127. var reg = _dereq_("./reg.js");
  6128. var state = _dereq_("./state.js").state;
  6129. var unicodeData = _dereq_("../data/ascii-identifier-data.js");
  6130. var asciiIdentifierStartTable = unicodeData.asciiIdentifierStartTable;
  6131. var asciiIdentifierPartTable = unicodeData.asciiIdentifierPartTable;
  6132. var Token = {
  6133. Identifier: 1,
  6134. Punctuator: 2,
  6135. NumericLiteral: 3,
  6136. StringLiteral: 4,
  6137. Comment: 5,
  6138. Keyword: 6,
  6139. NullLiteral: 7,
  6140. BooleanLiteral: 8,
  6141. RegExp: 9,
  6142. TemplateLiteral: 10
  6143. };
  6144. function asyncTrigger() {
  6145. var _checks = [];
  6146. return {
  6147. push: function (fn) {
  6148. _checks.push(fn);
  6149. },
  6150. check: function () {
  6151. for (var check = 0; check < _checks.length; ++check) {
  6152. _checks[check]();
  6153. }
  6154. _checks.splice(0, _checks.length);
  6155. }
  6156. };
  6157. }
  6158. function Lexer(source) {
  6159. var lines = source;
  6160. if (typeof lines === "string") {
  6161. lines = lines
  6162. .replace(/\r\n/g, "\n")
  6163. .replace(/\r/g, "\n")
  6164. .split("\n");
  6165. }
  6166. if (lines[0] && lines[0].substr(0, 2) === "#!") {
  6167. if (lines[0].indexOf("node") !== -1) {
  6168. state.option.node = true;
  6169. }
  6170. lines[0] = "";
  6171. }
  6172. this.emitter = new events.EventEmitter();
  6173. this.source = source;
  6174. this.setLines(lines);
  6175. this.prereg = true;
  6176. this.line = 0;
  6177. this.char = 1;
  6178. this.from = 1;
  6179. this.input = "";
  6180. this.inComment = false;
  6181. for (var i = 0; i < state.option.indent; i += 1) {
  6182. state.tab += " ";
  6183. }
  6184. }
  6185. Lexer.prototype = {
  6186. _lines: [],
  6187. getLines: function () {
  6188. this._lines = state.lines;
  6189. return this._lines;
  6190. },
  6191. setLines: function (val) {
  6192. this._lines = val;
  6193. state.lines = this._lines;
  6194. },
  6195. peek: function (i) {
  6196. return this.input.charAt(i || 0);
  6197. },
  6198. skip: function (i) {
  6199. i = i || 1;
  6200. this.char += i;
  6201. this.input = this.input.slice(i);
  6202. },
  6203. on: function (names, listener) {
  6204. names.split(" ").forEach(function (name) {
  6205. this.emitter.on(name, listener);
  6206. }.bind(this));
  6207. },
  6208. trigger: function () {
  6209. this.emitter.emit.apply(this.emitter, Array.prototype.slice.call(arguments));
  6210. },
  6211. triggerAsync: function (type, args, checks, fn) {
  6212. checks.push(function () {
  6213. if (fn()) {
  6214. this.trigger(type, args);
  6215. }
  6216. }.bind(this));
  6217. },
  6218. scanPunctuator: function () {
  6219. var ch1 = this.peek();
  6220. var ch2, ch3, ch4;
  6221. switch (ch1) {
  6222. case ".":
  6223. if ((/^[0-9]$/).test(this.peek(1))) {
  6224. return null;
  6225. }
  6226. if (this.peek(1) === "." && this.peek(2) === ".") {
  6227. return {
  6228. type: Token.Punctuator,
  6229. value: "..."
  6230. };
  6231. }
  6232. case "(":
  6233. case ")":
  6234. case ";":
  6235. case ",":
  6236. case "{":
  6237. case "}":
  6238. case "[":
  6239. case "]":
  6240. case ":":
  6241. case "~":
  6242. case "?":
  6243. return {
  6244. type: Token.Punctuator,
  6245. value: ch1
  6246. };
  6247. case "#":
  6248. return {
  6249. type: Token.Punctuator,
  6250. value: ch1
  6251. };
  6252. case "":
  6253. return null;
  6254. }
  6255. ch2 = this.peek(1);
  6256. ch3 = this.peek(2);
  6257. ch4 = this.peek(3);
  6258. if (ch1 === ">" && ch2 === ">" && ch3 === ">" && ch4 === "=") {
  6259. return {
  6260. type: Token.Punctuator,
  6261. value: ">>>="
  6262. };
  6263. }
  6264. if (ch1 === "=" && ch2 === "=" && ch3 === "=") {
  6265. return {
  6266. type: Token.Punctuator,
  6267. value: "==="
  6268. };
  6269. }
  6270. if (ch1 === "!" && ch2 === "=" && ch3 === "=") {
  6271. return {
  6272. type: Token.Punctuator,
  6273. value: "!=="
  6274. };
  6275. }
  6276. if (ch1 === ">" && ch2 === ">" && ch3 === ">") {
  6277. return {
  6278. type: Token.Punctuator,
  6279. value: ">>>"
  6280. };
  6281. }
  6282. if (ch1 === "<" && ch2 === "<" && ch3 === "=") {
  6283. return {
  6284. type: Token.Punctuator,
  6285. value: "<<="
  6286. };
  6287. }
  6288. if (ch1 === ">" && ch2 === ">" && ch3 === "=") {
  6289. return {
  6290. type: Token.Punctuator,
  6291. value: ">>="
  6292. };
  6293. }
  6294. if (ch1 === "=" && ch2 === ">") {
  6295. return {
  6296. type: Token.Punctuator,
  6297. value: ch1 + ch2
  6298. };
  6299. }
  6300. if (ch1 === ch2 && ("+-<>&|".indexOf(ch1) >= 0)) {
  6301. return {
  6302. type: Token.Punctuator,
  6303. value: ch1 + ch2
  6304. };
  6305. }
  6306. if ("<>=!+-*%&|^".indexOf(ch1) >= 0) {
  6307. if (ch2 === "=") {
  6308. return {
  6309. type: Token.Punctuator,
  6310. value: ch1 + ch2
  6311. };
  6312. }
  6313. return {
  6314. type: Token.Punctuator,
  6315. value: ch1
  6316. };
  6317. }
  6318. if (ch1 === "/") {
  6319. if (ch2 === "=" && /\/=(?!(\S*\/[gim]?))/.test(this.input)) {
  6320. return {
  6321. type: Token.Punctuator,
  6322. value: "/="
  6323. };
  6324. }
  6325. return {
  6326. type: Token.Punctuator,
  6327. value: "/"
  6328. };
  6329. }
  6330. return null;
  6331. },
  6332. scanComments: function () {
  6333. var ch1 = this.peek();
  6334. var ch2 = this.peek(1);
  6335. var rest = this.input.substr(2);
  6336. var startLine = this.line;
  6337. var startChar = this.char;
  6338. function commentToken(label, body, opt) {
  6339. var special = ["jshint", "jslint", "members", "member", "globals", "global", "exported"];
  6340. var isSpecial = false;
  6341. var value = label + body;
  6342. var commentType = "plain";
  6343. opt = opt || {};
  6344. if (opt.isMultiline) {
  6345. value += "*/";
  6346. }
  6347. special.forEach(function (str) {
  6348. if (isSpecial) {
  6349. return;
  6350. }
  6351. if (label === "//" && str !== "jshint") {
  6352. return;
  6353. }
  6354. if (body.substr(0, str.length) === str) {
  6355. isSpecial = true;
  6356. label = label + str;
  6357. body = body.substr(str.length);
  6358. }
  6359. if (!isSpecial && body.charAt(0) === " " && body.substr(1, str.length) === str) {
  6360. isSpecial = true;
  6361. label = label + " " + str;
  6362. body = body.substr(str.length + 1);
  6363. }
  6364. if (!isSpecial) {
  6365. return;
  6366. }
  6367. switch (str) {
  6368. case "member":
  6369. commentType = "members";
  6370. break;
  6371. case "global":
  6372. commentType = "globals";
  6373. break;
  6374. default:
  6375. commentType = str;
  6376. }
  6377. });
  6378. return {
  6379. type: Token.Comment,
  6380. commentType: commentType,
  6381. value: value,
  6382. body: body,
  6383. isSpecial: isSpecial,
  6384. isMultiline: opt.isMultiline || false,
  6385. isMalformed: opt.isMalformed || false
  6386. };
  6387. }
  6388. if (ch1 === "*" && ch2 === "/") {
  6389. this.trigger("error", {
  6390. code: "E018",
  6391. line: startLine,
  6392. character: startChar
  6393. });
  6394. this.skip(2);
  6395. return null;
  6396. }
  6397. if (ch1 !== "/" || (ch2 !== "*" && ch2 !== "/")) {
  6398. return null;
  6399. }
  6400. if (ch2 === "/") {
  6401. this.skip(this.input.length); // Skip to the EOL.
  6402. return commentToken("//", rest);
  6403. }
  6404. var body = "";
  6405. if (ch2 === "*") {
  6406. this.inComment = true;
  6407. this.skip(2);
  6408. while (this.peek() !== "*" || this.peek(1) !== "/") {
  6409. if (this.peek() === "") { // End of Line
  6410. body += "\n";
  6411. if (!this.nextLine()) {
  6412. this.trigger("error", {
  6413. code: "E017",
  6414. line: startLine,
  6415. character: startChar
  6416. });
  6417. this.inComment = false;
  6418. return commentToken("/*", body, {
  6419. isMultiline: true,
  6420. isMalformed: true
  6421. });
  6422. }
  6423. } else {
  6424. body += this.peek();
  6425. this.skip();
  6426. }
  6427. }
  6428. this.skip(2);
  6429. this.inComment = false;
  6430. return commentToken("/*", body, { isMultiline: true });
  6431. }
  6432. },
  6433. scanKeyword: function () {
  6434. var result = /^[a-zA-Z_$][a-zA-Z0-9_$]*/.exec(this.input);
  6435. var keywords = [
  6436. "if", "in", "do", "var", "for", "new",
  6437. "try", "let", "this", "else", "case",
  6438. "void", "with", "enum", "while", "break",
  6439. "catch", "throw", "const", "yield", "class",
  6440. "super", "return", "typeof", "delete",
  6441. "switch", "export", "import", "default",
  6442. "finally", "extends", "function", "continue",
  6443. "debugger", "instanceof"
  6444. ];
  6445. if (result && keywords.indexOf(result[0]) >= 0) {
  6446. return {
  6447. type: Token.Keyword,
  6448. value: result[0]
  6449. };
  6450. }
  6451. return null;
  6452. },
  6453. scanIdentifier: function () {
  6454. var id = "";
  6455. var index = 0;
  6456. var type, char;
  6457. function isNonAsciiIdentifierStart(code) {
  6458. return code > 256;
  6459. }
  6460. function isNonAsciiIdentifierPart(code) {
  6461. return code > 256;
  6462. }
  6463. function isHexDigit(str) {
  6464. return (/^[0-9a-fA-F]$/).test(str);
  6465. }
  6466. var readUnicodeEscapeSequence = function () {
  6467. index += 1;
  6468. if (this.peek(index) !== "u") {
  6469. return null;
  6470. }
  6471. var ch1 = this.peek(index + 1);
  6472. var ch2 = this.peek(index + 2);
  6473. var ch3 = this.peek(index + 3);
  6474. var ch4 = this.peek(index + 4);
  6475. var code;
  6476. if (isHexDigit(ch1) && isHexDigit(ch2) && isHexDigit(ch3) && isHexDigit(ch4)) {
  6477. code = parseInt(ch1 + ch2 + ch3 + ch4, 16);
  6478. if (asciiIdentifierPartTable[code] || isNonAsciiIdentifierPart(code)) {
  6479. index += 5;
  6480. return "\\u" + ch1 + ch2 + ch3 + ch4;
  6481. }
  6482. return null;
  6483. }
  6484. return null;
  6485. }.bind(this);
  6486. var getIdentifierStart = function () {
  6487. var chr = this.peek(index);
  6488. var code = chr.charCodeAt(0);
  6489. if (code === 92) {
  6490. return readUnicodeEscapeSequence();
  6491. }
  6492. if (code < 128) {
  6493. if (asciiIdentifierStartTable[code]) {
  6494. index += 1;
  6495. return chr;
  6496. }
  6497. return null;
  6498. }
  6499. if (isNonAsciiIdentifierStart(code)) {
  6500. index += 1;
  6501. return chr;
  6502. }
  6503. return null;
  6504. }.bind(this);
  6505. var getIdentifierPart = function () {
  6506. var chr = this.peek(index);
  6507. var code = chr.charCodeAt(0);
  6508. if (code === 92) {
  6509. return readUnicodeEscapeSequence();
  6510. }
  6511. if (code < 128) {
  6512. if (asciiIdentifierPartTable[code]) {
  6513. index += 1;
  6514. return chr;
  6515. }
  6516. return null;
  6517. }
  6518. if (isNonAsciiIdentifierPart(code)) {
  6519. index += 1;
  6520. return chr;
  6521. }
  6522. return null;
  6523. }.bind(this);
  6524. char = getIdentifierStart();
  6525. if (char === null) {
  6526. return null;
  6527. }
  6528. id = char;
  6529. for (;;) {
  6530. char = getIdentifierPart();
  6531. if (char === null) {
  6532. break;
  6533. }
  6534. id += char;
  6535. }
  6536. switch (id) {
  6537. case "true":
  6538. case "false":
  6539. type = Token.BooleanLiteral;
  6540. break;
  6541. case "null":
  6542. type = Token.NullLiteral;
  6543. break;
  6544. default:
  6545. type = Token.Identifier;
  6546. }
  6547. return {
  6548. type: type,
  6549. value: id
  6550. };
  6551. },
  6552. scanNumericLiteral: function () {
  6553. var index = 0;
  6554. var value = "";
  6555. var length = this.input.length;
  6556. var char = this.peek(index);
  6557. var bad;
  6558. function isDecimalDigit(str) {
  6559. return (/^[0-9]$/).test(str);
  6560. }
  6561. function isOctalDigit(str) {
  6562. return (/^[0-7]$/).test(str);
  6563. }
  6564. function isHexDigit(str) {
  6565. return (/^[0-9a-fA-F]$/).test(str);
  6566. }
  6567. function isIdentifierStart(ch) {
  6568. return (ch === "$") || (ch === "_") || (ch === "\\") ||
  6569. (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z");
  6570. }
  6571. if (char !== "." && !isDecimalDigit(char)) {
  6572. return null;
  6573. }
  6574. if (char !== ".") {
  6575. value = this.peek(index);
  6576. index += 1;
  6577. char = this.peek(index);
  6578. if (value === "0") {
  6579. if (char === "x" || char === "X") {
  6580. index += 1;
  6581. value += char;
  6582. while (index < length) {
  6583. char = this.peek(index);
  6584. if (!isHexDigit(char)) {
  6585. break;
  6586. }
  6587. value += char;
  6588. index += 1;
  6589. }
  6590. if (value.length <= 2) { // 0x
  6591. return {
  6592. type: Token.NumericLiteral,
  6593. value: value,
  6594. isMalformed: true
  6595. };
  6596. }
  6597. if (index < length) {
  6598. char = this.peek(index);
  6599. if (isIdentifierStart(char)) {
  6600. return null;
  6601. }
  6602. }
  6603. return {
  6604. type: Token.NumericLiteral,
  6605. value: value,
  6606. base: 16,
  6607. isMalformed: false
  6608. };
  6609. }
  6610. if (isOctalDigit(char)) {
  6611. index += 1;
  6612. value += char;
  6613. bad = false;
  6614. while (index < length) {
  6615. char = this.peek(index);
  6616. if (isDecimalDigit(char)) {
  6617. bad = true;
  6618. } else if (!isOctalDigit(char)) {
  6619. break;
  6620. }
  6621. value += char;
  6622. index += 1;
  6623. }
  6624. if (index < length) {
  6625. char = this.peek(index);
  6626. if (isIdentifierStart(char)) {
  6627. return null;
  6628. }
  6629. }
  6630. return {
  6631. type: Token.NumericLiteral,
  6632. value: value,
  6633. base: 8,
  6634. isMalformed: false
  6635. };
  6636. }
  6637. if (isDecimalDigit(char)) {
  6638. index += 1;
  6639. value += char;
  6640. }
  6641. }
  6642. while (index < length) {
  6643. char = this.peek(index);
  6644. if (!isDecimalDigit(char)) {
  6645. break;
  6646. }
  6647. value += char;
  6648. index += 1;
  6649. }
  6650. }
  6651. if (char === ".") {
  6652. value += char;
  6653. index += 1;
  6654. while (index < length) {
  6655. char = this.peek(index);
  6656. if (!isDecimalDigit(char)) {
  6657. break;
  6658. }
  6659. value += char;
  6660. index += 1;
  6661. }
  6662. }
  6663. if (char === "e" || char === "E") {
  6664. value += char;
  6665. index += 1;
  6666. char = this.peek(index);
  6667. if (char === "+" || char === "-") {
  6668. value += this.peek(index);
  6669. index += 1;
  6670. }
  6671. char = this.peek(index);
  6672. if (isDecimalDigit(char)) {
  6673. value += char;
  6674. index += 1;
  6675. while (index < length) {
  6676. char = this.peek(index);
  6677. if (!isDecimalDigit(char)) {
  6678. break;
  6679. }
  6680. value += char;
  6681. index += 1;
  6682. }
  6683. } else {
  6684. return null;
  6685. }
  6686. }
  6687. if (index < length) {
  6688. char = this.peek(index);
  6689. if (isIdentifierStart(char)) {
  6690. return null;
  6691. }
  6692. }
  6693. return {
  6694. type: Token.NumericLiteral,
  6695. value: value,
  6696. base: 10,
  6697. isMalformed: !isFinite(value)
  6698. };
  6699. },
  6700. scanTemplateLiteral: function () {
  6701. if (!state.option.esnext || this.peek() !== "`") {
  6702. return null;
  6703. }
  6704. var startLine = this.line;
  6705. var startChar = this.char;
  6706. var jump = 1;
  6707. var value = "";
  6708. this.skip();
  6709. while (this.peek() !== "`") {
  6710. while (this.peek() === "") {
  6711. if (!this.nextLine()) {
  6712. this.trigger("error", {
  6713. code: "E052",
  6714. line: startLine,
  6715. character: startChar
  6716. });
  6717. return {
  6718. type: Token.TemplateLiteral,
  6719. value: value,
  6720. isUnclosed: true
  6721. };
  6722. }
  6723. value += "\n";
  6724. }
  6725. var char = this.peek();
  6726. this.skip(jump);
  6727. value += char;
  6728. }
  6729. this.skip();
  6730. return {
  6731. type: Token.TemplateLiteral,
  6732. value: value,
  6733. isUnclosed: false
  6734. };
  6735. },
  6736. scanStringLiteral: function (checks) {
  6737. var quote = this.peek();
  6738. if (quote !== "\"" && quote !== "'") {
  6739. return null;
  6740. }
  6741. this.triggerAsync("warning", {
  6742. code: "W108",
  6743. line: this.line,
  6744. character: this.char // +1?
  6745. }, checks, function () { return state.jsonMode && quote !== "\""; });
  6746. var value = "";
  6747. var startLine = this.line;
  6748. var startChar = this.char;
  6749. var allowNewLine = false;
  6750. this.skip();
  6751. outer: while (this.peek() !== quote) {
  6752. while (this.peek() === "") { // End Of Line
  6753. if (!allowNewLine) {
  6754. this.trigger("warning", {
  6755. code: "W112",
  6756. line: this.line,
  6757. character: this.char
  6758. });
  6759. } else {
  6760. allowNewLine = false;
  6761. this.triggerAsync("warning", {
  6762. code: "W043",
  6763. line: this.line,
  6764. character: this.char
  6765. }, checks, function () { return !state.option.multistr; });
  6766. this.triggerAsync("warning", {
  6767. code: "W042",
  6768. line: this.line,
  6769. character: this.char
  6770. }, checks, function () { return state.jsonMode && state.option.multistr; });
  6771. }
  6772. if (!this.nextLine()) {
  6773. this.trigger("error", {
  6774. code: "E029",
  6775. line: startLine,
  6776. character: startChar
  6777. });
  6778. return {
  6779. type: Token.StringLiteral,
  6780. value: value,
  6781. isUnclosed: true,
  6782. quote: quote
  6783. };
  6784. }
  6785. if (this.peek() == quote)
  6786. break outer;
  6787. }
  6788. allowNewLine = false;
  6789. var char = this.peek();
  6790. var jump = 1; // A length of a jump, after we're done
  6791. if (char < " ") {
  6792. this.trigger("warning", {
  6793. code: "W113",
  6794. line: this.line,
  6795. character: this.char,
  6796. data: [ "<non-printable>" ]
  6797. });
  6798. }
  6799. if (char === "\\") {
  6800. this.skip();
  6801. char = this.peek();
  6802. switch (char) {
  6803. case "'":
  6804. this.triggerAsync("warning", {
  6805. code: "W114",
  6806. line: this.line,
  6807. character: this.char,
  6808. data: [ "\\'" ]
  6809. }, checks, function () {return state.jsonMode; });
  6810. break;
  6811. case "b":
  6812. char = "\\b";
  6813. break;
  6814. case "f":
  6815. char = "\\f";
  6816. break;
  6817. case "n":
  6818. char = "\\n";
  6819. break;
  6820. case "r":
  6821. char = "\\r";
  6822. break;
  6823. case "t":
  6824. char = "\\t";
  6825. break;
  6826. case "0":
  6827. char = "\\0";
  6828. var n = parseInt(this.peek(1), 10);
  6829. this.triggerAsync("warning", {
  6830. code: "W115",
  6831. line: this.line,
  6832. character: this.char
  6833. }, checks,
  6834. function () { return n >= 0 && n <= 7 && state.directive["use strict"]; });
  6835. break;
  6836. case "u":
  6837. char = String.fromCharCode(parseInt(this.input.substr(1, 4), 16));
  6838. jump = 5;
  6839. break;
  6840. case "v":
  6841. this.triggerAsync("warning", {
  6842. code: "W114",
  6843. line: this.line,
  6844. character: this.char,
  6845. data: [ "\\v" ]
  6846. }, checks, function () { return state.jsonMode; });
  6847. char = "\v";
  6848. break;
  6849. case "x":
  6850. var x = parseInt(this.input.substr(1, 2), 16);
  6851. this.triggerAsync("warning", {
  6852. code: "W114",
  6853. line: this.line,
  6854. character: this.char,
  6855. data: [ "\\x-" ]
  6856. }, checks, function () { return state.jsonMode; });
  6857. char = String.fromCharCode(x);
  6858. jump = 3;
  6859. break;
  6860. case "\\":
  6861. char = "\\\\";
  6862. break;
  6863. case "\"":
  6864. char = "\\\"";
  6865. break;
  6866. case "/":
  6867. break;
  6868. case "":
  6869. allowNewLine = true;
  6870. char = "";
  6871. break;
  6872. case "!":
  6873. if (value.slice(value.length - 2) === "<") {
  6874. break;
  6875. }
  6876. default:
  6877. this.trigger("warning", {
  6878. code: "W044",
  6879. line: this.line,
  6880. character: this.char
  6881. });
  6882. }
  6883. }
  6884. value += char;
  6885. this.skip(jump);
  6886. }
  6887. this.skip();
  6888. return {
  6889. type: Token.StringLiteral,
  6890. value: value,
  6891. isUnclosed: false,
  6892. quote: quote
  6893. };
  6894. },
  6895. scanRegExp: function () {
  6896. var index = 0;
  6897. var length = this.input.length;
  6898. var char = this.peek();
  6899. var value = char;
  6900. var body = "";
  6901. var flags = [];
  6902. var malformed = false;
  6903. var isCharSet = false;
  6904. var terminated;
  6905. var scanUnexpectedChars = function () {
  6906. if (char < " ") {
  6907. malformed = true;
  6908. this.trigger("warning", {
  6909. code: "W048",
  6910. line: this.line,
  6911. character: this.char
  6912. });
  6913. }
  6914. if (char === "<") {
  6915. malformed = true;
  6916. this.trigger("warning", {
  6917. code: "W049",
  6918. line: this.line,
  6919. character: this.char,
  6920. data: [ char ]
  6921. });
  6922. }
  6923. }.bind(this);
  6924. if (!this.prereg || char !== "/") {
  6925. return null;
  6926. }
  6927. index += 1;
  6928. terminated = false;
  6929. while (index < length) {
  6930. char = this.peek(index);
  6931. value += char;
  6932. body += char;
  6933. if (isCharSet) {
  6934. if (char === "]") {
  6935. if (this.peek(index - 1) !== "\\" || this.peek(index - 2) === "\\") {
  6936. isCharSet = false;
  6937. }
  6938. }
  6939. if (char === "\\") {
  6940. index += 1;
  6941. char = this.peek(index);
  6942. body += char;
  6943. value += char;
  6944. scanUnexpectedChars();
  6945. }
  6946. index += 1;
  6947. continue;
  6948. }
  6949. if (char === "\\") {
  6950. index += 1;
  6951. char = this.peek(index);
  6952. body += char;
  6953. value += char;
  6954. scanUnexpectedChars();
  6955. if (char === "/") {
  6956. index += 1;
  6957. continue;
  6958. }
  6959. if (char === "[") {
  6960. index += 1;
  6961. continue;
  6962. }
  6963. }
  6964. if (char === "[") {
  6965. isCharSet = true;
  6966. index += 1;
  6967. continue;
  6968. }
  6969. if (char === "/") {
  6970. body = body.substr(0, body.length - 1);
  6971. terminated = true;
  6972. index += 1;
  6973. break;
  6974. }
  6975. index += 1;
  6976. }
  6977. if (!terminated) {
  6978. this.trigger("error", {
  6979. code: "E015",
  6980. line: this.line,
  6981. character: this.from
  6982. });
  6983. return void this.trigger("fatal", {
  6984. line: this.line,
  6985. from: this.from
  6986. });
  6987. }
  6988. while (index < length) {
  6989. char = this.peek(index);
  6990. if (!/[gim]/.test(char)) {
  6991. break;
  6992. }
  6993. flags.push(char);
  6994. value += char;
  6995. index += 1;
  6996. }
  6997. try {
  6998. new RegExp(body, flags.join(""));
  6999. } catch (err) {
  7000. malformed = true;
  7001. this.trigger("error", {
  7002. code: "E016",
  7003. line: this.line,
  7004. character: this.char,
  7005. data: [ err.message ] // Platform dependent!
  7006. });
  7007. }
  7008. return {
  7009. type: Token.RegExp,
  7010. value: value,
  7011. flags: flags,
  7012. isMalformed: malformed
  7013. };
  7014. },
  7015. scanNonBreakingSpaces: function () {
  7016. return state.option.nonbsp ?
  7017. this.input.search(/(\u00A0)/) : -1;
  7018. },
  7019. scanUnsafeChars: function () {
  7020. return this.input.search(reg.unsafeChars);
  7021. },
  7022. next: function (checks) {
  7023. this.from = this.char;
  7024. var start;
  7025. if (/\s/.test(this.peek())) {
  7026. start = this.char;
  7027. while (/\s/.test(this.peek())) {
  7028. this.from += 1;
  7029. this.skip();
  7030. }
  7031. }
  7032. var match = this.scanComments() ||
  7033. this.scanStringLiteral(checks) ||
  7034. this.scanTemplateLiteral();
  7035. if (match) {
  7036. return match;
  7037. }
  7038. match =
  7039. this.scanRegExp() ||
  7040. this.scanPunctuator() ||
  7041. this.scanKeyword() ||
  7042. this.scanIdentifier() ||
  7043. this.scanNumericLiteral();
  7044. if (match) {
  7045. this.skip(match.value.length);
  7046. return match;
  7047. }
  7048. return null;
  7049. },
  7050. nextLine: function () {
  7051. var char;
  7052. if (this.line >= this.getLines().length) {
  7053. return false;
  7054. }
  7055. this.input = this.getLines()[this.line];
  7056. this.line += 1;
  7057. this.char = 1;
  7058. this.from = 1;
  7059. var inputTrimmed = this.input.trim();
  7060. var startsWith = function () {
  7061. return _.some(arguments, function (prefix) {
  7062. return inputTrimmed.indexOf(prefix) === 0;
  7063. });
  7064. };
  7065. var endsWith = function () {
  7066. return _.some(arguments, function (suffix) {
  7067. return inputTrimmed.indexOf(suffix, inputTrimmed.length - suffix.length) !== -1;
  7068. });
  7069. };
  7070. if (state.ignoreLinterErrors === true) {
  7071. if (!startsWith("/*", "//") && !endsWith("*/")) {
  7072. this.input = "";
  7073. }
  7074. }
  7075. char = this.scanNonBreakingSpaces();
  7076. if (char >= 0) {
  7077. this.trigger("warning", { code: "W125", line: this.line, character: char + 1 });
  7078. }
  7079. this.input = this.input.replace(/\t/g, state.tab);
  7080. char = this.scanUnsafeChars();
  7081. if (char >= 0) {
  7082. this.trigger("warning", { code: "W100", line: this.line, character: char });
  7083. }
  7084. if (state.option.maxlen && state.option.maxlen < this.input.length) {
  7085. var inComment = this.inComment ||
  7086. startsWith.call(inputTrimmed, "//") ||
  7087. startsWith.call(inputTrimmed, "/*");
  7088. var shouldTriggerError = !inComment || !reg.maxlenException.test(inputTrimmed);
  7089. if (shouldTriggerError) {
  7090. this.trigger("warning", { code: "W101", line: this.line, character: this.input.length });
  7091. }
  7092. }
  7093. return true;
  7094. },
  7095. start: function () {
  7096. this.nextLine();
  7097. },
  7098. token: function () {
  7099. var checks = asyncTrigger();
  7100. var token;
  7101. function isReserved(token, isProperty) {
  7102. if (!token.reserved) {
  7103. return false;
  7104. }
  7105. var meta = token.meta;
  7106. if (meta && meta.isFutureReservedWord && state.option.inES5()) {
  7107. if (!meta.es5) {
  7108. return false;
  7109. }
  7110. if (meta.strictOnly) {
  7111. if (!state.option.strict && !state.directive["use strict"]) {
  7112. return false;
  7113. }
  7114. }
  7115. if (isProperty) {
  7116. return false;
  7117. }
  7118. }
  7119. return true;
  7120. }
  7121. var create = function (type, value, isProperty) {
  7122. var obj;
  7123. if (type !== "(endline)" && type !== "(end)") {
  7124. this.prereg = false;
  7125. }
  7126. if (type === "(punctuator)") {
  7127. switch (value) {
  7128. case ".":
  7129. case ")":
  7130. case "~":
  7131. case "#":
  7132. case "]":
  7133. this.prereg = false;
  7134. break;
  7135. default:
  7136. this.prereg = true;
  7137. }
  7138. obj = Object.create(state.syntax[value] || state.syntax["(error)"]);
  7139. }
  7140. if (type === "(identifier)") {
  7141. if (value === "return" || value === "case" || value === "typeof") {
  7142. this.prereg = true;
  7143. }
  7144. if (_.has(state.syntax, value)) {
  7145. obj = Object.create(state.syntax[value] || state.syntax["(error)"]);
  7146. if (!isReserved(obj, isProperty && type === "(identifier)")) {
  7147. obj = null;
  7148. }
  7149. }
  7150. }
  7151. if (!obj) {
  7152. obj = Object.create(state.syntax[type]);
  7153. }
  7154. obj.identifier = (type === "(identifier)");
  7155. obj.type = obj.type || type;
  7156. obj.value = value;
  7157. obj.line = this.line;
  7158. obj.character = this.char;
  7159. obj.from = this.from;
  7160. if (isProperty && obj.identifier) {
  7161. obj.isProperty = isProperty;
  7162. }
  7163. obj.check = checks.check;
  7164. return obj;
  7165. }.bind(this);
  7166. for (;;) {
  7167. if (!this.input.length) {
  7168. return create(this.nextLine() ? "(endline)" : "(end)", "");
  7169. }
  7170. token = this.next(checks);
  7171. if (!token) {
  7172. if (this.input.length) {
  7173. this.trigger("error", {
  7174. code: "E024",
  7175. line: this.line,
  7176. character: this.char,
  7177. data: [ this.peek() ]
  7178. });
  7179. this.input = "";
  7180. }
  7181. continue;
  7182. }
  7183. switch (token.type) {
  7184. case Token.StringLiteral:
  7185. this.triggerAsync("String", {
  7186. line: this.line,
  7187. char: this.char,
  7188. from: this.from,
  7189. value: token.value,
  7190. quote: token.quote
  7191. }, checks, function () { return true; });
  7192. return create("(string)", token.value);
  7193. case Token.TemplateLiteral:
  7194. this.trigger("Template", {
  7195. line: this.line,
  7196. char: this.char,
  7197. from: this.from,
  7198. value: token.value
  7199. });
  7200. return create("(template)", token.value);
  7201. case Token.Identifier:
  7202. this.trigger("Identifier", {
  7203. line: this.line,
  7204. char: this.char,
  7205. from: this.form,
  7206. name: token.value,
  7207. isProperty: state.tokens.curr.id === "."
  7208. });
  7209. case Token.Keyword:
  7210. case Token.NullLiteral:
  7211. case Token.BooleanLiteral:
  7212. return create("(identifier)", token.value, state.tokens.curr.id === ".");
  7213. case Token.NumericLiteral:
  7214. if (token.isMalformed) {
  7215. this.trigger("warning", {
  7216. code: "W045",
  7217. line: this.line,
  7218. character: this.char,
  7219. data: [ token.value ]
  7220. });
  7221. }
  7222. this.triggerAsync("warning", {
  7223. code: "W114",
  7224. line: this.line,
  7225. character: this.char,
  7226. data: [ "0x-" ]
  7227. }, checks, function () { return token.base === 16 && state.jsonMode; });
  7228. this.triggerAsync("warning", {
  7229. code: "W115",
  7230. line: this.line,
  7231. character: this.char
  7232. }, checks, function () {
  7233. return state.directive["use strict"] && token.base === 8;
  7234. });
  7235. this.trigger("Number", {
  7236. line: this.line,
  7237. char: this.char,
  7238. from: this.from,
  7239. value: token.value,
  7240. base: token.base,
  7241. isMalformed: token.malformed
  7242. });
  7243. return create("(number)", token.value);
  7244. case Token.RegExp:
  7245. return create("(regexp)", token.value);
  7246. case Token.Comment:
  7247. state.tokens.curr.comment = true;
  7248. if (token.isSpecial) {
  7249. return {
  7250. id: '(comment)',
  7251. value: token.value,
  7252. body: token.body,
  7253. type: token.commentType,
  7254. isSpecial: token.isSpecial,
  7255. line: this.line,
  7256. character: this.char,
  7257. from: this.from
  7258. };
  7259. }
  7260. break;
  7261. case "":
  7262. break;
  7263. default:
  7264. return create("(punctuator)", token.value);
  7265. }
  7266. }
  7267. }
  7268. };
  7269. exports.Lexer = Lexer;
  7270. },
  7271. {"../data/ascii-identifier-data.js":1,"./reg.js":6,"./state.js":7,"events":10,"underscore":2}],
  7272. 5:[function(_dereq_,module,exports){
  7273. "use strict";
  7274. var _ = _dereq_("underscore");
  7275. var errors = {
  7276. E001: "Bad option: '{a}'.",
  7277. E002: "Bad option value.",
  7278. E003: "Expected a JSON value.",
  7279. E004: "Input is neither a string nor an array of strings.",
  7280. E005: "Input is empty.",
  7281. E006: "Unexpected early end of program.",
  7282. E007: "Missing \"use strict\" statement.",
  7283. E008: "Strict violation.",
  7284. E009: "Option 'validthis' can't be used in a global scope.",
  7285. E010: "'with' is not allowed in strict mode.",
  7286. E011: "const '{a}' has already been declared.",
  7287. E012: "const '{a}' is initialized to 'undefined'.",
  7288. E013: "Attempting to override '{a}' which is a constant.",
  7289. E014: "A regular expression literal can be confused with '/='.",
  7290. E015: "Unclosed regular expression.",
  7291. E016: "Invalid regular expression.",
  7292. E017: "Unclosed comment.",
  7293. E018: "Unbegun comment.",
  7294. E019: "Unmatched '{a}'.",
  7295. E020: "Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.",
  7296. E021: "Expected '{a}' and instead saw '{b}'.",
  7297. E022: "Line breaking error '{a}'.",
  7298. E023: "Missing '{a}'.",
  7299. E024: "Unexpected '{a}'.",
  7300. E025: "Missing ':' on a case clause.",
  7301. E026: "Missing '}' to match '{' from line {a}.",
  7302. E027: "Missing ']' to match '[' from line {a}.",
  7303. E028: "Illegal comma.",
  7304. E029: "Unclosed string.",
  7305. E030: "Expected an identifier and instead saw '{a}'.",
  7306. E031: "Bad assignment.", // FIXME: Rephrase
  7307. E032: "Expected a small integer or 'false' and instead saw '{a}'.",
  7308. E033: "Expected an operator and instead saw '{a}'.",
  7309. E034: "get/set are ES5 features.",
  7310. E035: "Missing property name.",
  7311. E036: "Expected to see a statement and instead saw a block.",
  7312. E037: null,
  7313. E038: null,
  7314. E039: "Function declarations are not invocable. Wrap the whole function invocation in parens.",
  7315. E040: "Each value should have its own case label.",
  7316. E041: "Unrecoverable syntax error.",
  7317. E042: "Stopping.",
  7318. E043: "Too many errors.",
  7319. E044: null,
  7320. E045: "Invalid for each loop.",
  7321. E046: "A yield statement shall be within a generator function (with syntax: `function*`)",
  7322. E047: null, // Vacant
  7323. E048: "Let declaration not directly within block.",
  7324. E049: "A {a} cannot be named '{b}'.",
  7325. E050: "Mozilla requires the yield expression to be parenthesized here.",
  7326. E051: "Regular parameters cannot come after default parameters.",
  7327. E052: "Unclosed template literal."
  7328. };
  7329. var warnings = {
  7330. W001: "'hasOwnProperty' is a really bad name.",
  7331. W002: "Value of '{a}' may be overwritten in IE 8 and earlier.",
  7332. W003: "'{a}' was used before it was defined.",
  7333. W004: "'{a}' is already defined.",
  7334. W005: "A dot following a number can be confused with a decimal point.",
  7335. W006: "Confusing minuses.",
  7336. W007: "Confusing plusses.",
  7337. W008: "A leading decimal point can be confused with a dot: '{a}'.",
  7338. W009: "The array literal notation [] is preferable.",
  7339. W010: "The object literal notation {} is preferable.",
  7340. W011: null,
  7341. W012: null,
  7342. W013: null,
  7343. W014: "Bad line breaking before '{a}'.",
  7344. W015: null,
  7345. W016: "Unexpected use of '{a}'.",
  7346. W017: "Bad operand.",
  7347. W018: "Confusing use of '{a}'.",
  7348. W019: "Use the isNaN function to compare with NaN.",
  7349. W020: "Read only.",
  7350. W021: "'{a}' is a function.",
  7351. W022: "Do not assign to the exception parameter.",
  7352. W023: "Expected an identifier in an assignment and instead saw a function invocation.",
  7353. W024: "Expected an identifier and instead saw '{a}' (a reserved word).",
  7354. W025: "Missing name in function declaration.",
  7355. W026: "Inner functions should be listed at the top of the outer function.",
  7356. W027: "Unreachable '{a}' after '{b}'.",
  7357. W028: "Label '{a}' on {b} statement.",
  7358. W030: "Expected an assignment or function call and instead saw an expression.",
  7359. W031: "Do not use 'new' for side effects.",
  7360. W032: "Unnecessary semicolon.",
  7361. W033: "Missing semicolon.",
  7362. W034: "Unnecessary directive \"{a}\".",
  7363. W035: "Empty block.",
  7364. W036: "Unexpected /*member '{a}'.",
  7365. W037: "'{a}' is a statement label.",
  7366. W038: "'{a}' used out of scope.",
  7367. W039: "'{a}' is not allowed.",
  7368. W040: "Possible strict violation.",
  7369. W041: "Use '{a}' to compare with '{b}'.",
  7370. W042: "Avoid EOL escaping.",
  7371. W043: "Bad escaping of EOL. Use option multistr if needed.",
  7372. W044: "Bad or unnecessary escaping.",
  7373. W045: "Bad number '{a}'.",
  7374. W046: "Don't use extra leading zeros '{a}'.",
  7375. W047: "A trailing decimal point can be confused with a dot: '{a}'.",
  7376. W048: "Unexpected control character in regular expression.",
  7377. W049: "Unexpected escaped character '{a}' in regular expression.",
  7378. W050: "JavaScript URL.",
  7379. W051: "Variables should not be deleted.",
  7380. W052: "Unexpected '{a}'.",
  7381. W053: "Do not use {a} as a constructor.",
  7382. W054: "The Function constructor is a form of eval.",
  7383. W055: "A constructor name should start with an uppercase letter.",
  7384. W056: "Bad constructor.",
  7385. W057: "Weird construction. Is 'new' necessary?",
  7386. W058: "Missing '()' invoking a constructor.",
  7387. W059: "Avoid arguments.{a}.",
  7388. W060: "document.write can be a form of eval.",
  7389. W061: "eval can be harmful.",
  7390. W062: "Wrap an immediate function invocation in parens " +
  7391. "to assist the reader in understanding that the expression " +
  7392. "is the result of a function, and not the function itself.",
  7393. W063: "Math is not a function.",
  7394. W064: "Missing 'new' prefix when invoking a constructor.",
  7395. W065: "Missing radix parameter.",
  7396. W066: "Implied eval. Consider passing a function instead of a string.",
  7397. W067: "Bad invocation.",
  7398. W068: "Wrapping non-IIFE function literals in parens is unnecessary.",
  7399. W069: "['{a}'] is better written in dot notation.",
  7400. W070: "Extra comma. (it breaks older versions of IE)",
  7401. W071: "This function has too many statements. ({a})",
  7402. W072: "This function has too many parameters. ({a})",
  7403. W073: "Blocks are nested too deeply. ({a})",
  7404. W074: "This function's cyclomatic complexity is too high. ({a})",
  7405. W075: "Duplicate key '{a}'.",
  7406. W076: "Unexpected parameter '{a}' in get {b} function.",
  7407. W077: "Expected a single parameter in set {a} function.",
  7408. W078: "Setter is defined without getter.",
  7409. W079: "Redefinition of '{a}'.",
  7410. W080: "It's not necessary to initialize '{a}' to 'undefined'.",
  7411. W081: null,
  7412. W082: "Function declarations should not be placed in blocks. " +
  7413. "Use a function expression or move the statement to the top of " +
  7414. "the outer function.",
  7415. W083: "Don't make functions within a loop.",
  7416. W084: "Assignment in conditional expression",
  7417. W085: "Don't use 'with'.",
  7418. W086: "Expected a 'break' statement before '{a}'.",
  7419. W087: "Forgotten 'debugger' statement?",
  7420. W088: "Creating global 'for' variable. Should be 'for (var {a} ...'.",
  7421. W089: "The body of a for in should be wrapped in an if statement to filter " +
  7422. "unwanted properties from the prototype.",
  7423. W090: "'{a}' is not a statement label.",
  7424. W091: "'{a}' is out of scope.",
  7425. W093: "Did you mean to return a conditional instead of an assignment?",
  7426. W094: "Unexpected comma.",
  7427. W095: "Expected a string and instead saw {a}.",
  7428. W096: "The '{a}' key may produce unexpected results.",
  7429. W097: "Use the function form of \"use strict\".",
  7430. W098: "'{a}' is defined but never used.",
  7431. W099: null,
  7432. W100: "This character may get silently deleted by one or more browsers.",
  7433. W101: "Line is too long.",
  7434. W102: null,
  7435. W103: "The '{a}' property is deprecated.",
  7436. W104: "'{a}' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).",
  7437. W105: "Unexpected {a} in '{b}'.",
  7438. W106: "Identifier '{a}' is not in camel case.",
  7439. W107: "Script URL.",
  7440. W108: "Strings must use doublequote.",
  7441. W109: "Strings must use singlequote.",
  7442. W110: "Mixed double and single quotes.",
  7443. W112: "Unclosed string.",
  7444. W113: "Control character in string: {a}.",
  7445. W114: "Avoid {a}.",
  7446. W115: "Octal literals are not allowed in strict mode.",
  7447. W116: "Expected '{a}' and instead saw '{b}'.",
  7448. W117: "'{a}' is not defined.",
  7449. W118: "'{a}' is only available in Mozilla JavaScript extensions (use moz option).",
  7450. W119: "'{a}' is only available in ES6 (use esnext option).",
  7451. W120: "You might be leaking a variable ({a}) here.",
  7452. W121: "Extending prototype of native object: '{a}'.",
  7453. W122: "Invalid typeof value '{a}'",
  7454. W123: "'{a}' is already defined in outer scope.",
  7455. W124: "A generator function shall contain a yield statement.",
  7456. W125: "This line contains non-breaking spaces: http://jshint.com/doc/options/#nonbsp"
  7457. };
  7458. var info = {
  7459. I001: "Comma warnings can be turned off with 'laxcomma'.",
  7460. I002: null,
  7461. I003: "ES5 option is now set per default"
  7462. };
  7463. exports.errors = {};
  7464. exports.warnings = {};
  7465. exports.info = {};
  7466. _.each(errors, function (desc, code) {
  7467. exports.errors[code] = { code: code, desc: desc };
  7468. });
  7469. _.each(warnings, function (desc, code) {
  7470. exports.warnings[code] = { code: code, desc: desc };
  7471. });
  7472. _.each(info, function (desc, code) {
  7473. exports.info[code] = { code: code, desc: desc };
  7474. });
  7475. },
  7476. {"underscore":2}],
  7477. 6:[function(_dereq_,module,exports){
  7478. "use string";
  7479. exports.unsafeString =
  7480. /@cc|<\/?|script|\]\s*\]|<\s*!|&lt/i;
  7481. exports.unsafeChars =
  7482. /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
  7483. exports.needEsc =
  7484. /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
  7485. exports.needEscGlobal =
  7486. /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  7487. exports.starSlash = /\*\//;
  7488. exports.identifier = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/;
  7489. exports.javascriptURL = /^(?:javascript|jscript|ecmascript|vbscript|livescript)\s*:/i;
  7490. exports.fallsThrough = /^\s*\/\*\s*falls?\sthrough\s*\*\/\s*$/;
  7491. exports.maxlenException = /^(?:(?:\/\/|\/\*|\*) ?)?[^ ]+$/;
  7492. },
  7493. {}],
  7494. 7:[function(_dereq_,module,exports){
  7495. "use strict";
  7496. var state = {
  7497. syntax: {},
  7498. reset: function () {
  7499. this.tokens = {
  7500. prev: null,
  7501. next: null,
  7502. curr: null
  7503. };
  7504. this.option = {};
  7505. this.ignored = {};
  7506. this.directive = {};
  7507. this.jsonMode = false;
  7508. this.jsonWarnings = [];
  7509. this.lines = [];
  7510. this.tab = "";
  7511. this.cache = {}; // Node.JS doesn't have Map. Sniff.
  7512. this.ignoredLines = {};
  7513. this.ignoreLinterErrors = false;
  7514. }
  7515. };
  7516. exports.state = state;
  7517. },
  7518. {}],
  7519. 8:[function(_dereq_,module,exports){
  7520. "use strict";
  7521. exports.register = function (linter) {
  7522. linter.on("Identifier", function style_scanProto(data) {
  7523. if (linter.getOption("proto")) {
  7524. return;
  7525. }
  7526. if (data.name === "__proto__") {
  7527. linter.warn("W103", {
  7528. line: data.line,
  7529. char: data.char,
  7530. data: [ data.name ]
  7531. });
  7532. }
  7533. });
  7534. linter.on("Identifier", function style_scanIterator(data) {
  7535. if (linter.getOption("iterator")) {
  7536. return;
  7537. }
  7538. if (data.name === "__iterator__") {
  7539. linter.warn("W104", {
  7540. line: data.line,
  7541. char: data.char,
  7542. data: [ data.name ]
  7543. });
  7544. }
  7545. });
  7546. linter.on("Identifier", function style_scanCamelCase(data) {
  7547. if (!linter.getOption("camelcase")) {
  7548. return;
  7549. }
  7550. if (data.name.replace(/^_+|_+$/g, "").indexOf("_") > -1 && !data.name.match(/^[A-Z0-9_]*$/)) {
  7551. linter.warn("W106", {
  7552. line: data.line,
  7553. char: data.from,
  7554. data: [ data.name ]
  7555. });
  7556. }
  7557. });
  7558. linter.on("String", function style_scanQuotes(data) {
  7559. var quotmark = linter.getOption("quotmark");
  7560. var code;
  7561. if (!quotmark) {
  7562. return;
  7563. }
  7564. if (quotmark === "single" && data.quote !== "'") {
  7565. code = "W109";
  7566. }
  7567. if (quotmark === "double" && data.quote !== "\"") {
  7568. code = "W108";
  7569. }
  7570. if (quotmark === true) {
  7571. if (!linter.getCache("quotmark")) {
  7572. linter.setCache("quotmark", data.quote);
  7573. }
  7574. if (linter.getCache("quotmark") !== data.quote) {
  7575. code = "W110";
  7576. }
  7577. }
  7578. if (code) {
  7579. linter.warn(code, {
  7580. line: data.line,
  7581. char: data.char,
  7582. });
  7583. }
  7584. });
  7585. linter.on("Number", function style_scanNumbers(data) {
  7586. if (data.value.charAt(0) === ".") {
  7587. linter.warn("W008", {
  7588. line: data.line,
  7589. char: data.char,
  7590. data: [ data.value ]
  7591. });
  7592. }
  7593. if (data.value.substr(data.value.length - 1) === ".") {
  7594. linter.warn("W047", {
  7595. line: data.line,
  7596. char: data.char,
  7597. data: [ data.value ]
  7598. });
  7599. }
  7600. if (/^00+/.test(data.value)) {
  7601. linter.warn("W046", {
  7602. line: data.line,
  7603. char: data.char,
  7604. data: [ data.value ]
  7605. });
  7606. }
  7607. });
  7608. linter.on("String", function style_scanJavaScriptURLs(data) {
  7609. var re = /^(?:javascript|jscript|ecmascript|vbscript|livescript)\s*:/i;
  7610. if (linter.getOption("scripturl")) {
  7611. return;
  7612. }
  7613. if (re.test(data.value)) {
  7614. linter.warn("W107", {
  7615. line: data.line,
  7616. char: data.char
  7617. });
  7618. }
  7619. });
  7620. };
  7621. },
  7622. {}],
  7623. 9:[function(_dereq_,module,exports){
  7624. "use strict";
  7625. exports.reservedVars = {
  7626. arguments : false,
  7627. NaN : false
  7628. };
  7629. exports.ecmaIdentifiers = {
  7630. Array : false,
  7631. Boolean : false,
  7632. Date : false,
  7633. decodeURI : false,
  7634. decodeURIComponent : false,
  7635. encodeURI : false,
  7636. encodeURIComponent : false,
  7637. Error : false,
  7638. "eval" : false,
  7639. EvalError : false,
  7640. Function : false,
  7641. hasOwnProperty : false,
  7642. isFinite : false,
  7643. isNaN : false,
  7644. JSON : false,
  7645. Math : false,
  7646. Number : false,
  7647. Object : false,
  7648. parseInt : false,
  7649. parseFloat : false,
  7650. RangeError : false,
  7651. ReferenceError : false,
  7652. RegExp : false,
  7653. String : false,
  7654. SyntaxError : false,
  7655. TypeError : false,
  7656. URIError : false,
  7657. };
  7658. exports.newEcmaIdentifiers = {
  7659. Set : false,
  7660. Map : false,
  7661. WeakMap : false,
  7662. WeakSet : false,
  7663. Proxy : false,
  7664. Promise : false
  7665. };
  7666. exports.browser = {
  7667. Audio : false,
  7668. Blob : false,
  7669. addEventListener : false,
  7670. applicationCache : false,
  7671. atob : false,
  7672. blur : false,
  7673. btoa : false,
  7674. CanvasGradient : false,
  7675. CanvasPattern : false,
  7676. CanvasRenderingContext2D: false,
  7677. clearInterval : false,
  7678. clearTimeout : false,
  7679. close : false,
  7680. closed : false,
  7681. CustomEvent : false,
  7682. DOMParser : false,
  7683. defaultStatus : false,
  7684. document : false,
  7685. Element : false,
  7686. ElementTimeControl : false,
  7687. event : false,
  7688. FileReader : false,
  7689. FormData : false,
  7690. focus : false,
  7691. frames : false,
  7692. getComputedStyle : false,
  7693. HTMLElement : false,
  7694. HTMLAnchorElement : false,
  7695. HTMLBaseElement : false,
  7696. HTMLBlockquoteElement: false,
  7697. HTMLBodyElement : false,
  7698. HTMLBRElement : false,
  7699. HTMLButtonElement : false,
  7700. HTMLCanvasElement : false,
  7701. HTMLDirectoryElement : false,
  7702. HTMLDivElement : false,
  7703. HTMLDListElement : false,
  7704. HTMLFieldSetElement : false,
  7705. HTMLFontElement : false,
  7706. HTMLFormElement : false,
  7707. HTMLFrameElement : false,
  7708. HTMLFrameSetElement : false,
  7709. HTMLHeadElement : false,
  7710. HTMLHeadingElement : false,
  7711. HTMLHRElement : false,
  7712. HTMLHtmlElement : false,
  7713. HTMLIFrameElement : false,
  7714. HTMLImageElement : false,
  7715. HTMLInputElement : false,
  7716. HTMLIsIndexElement : false,
  7717. HTMLLabelElement : false,
  7718. HTMLLayerElement : false,
  7719. HTMLLegendElement : false,
  7720. HTMLLIElement : false,
  7721. HTMLLinkElement : false,
  7722. HTMLMapElement : false,
  7723. HTMLMenuElement : false,
  7724. HTMLMetaElement : false,
  7725. HTMLModElement : false,
  7726. HTMLObjectElement : false,
  7727. HTMLOListElement : false,
  7728. HTMLOptGroupElement : false,
  7729. HTMLOptionElement : false,
  7730. HTMLParagraphElement : false,
  7731. HTMLParamElement : false,
  7732. HTMLPreElement : false,
  7733. HTMLQuoteElement : false,
  7734. HTMLScriptElement : false,
  7735. HTMLSelectElement : false,
  7736. HTMLStyleElement : false,
  7737. HTMLTableCaptionElement: false,
  7738. HTMLTableCellElement : false,
  7739. HTMLTableColElement : false,
  7740. HTMLTableElement : false,
  7741. HTMLTableRowElement : false,
  7742. HTMLTableSectionElement: false,
  7743. HTMLTextAreaElement : false,
  7744. HTMLTitleElement : false,
  7745. HTMLUListElement : false,
  7746. HTMLVideoElement : false,
  7747. history : false,
  7748. Image : false,
  7749. length : false,
  7750. localStorage : false,
  7751. location : false,
  7752. matchMedia : false,
  7753. MessageChannel : false,
  7754. MessageEvent : false,
  7755. MessagePort : false,
  7756. MouseEvent : false,
  7757. moveBy : false,
  7758. moveTo : false,
  7759. MutationObserver : false,
  7760. name : false,
  7761. Node : false,
  7762. NodeFilter : false,
  7763. NodeList : false,
  7764. navigator : false,
  7765. onbeforeunload : true,
  7766. onblur : true,
  7767. onerror : true,
  7768. onfocus : true,
  7769. onload : true,
  7770. onresize : true,
  7771. onunload : true,
  7772. open : false,
  7773. openDatabase : false,
  7774. opener : false,
  7775. Option : false,
  7776. parent : false,
  7777. print : false,
  7778. removeEventListener : false,
  7779. resizeBy : false,
  7780. resizeTo : false,
  7781. screen : false,
  7782. scroll : false,
  7783. scrollBy : false,
  7784. scrollTo : false,
  7785. sessionStorage : false,
  7786. setInterval : false,
  7787. setTimeout : false,
  7788. SharedWorker : false,
  7789. status : false,
  7790. SVGAElement : false,
  7791. SVGAltGlyphDefElement: false,
  7792. SVGAltGlyphElement : false,
  7793. SVGAltGlyphItemElement: false,
  7794. SVGAngle : false,
  7795. SVGAnimateColorElement: false,
  7796. SVGAnimateElement : false,
  7797. SVGAnimateMotionElement: false,
  7798. SVGAnimateTransformElement: false,
  7799. SVGAnimatedAngle : false,
  7800. SVGAnimatedBoolean : false,
  7801. SVGAnimatedEnumeration: false,
  7802. SVGAnimatedInteger : false,
  7803. SVGAnimatedLength : false,
  7804. SVGAnimatedLengthList: false,
  7805. SVGAnimatedNumber : false,
  7806. SVGAnimatedNumberList: false,
  7807. SVGAnimatedPathData : false,
  7808. SVGAnimatedPoints : false,
  7809. SVGAnimatedPreserveAspectRatio: false,
  7810. SVGAnimatedRect : false,
  7811. SVGAnimatedString : false,
  7812. SVGAnimatedTransformList: false,
  7813. SVGAnimationElement : false,
  7814. SVGCSSRule : false,
  7815. SVGCircleElement : false,
  7816. SVGClipPathElement : false,
  7817. SVGColor : false,
  7818. SVGColorProfileElement: false,
  7819. SVGColorProfileRule : false,
  7820. SVGComponentTransferFunctionElement: false,
  7821. SVGCursorElement : false,
  7822. SVGDefsElement : false,
  7823. SVGDescElement : false,
  7824. SVGDocument : false,
  7825. SVGElement : false,
  7826. SVGElementInstance : false,
  7827. SVGElementInstanceList: false,
  7828. SVGEllipseElement : false,
  7829. SVGExternalResourcesRequired: false,
  7830. SVGFEBlendElement : false,
  7831. SVGFEColorMatrixElement: false,
  7832. SVGFEComponentTransferElement: false,
  7833. SVGFECompositeElement: false,
  7834. SVGFEConvolveMatrixElement: false,
  7835. SVGFEDiffuseLightingElement: false,
  7836. SVGFEDisplacementMapElement: false,
  7837. SVGFEDistantLightElement: false,
  7838. SVGFEFloodElement : false,
  7839. SVGFEFuncAElement : false,
  7840. SVGFEFuncBElement : false,
  7841. SVGFEFuncGElement : false,
  7842. SVGFEFuncRElement : false,
  7843. SVGFEGaussianBlurElement: false,
  7844. SVGFEImageElement : false,
  7845. SVGFEMergeElement : false,
  7846. SVGFEMergeNodeElement: false,
  7847. SVGFEMorphologyElement: false,
  7848. SVGFEOffsetElement : false,
  7849. SVGFEPointLightElement: false,
  7850. SVGFESpecularLightingElement: false,
  7851. SVGFESpotLightElement: false,
  7852. SVGFETileElement : false,
  7853. SVGFETurbulenceElement: false,
  7854. SVGFilterElement : false,
  7855. SVGFilterPrimitiveStandardAttributes: false,
  7856. SVGFitToViewBox : false,
  7857. SVGFontElement : false,
  7858. SVGFontFaceElement : false,
  7859. SVGFontFaceFormatElement: false,
  7860. SVGFontFaceNameElement: false,
  7861. SVGFontFaceSrcElement: false,
  7862. SVGFontFaceUriElement: false,
  7863. SVGForeignObjectElement: false,
  7864. SVGGElement : false,
  7865. SVGGlyphElement : false,
  7866. SVGGlyphRefElement : false,
  7867. SVGGradientElement : false,
  7868. SVGHKernElement : false,
  7869. SVGICCColor : false,
  7870. SVGImageElement : false,
  7871. SVGLangSpace : false,
  7872. SVGLength : false,
  7873. SVGLengthList : false,
  7874. SVGLineElement : false,
  7875. SVGLinearGradientElement: false,
  7876. SVGLocatable : false,
  7877. SVGMPathElement : false,
  7878. SVGMarkerElement : false,
  7879. SVGMaskElement : false,
  7880. SVGMatrix : false,
  7881. SVGMetadataElement : false,
  7882. SVGMissingGlyphElement: false,
  7883. SVGNumber : false,
  7884. SVGNumberList : false,
  7885. SVGPaint : false,
  7886. SVGPathElement : false,
  7887. SVGPathSeg : false,
  7888. SVGPathSegArcAbs : false,
  7889. SVGPathSegArcRel : false,
  7890. SVGPathSegClosePath : false,
  7891. SVGPathSegCurvetoCubicAbs: false,
  7892. SVGPathSegCurvetoCubicRel: false,
  7893. SVGPathSegCurvetoCubicSmoothAbs: false,
  7894. SVGPathSegCurvetoCubicSmoothRel: false,
  7895. SVGPathSegCurvetoQuadraticAbs: false,
  7896. SVGPathSegCurvetoQuadraticRel: false,
  7897. SVGPathSegCurvetoQuadraticSmoothAbs: false,
  7898. SVGPathSegCurvetoQuadraticSmoothRel: false,
  7899. SVGPathSegLinetoAbs : false,
  7900. SVGPathSegLinetoHorizontalAbs: false,
  7901. SVGPathSegLinetoHorizontalRel: false,
  7902. SVGPathSegLinetoRel : false,
  7903. SVGPathSegLinetoVerticalAbs: false,
  7904. SVGPathSegLinetoVerticalRel: false,
  7905. SVGPathSegList : false,
  7906. SVGPathSegMovetoAbs : false,
  7907. SVGPathSegMovetoRel : false,
  7908. SVGPatternElement : false,
  7909. SVGPoint : false,
  7910. SVGPointList : false,
  7911. SVGPolygonElement : false,
  7912. SVGPolylineElement : false,
  7913. SVGPreserveAspectRatio: false,
  7914. SVGRadialGradientElement: false,
  7915. SVGRect : false,
  7916. SVGRectElement : false,
  7917. SVGRenderingIntent : false,
  7918. SVGSVGElement : false,
  7919. SVGScriptElement : false,
  7920. SVGSetElement : false,
  7921. SVGStopElement : false,
  7922. SVGStringList : false,
  7923. SVGStylable : false,
  7924. SVGStyleElement : false,
  7925. SVGSwitchElement : false,
  7926. SVGSymbolElement : false,
  7927. SVGTRefElement : false,
  7928. SVGTSpanElement : false,
  7929. SVGTests : false,
  7930. SVGTextContentElement: false,
  7931. SVGTextElement : false,
  7932. SVGTextPathElement : false,
  7933. SVGTextPositioningElement: false,
  7934. SVGTitleElement : false,
  7935. SVGTransform : false,
  7936. SVGTransformList : false,
  7937. SVGTransformable : false,
  7938. SVGURIReference : false,
  7939. SVGUnitTypes : false,
  7940. SVGUseElement : false,
  7941. SVGVKernElement : false,
  7942. SVGViewElement : false,
  7943. SVGViewSpec : false,
  7944. SVGZoomAndPan : false,
  7945. TimeEvent : false,
  7946. top : false,
  7947. URL : false,
  7948. WebSocket : false,
  7949. window : false,
  7950. Worker : false,
  7951. XMLHttpRequest : false,
  7952. XMLSerializer : false,
  7953. XPathEvaluator : false,
  7954. XPathException : false,
  7955. XPathExpression : false,
  7956. XPathNamespace : false,
  7957. XPathNSResolver : false,
  7958. XPathResult : false
  7959. };
  7960. exports.devel = {
  7961. alert : false,
  7962. confirm: false,
  7963. console: false,
  7964. Debug : false,
  7965. opera : false,
  7966. prompt : false
  7967. };
  7968. exports.worker = {
  7969. importScripts: true,
  7970. postMessage : true,
  7971. self : true
  7972. };
  7973. exports.nonstandard = {
  7974. escape : false,
  7975. unescape: false
  7976. };
  7977. exports.couch = {
  7978. "require" : false,
  7979. respond : false,
  7980. getRow : false,
  7981. emit : false,
  7982. send : false,
  7983. start : false,
  7984. sum : false,
  7985. log : false,
  7986. exports : false,
  7987. module : false,
  7988. provides : false
  7989. };
  7990. exports.node = {
  7991. __filename : false,
  7992. __dirname : false,
  7993. GLOBAL : false,
  7994. global : false,
  7995. module : false,
  7996. require : false,
  7997. Buffer : true,
  7998. console : true,
  7999. exports : true,
  8000. process : true,
  8001. setTimeout : true,
  8002. clearTimeout : true,
  8003. setInterval : true,
  8004. clearInterval : true,
  8005. setImmediate : true, // v0.9.1+
  8006. clearImmediate: true // v0.9.1+
  8007. };
  8008. exports.phantom = {
  8009. phantom : true,
  8010. require : true,
  8011. WebPage : true,
  8012. console : true, // in examples, but undocumented
  8013. exports : true // v1.7+
  8014. };
  8015. exports.qunit = {
  8016. asyncTest : false,
  8017. deepEqual : false,
  8018. equal : false,
  8019. expect : false,
  8020. module : false,
  8021. notDeepEqual : false,
  8022. notEqual : false,
  8023. notPropEqual : false,
  8024. notStrictEqual : false,
  8025. ok : false,
  8026. propEqual : false,
  8027. QUnit : false,
  8028. raises : false,
  8029. start : false,
  8030. stop : false,
  8031. strictEqual : false,
  8032. test : false,
  8033. "throws" : false
  8034. };
  8035. exports.rhino = {
  8036. defineClass : false,
  8037. deserialize : false,
  8038. gc : false,
  8039. help : false,
  8040. importClass : false,
  8041. importPackage: false,
  8042. "java" : false,
  8043. load : false,
  8044. loadClass : false,
  8045. Packages : false,
  8046. print : false,
  8047. quit : false,
  8048. readFile : false,
  8049. readUrl : false,
  8050. runCommand : false,
  8051. seal : false,
  8052. serialize : false,
  8053. spawn : false,
  8054. sync : false,
  8055. toint32 : false,
  8056. version : false
  8057. };
  8058. exports.shelljs = {
  8059. target : false,
  8060. echo : false,
  8061. exit : false,
  8062. cd : false,
  8063. pwd : false,
  8064. ls : false,
  8065. find : false,
  8066. cp : false,
  8067. rm : false,
  8068. mv : false,
  8069. mkdir : false,
  8070. test : false,
  8071. cat : false,
  8072. sed : false,
  8073. grep : false,
  8074. which : false,
  8075. dirs : false,
  8076. pushd : false,
  8077. popd : false,
  8078. env : false,
  8079. exec : false,
  8080. chmod : false,
  8081. config : false,
  8082. error : false,
  8083. tempdir : false
  8084. };
  8085. exports.typed = {
  8086. ArrayBuffer : false,
  8087. ArrayBufferView : false,
  8088. DataView : false,
  8089. Float32Array : false,
  8090. Float64Array : false,
  8091. Int16Array : false,
  8092. Int32Array : false,
  8093. Int8Array : false,
  8094. Uint16Array : false,
  8095. Uint32Array : false,
  8096. Uint8Array : false,
  8097. Uint8ClampedArray : false
  8098. };
  8099. exports.wsh = {
  8100. ActiveXObject : true,
  8101. Enumerator : true,
  8102. GetObject : true,
  8103. ScriptEngine : true,
  8104. ScriptEngineBuildVersion : true,
  8105. ScriptEngineMajorVersion : true,
  8106. ScriptEngineMinorVersion : true,
  8107. VBArray : true,
  8108. WSH : true,
  8109. WScript : true,
  8110. XDomainRequest : true
  8111. };
  8112. exports.dojo = {
  8113. dojo : false,
  8114. dijit : false,
  8115. dojox : false,
  8116. define : false,
  8117. "require": false
  8118. };
  8119. exports.jquery = {
  8120. "$" : false,
  8121. jQuery : false
  8122. };
  8123. exports.mootools = {
  8124. "$" : false,
  8125. "$$" : false,
  8126. Asset : false,
  8127. Browser : false,
  8128. Chain : false,
  8129. Class : false,
  8130. Color : false,
  8131. Cookie : false,
  8132. Core : false,
  8133. Document : false,
  8134. DomReady : false,
  8135. DOMEvent : false,
  8136. DOMReady : false,
  8137. Drag : false,
  8138. Element : false,
  8139. Elements : false,
  8140. Event : false,
  8141. Events : false,
  8142. Fx : false,
  8143. Group : false,
  8144. Hash : false,
  8145. HtmlTable : false,
  8146. IFrame : false,
  8147. IframeShim : false,
  8148. InputValidator: false,
  8149. instanceOf : false,
  8150. Keyboard : false,
  8151. Locale : false,
  8152. Mask : false,
  8153. MooTools : false,
  8154. Native : false,
  8155. Options : false,
  8156. OverText : false,
  8157. Request : false,
  8158. Scroller : false,
  8159. Slick : false,
  8160. Slider : false,
  8161. Sortables : false,
  8162. Spinner : false,
  8163. Swiff : false,
  8164. Tips : false,
  8165. Type : false,
  8166. typeOf : false,
  8167. URI : false,
  8168. Window : false
  8169. };
  8170. exports.prototypejs = {
  8171. "$" : false,
  8172. "$$" : false,
  8173. "$A" : false,
  8174. "$F" : false,
  8175. "$H" : false,
  8176. "$R" : false,
  8177. "$break" : false,
  8178. "$continue" : false,
  8179. "$w" : false,
  8180. Abstract : false,
  8181. Ajax : false,
  8182. Class : false,
  8183. Enumerable : false,
  8184. Element : false,
  8185. Event : false,
  8186. Field : false,
  8187. Form : false,
  8188. Hash : false,
  8189. Insertion : false,
  8190. ObjectRange : false,
  8191. PeriodicalExecuter: false,
  8192. Position : false,
  8193. Prototype : false,
  8194. Selector : false,
  8195. Template : false,
  8196. Toggle : false,
  8197. Try : false,
  8198. Autocompleter : false,
  8199. Builder : false,
  8200. Control : false,
  8201. Draggable : false,
  8202. Draggables : false,
  8203. Droppables : false,
  8204. Effect : false,
  8205. Sortable : false,
  8206. SortableObserver : false,
  8207. Sound : false,
  8208. Scriptaculous : false
  8209. };
  8210. exports.yui = {
  8211. YUI : false,
  8212. Y : false,
  8213. YUI_config: false
  8214. };
  8215. exports.mocha = {
  8216. describe : false,
  8217. it : false,
  8218. before : false,
  8219. after : false,
  8220. beforeEach : false,
  8221. afterEach : false,
  8222. suite : false,
  8223. test : false,
  8224. setup : false,
  8225. teardown : false
  8226. };
  8227. exports.jasmine = {
  8228. jasmine : false,
  8229. describe : false,
  8230. it : false,
  8231. xit : false,
  8232. beforeEach : false,
  8233. afterEach : false,
  8234. setFixtures : false,
  8235. loadFixtures: false,
  8236. spyOn : false,
  8237. expect : false,
  8238. runs : false,
  8239. waitsFor : false,
  8240. waits : false
  8241. };
  8242. },
  8243. {}],
  8244. 10:[function(_dereq_,module,exports){
  8245. function EventEmitter() {
  8246. this._events = this._events || {};
  8247. this._maxListeners = this._maxListeners || undefined;
  8248. }
  8249. module.exports = EventEmitter;
  8250. EventEmitter.EventEmitter = EventEmitter;
  8251. EventEmitter.prototype._events = undefined;
  8252. EventEmitter.prototype._maxListeners = undefined;
  8253. EventEmitter.defaultMaxListeners = 10;
  8254. EventEmitter.prototype.setMaxListeners = function(n) {
  8255. if (!isNumber(n) || n < 0 || isNaN(n))
  8256. throw TypeError('n must be a positive number');
  8257. this._maxListeners = n;
  8258. return this;
  8259. };
  8260. EventEmitter.prototype.emit = function(type) {
  8261. var er, handler, len, args, i, listeners;
  8262. if (!this._events)
  8263. this._events = {};
  8264. if (type === 'error') {
  8265. if (!this._events.error ||
  8266. (isObject(this._events.error) && !this._events.error.length)) {
  8267. er = arguments[1];
  8268. if (er instanceof Error) {
  8269. throw er; // Unhandled 'error' event
  8270. } else {
  8271. throw TypeError('Uncaught, unspecified "error" event.');
  8272. }
  8273. return false;
  8274. }
  8275. }
  8276. handler = this._events[type];
  8277. if (isUndefined(handler))
  8278. return false;
  8279. if (isFunction(handler)) {
  8280. switch (arguments.length) {
  8281. case 1:
  8282. handler.call(this);
  8283. break;
  8284. case 2:
  8285. handler.call(this, arguments[1]);
  8286. break;
  8287. case 3:
  8288. handler.call(this, arguments[1], arguments[2]);
  8289. break;
  8290. default:
  8291. len = arguments.length;
  8292. args = new Array(len - 1);
  8293. for (i = 1; i < len; i++)
  8294. args[i - 1] = arguments[i];
  8295. handler.apply(this, args);
  8296. }
  8297. } else if (isObject(handler)) {
  8298. len = arguments.length;
  8299. args = new Array(len - 1);
  8300. for (i = 1; i < len; i++)
  8301. args[i - 1] = arguments[i];
  8302. listeners = handler.slice();
  8303. len = listeners.length;
  8304. for (i = 0; i < len; i++)
  8305. listeners[i].apply(this, args);
  8306. }
  8307. return true;
  8308. };
  8309. EventEmitter.prototype.addListener = function(type, listener) {
  8310. var m;
  8311. if (!isFunction(listener))
  8312. throw TypeError('listener must be a function');
  8313. if (!this._events)
  8314. this._events = {};
  8315. if (this._events.newListener)
  8316. this.emit('newListener', type,
  8317. isFunction(listener.listener) ?
  8318. listener.listener : listener);
  8319. if (!this._events[type])
  8320. this._events[type] = listener;
  8321. else if (isObject(this._events[type]))
  8322. this._events[type].push(listener);
  8323. else
  8324. this._events[type] = [this._events[type], listener];
  8325. if (isObject(this._events[type]) && !this._events[type].warned) {
  8326. var m;
  8327. if (!isUndefined(this._maxListeners)) {
  8328. m = this._maxListeners;
  8329. } else {
  8330. m = EventEmitter.defaultMaxListeners;
  8331. }
  8332. if (m && m > 0 && this._events[type].length > m) {
  8333. this._events[type].warned = true;
  8334. console.error('(node) warning: possible EventEmitter memory ' +
  8335. 'leak detected. %d listeners added. ' +
  8336. 'Use emitter.setMaxListeners() to increase limit.',
  8337. this._events[type].length);
  8338. console.trace();
  8339. }
  8340. }
  8341. return this;
  8342. };
  8343. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  8344. EventEmitter.prototype.once = function(type, listener) {
  8345. if (!isFunction(listener))
  8346. throw TypeError('listener must be a function');
  8347. var fired = false;
  8348. function g() {
  8349. this.removeListener(type, g);
  8350. if (!fired) {
  8351. fired = true;
  8352. listener.apply(this, arguments);
  8353. }
  8354. }
  8355. g.listener = listener;
  8356. this.on(type, g);
  8357. return this;
  8358. };
  8359. EventEmitter.prototype.removeListener = function(type, listener) {
  8360. var list, position, length, i;
  8361. if (!isFunction(listener))
  8362. throw TypeError('listener must be a function');
  8363. if (!this._events || !this._events[type])
  8364. return this;
  8365. list = this._events[type];
  8366. length = list.length;
  8367. position = -1;
  8368. if (list === listener ||
  8369. (isFunction(list.listener) && list.listener === listener)) {
  8370. delete this._events[type];
  8371. if (this._events.removeListener)
  8372. this.emit('removeListener', type, listener);
  8373. } else if (isObject(list)) {
  8374. for (i = length; i-- > 0;) {
  8375. if (list[i] === listener ||
  8376. (list[i].listener && list[i].listener === listener)) {
  8377. position = i;
  8378. break;
  8379. }
  8380. }
  8381. if (position < 0)
  8382. return this;
  8383. if (list.length === 1) {
  8384. list.length = 0;
  8385. delete this._events[type];
  8386. } else {
  8387. list.splice(position, 1);
  8388. }
  8389. if (this._events.removeListener)
  8390. this.emit('removeListener', type, listener);
  8391. }
  8392. return this;
  8393. };
  8394. EventEmitter.prototype.removeAllListeners = function(type) {
  8395. var key, listeners;
  8396. if (!this._events)
  8397. return this;
  8398. if (!this._events.removeListener) {
  8399. if (arguments.length === 0)
  8400. this._events = {};
  8401. else if (this._events[type])
  8402. delete this._events[type];
  8403. return this;
  8404. }
  8405. if (arguments.length === 0) {
  8406. for (key in this._events) {
  8407. if (key === 'removeListener') continue;
  8408. this.removeAllListeners(key);
  8409. }
  8410. this.removeAllListeners('removeListener');
  8411. this._events = {};
  8412. return this;
  8413. }
  8414. listeners = this._events[type];
  8415. if (isFunction(listeners)) {
  8416. this.removeListener(type, listeners);
  8417. } else {
  8418. while (listeners.length)
  8419. this.removeListener(type, listeners[listeners.length - 1]);
  8420. }
  8421. delete this._events[type];
  8422. return this;
  8423. };
  8424. EventEmitter.prototype.listeners = function(type) {
  8425. var ret;
  8426. if (!this._events || !this._events[type])
  8427. ret = [];
  8428. else if (isFunction(this._events[type]))
  8429. ret = [this._events[type]];
  8430. else
  8431. ret = this._events[type].slice();
  8432. return ret;
  8433. };
  8434. EventEmitter.listenerCount = function(emitter, type) {
  8435. var ret;
  8436. if (!emitter._events || !emitter._events[type])
  8437. ret = 0;
  8438. else if (isFunction(emitter._events[type]))
  8439. ret = 1;
  8440. else
  8441. ret = emitter._events[type].length;
  8442. return ret;
  8443. };
  8444. function isFunction(arg) {
  8445. return typeof arg === 'function';
  8446. }
  8447. function isNumber(arg) {
  8448. return typeof arg === 'number';
  8449. }
  8450. function isObject(arg) {
  8451. return typeof arg === 'object' && arg !== null;
  8452. }
  8453. function isUndefined(arg) {
  8454. return arg === void 0;
  8455. }
  8456. },
  8457. {}]},{},[3])
  8458. (3)
  8459. });
  8460. ace.define("ace/mode/javascript_worker",["require","exports","module","ace/lib/oop","ace/worker/mirror","ace/mode/javascript/jshint"], function(require, exports, module) {
  8461. "use strict";
  8462. var oop = require("../lib/oop");
  8463. var Mirror = require("../worker/mirror").Mirror;
  8464. var lint = require("./javascript/jshint").JSHINT;
  8465. function startRegex(arr) {
  8466. return RegExp("^(" + arr.join("|") + ")");
  8467. }
  8468. var disabledWarningsRe = startRegex([
  8469. "Bad for in variable '(.+)'.",
  8470. 'Missing "use strict"'
  8471. ]);
  8472. var errorsRe = startRegex([
  8473. "Unexpected",
  8474. "Expected ",
  8475. "Confusing (plus|minus)",
  8476. "\\{a\\} unterminated regular expression",
  8477. "Unclosed ",
  8478. "Unmatched ",
  8479. "Unbegun comment",
  8480. "Bad invocation",
  8481. "Missing space after",
  8482. "Missing operator at"
  8483. ]);
  8484. var infoRe = startRegex([
  8485. "Expected an assignment",
  8486. "Bad escapement of EOL",
  8487. "Unexpected comma",
  8488. "Unexpected space",
  8489. "Missing radix parameter.",
  8490. "A leading decimal point can",
  8491. "\\['{a}'\\] is better written in dot notation.",
  8492. "'{a}' used out of scope"
  8493. ]);
  8494. var JavaScriptWorker = exports.JavaScriptWorker = function(sender) {
  8495. Mirror.call(this, sender);
  8496. this.setTimeout(500);
  8497. this.setOptions();
  8498. };
  8499. oop.inherits(JavaScriptWorker, Mirror);
  8500. (function() {
  8501. this.setOptions = function(options) {
  8502. this.options = options || {
  8503. esnext: true,
  8504. moz: true,
  8505. devel: true,
  8506. browser: true,
  8507. node: true,
  8508. laxcomma: true,
  8509. laxbreak: true,
  8510. lastsemic: true,
  8511. onevar: false,
  8512. passfail: false,
  8513. maxerr: 100,
  8514. expr: true,
  8515. multistr: true,
  8516. globalstrict: true
  8517. };
  8518. this.doc.getValue() && this.deferredUpdate.schedule(100);
  8519. };
  8520. this.changeOptions = function(newOptions) {
  8521. oop.mixin(this.options, newOptions);
  8522. this.doc.getValue() && this.deferredUpdate.schedule(100);
  8523. };
  8524. this.isValidJS = function(str) {
  8525. try {
  8526. eval("throw 0;" + str);
  8527. } catch(e) {
  8528. if (e === 0)
  8529. return true;
  8530. }
  8531. return false
  8532. };
  8533. this.onUpdate = function() {
  8534. var value = this.doc.getValue();
  8535. value = value.replace(/^#!.*\n/, "\n");
  8536. if (!value) {
  8537. this.sender.emit("jslint", []);
  8538. return;
  8539. }
  8540. var errors = [];
  8541. var maxErrorLevel = this.isValidJS(value) ? "warning" : "error";
  8542. lint(value, this.options);
  8543. var results = lint.errors;
  8544. var errorAdded = false
  8545. for (var i = 0; i < results.length; i++) {
  8546. var error = results[i];
  8547. if (!error)
  8548. continue;
  8549. var raw = error.raw;
  8550. var type = "warning";
  8551. if (raw == "Missing semicolon.") {
  8552. var str = error.evidence.substr(error.character);
  8553. str = str.charAt(str.search(/\S/));
  8554. if (maxErrorLevel == "error" && str && /[\w\d{(['"]/.test(str)) {
  8555. error.reason = 'Missing ";" before statement';
  8556. type = "error";
  8557. } else {
  8558. type = "info";
  8559. }
  8560. }
  8561. else if (disabledWarningsRe.test(raw)) {
  8562. continue;
  8563. }
  8564. else if (infoRe.test(raw)) {
  8565. type = "info"
  8566. }
  8567. else if (errorsRe.test(raw)) {
  8568. errorAdded = true;
  8569. type = maxErrorLevel;
  8570. }
  8571. else if (raw == "'{a}' is not defined.") {
  8572. type = "warning";
  8573. }
  8574. else if (raw == "'{a}' is defined but never used.") {
  8575. type = "info";
  8576. }
  8577. errors.push({
  8578. row: error.line-1,
  8579. column: error.character-1,
  8580. text: error.reason,
  8581. type: type,
  8582. raw: raw
  8583. });
  8584. if (errorAdded) {
  8585. }
  8586. }
  8587. this.sender.emit("jslint", errors);
  8588. };
  8589. }).call(JavaScriptWorker.prototype);
  8590. });
  8591. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  8592. function Empty() {}
  8593. if (!Function.prototype.bind) {
  8594. Function.prototype.bind = function bind(that) { // .length is 1
  8595. var target = this;
  8596. if (typeof target != "function") {
  8597. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  8598. }
  8599. var args = slice.call(arguments, 1); // for normal call
  8600. var bound = function () {
  8601. if (this instanceof bound) {
  8602. var result = target.apply(
  8603. this,
  8604. args.concat(slice.call(arguments))
  8605. );
  8606. if (Object(result) === result) {
  8607. return result;
  8608. }
  8609. return this;
  8610. } else {
  8611. return target.apply(
  8612. that,
  8613. args.concat(slice.call(arguments))
  8614. );
  8615. }
  8616. };
  8617. if(target.prototype) {
  8618. Empty.prototype = target.prototype;
  8619. bound.prototype = new Empty();
  8620. Empty.prototype = null;
  8621. }
  8622. return bound;
  8623. };
  8624. }
  8625. var call = Function.prototype.call;
  8626. var prototypeOfArray = Array.prototype;
  8627. var prototypeOfObject = Object.prototype;
  8628. var slice = prototypeOfArray.slice;
  8629. var _toString = call.bind(prototypeOfObject.toString);
  8630. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  8631. var defineGetter;
  8632. var defineSetter;
  8633. var lookupGetter;
  8634. var lookupSetter;
  8635. var supportsAccessors;
  8636. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  8637. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  8638. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  8639. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  8640. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  8641. }
  8642. if ([1,2].splice(0).length != 2) {
  8643. if(function() { // test IE < 9 to splice bug - see issue #138
  8644. function makeArray(l) {
  8645. var a = new Array(l+2);
  8646. a[0] = a[1] = 0;
  8647. return a;
  8648. }
  8649. var array = [], lengthBefore;
  8650. array.splice.apply(array, makeArray(20));
  8651. array.splice.apply(array, makeArray(26));
  8652. lengthBefore = array.length; //46
  8653. array.splice(5, 0, "XXX"); // add one element
  8654. lengthBefore + 1 == array.length
  8655. if (lengthBefore + 1 == array.length) {
  8656. return true;// has right splice implementation without bugs
  8657. }
  8658. }()) {//IE 6/7
  8659. var array_splice = Array.prototype.splice;
  8660. Array.prototype.splice = function(start, deleteCount) {
  8661. if (!arguments.length) {
  8662. return [];
  8663. } else {
  8664. return array_splice.apply(this, [
  8665. start === void 0 ? 0 : start,
  8666. deleteCount === void 0 ? (this.length - start) : deleteCount
  8667. ].concat(slice.call(arguments, 2)))
  8668. }
  8669. };
  8670. } else {//IE8
  8671. Array.prototype.splice = function(pos, removeCount){
  8672. var length = this.length;
  8673. if (pos > 0) {
  8674. if (pos > length)
  8675. pos = length;
  8676. } else if (pos == void 0) {
  8677. pos = 0;
  8678. } else if (pos < 0) {
  8679. pos = Math.max(length + pos, 0);
  8680. }
  8681. if (!(pos+removeCount < length))
  8682. removeCount = length - pos;
  8683. var removed = this.slice(pos, pos+removeCount);
  8684. var insert = slice.call(arguments, 2);
  8685. var add = insert.length;
  8686. if (pos === length) {
  8687. if (add) {
  8688. this.push.apply(this, insert);
  8689. }
  8690. } else {
  8691. var remove = Math.min(removeCount, length - pos);
  8692. var tailOldPos = pos + remove;
  8693. var tailNewPos = tailOldPos + add - remove;
  8694. var tailCount = length - tailOldPos;
  8695. var lengthAfterRemove = length - remove;
  8696. if (tailNewPos < tailOldPos) { // case A
  8697. for (var i = 0; i < tailCount; ++i) {
  8698. this[tailNewPos+i] = this[tailOldPos+i];
  8699. }
  8700. } else if (tailNewPos > tailOldPos) { // case B
  8701. for (i = tailCount; i--; ) {
  8702. this[tailNewPos+i] = this[tailOldPos+i];
  8703. }
  8704. } // else, add == remove (nothing to do)
  8705. if (add && pos === lengthAfterRemove) {
  8706. this.length = lengthAfterRemove; // truncate array
  8707. this.push.apply(this, insert);
  8708. } else {
  8709. this.length = lengthAfterRemove + add; // reserves space
  8710. for (i = 0; i < add; ++i) {
  8711. this[pos+i] = insert[i];
  8712. }
  8713. }
  8714. }
  8715. return removed;
  8716. };
  8717. }
  8718. }
  8719. if (!Array.isArray) {
  8720. Array.isArray = function isArray(obj) {
  8721. return _toString(obj) == "[object Array]";
  8722. };
  8723. }
  8724. var boxedString = Object("a"),
  8725. splitString = boxedString[0] != "a" || !(0 in boxedString);
  8726. if (!Array.prototype.forEach) {
  8727. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  8728. var object = toObject(this),
  8729. self = splitString && _toString(this) == "[object String]" ?
  8730. this.split("") :
  8731. object,
  8732. thisp = arguments[1],
  8733. i = -1,
  8734. length = self.length >>> 0;
  8735. if (_toString(fun) != "[object Function]") {
  8736. throw new TypeError(); // TODO message
  8737. }
  8738. while (++i < length) {
  8739. if (i in self) {
  8740. fun.call(thisp, self[i], i, object);
  8741. }
  8742. }
  8743. };
  8744. }
  8745. if (!Array.prototype.map) {
  8746. Array.prototype.map = function map(fun /*, thisp*/) {
  8747. var object = toObject(this),
  8748. self = splitString && _toString(this) == "[object String]" ?
  8749. this.split("") :
  8750. object,
  8751. length = self.length >>> 0,
  8752. result = Array(length),
  8753. thisp = arguments[1];
  8754. if (_toString(fun) != "[object Function]") {
  8755. throw new TypeError(fun + " is not a function");
  8756. }
  8757. for (var i = 0; i < length; i++) {
  8758. if (i in self)
  8759. result[i] = fun.call(thisp, self[i], i, object);
  8760. }
  8761. return result;
  8762. };
  8763. }
  8764. if (!Array.prototype.filter) {
  8765. Array.prototype.filter = function filter(fun /*, thisp */) {
  8766. var object = toObject(this),
  8767. self = splitString && _toString(this) == "[object String]" ?
  8768. this.split("") :
  8769. object,
  8770. length = self.length >>> 0,
  8771. result = [],
  8772. value,
  8773. thisp = arguments[1];
  8774. if (_toString(fun) != "[object Function]") {
  8775. throw new TypeError(fun + " is not a function");
  8776. }
  8777. for (var i = 0; i < length; i++) {
  8778. if (i in self) {
  8779. value = self[i];
  8780. if (fun.call(thisp, value, i, object)) {
  8781. result.push(value);
  8782. }
  8783. }
  8784. }
  8785. return result;
  8786. };
  8787. }
  8788. if (!Array.prototype.every) {
  8789. Array.prototype.every = function every(fun /*, thisp */) {
  8790. var object = toObject(this),
  8791. self = splitString && _toString(this) == "[object String]" ?
  8792. this.split("") :
  8793. object,
  8794. length = self.length >>> 0,
  8795. thisp = arguments[1];
  8796. if (_toString(fun) != "[object Function]") {
  8797. throw new TypeError(fun + " is not a function");
  8798. }
  8799. for (var i = 0; i < length; i++) {
  8800. if (i in self && !fun.call(thisp, self[i], i, object)) {
  8801. return false;
  8802. }
  8803. }
  8804. return true;
  8805. };
  8806. }
  8807. if (!Array.prototype.some) {
  8808. Array.prototype.some = function some(fun /*, thisp */) {
  8809. var object = toObject(this),
  8810. self = splitString && _toString(this) == "[object String]" ?
  8811. this.split("") :
  8812. object,
  8813. length = self.length >>> 0,
  8814. thisp = arguments[1];
  8815. if (_toString(fun) != "[object Function]") {
  8816. throw new TypeError(fun + " is not a function");
  8817. }
  8818. for (var i = 0; i < length; i++) {
  8819. if (i in self && fun.call(thisp, self[i], i, object)) {
  8820. return true;
  8821. }
  8822. }
  8823. return false;
  8824. };
  8825. }
  8826. if (!Array.prototype.reduce) {
  8827. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  8828. var object = toObject(this),
  8829. self = splitString && _toString(this) == "[object String]" ?
  8830. this.split("") :
  8831. object,
  8832. length = self.length >>> 0;
  8833. if (_toString(fun) != "[object Function]") {
  8834. throw new TypeError(fun + " is not a function");
  8835. }
  8836. if (!length && arguments.length == 1) {
  8837. throw new TypeError("reduce of empty array with no initial value");
  8838. }
  8839. var i = 0;
  8840. var result;
  8841. if (arguments.length >= 2) {
  8842. result = arguments[1];
  8843. } else {
  8844. do {
  8845. if (i in self) {
  8846. result = self[i++];
  8847. break;
  8848. }
  8849. if (++i >= length) {
  8850. throw new TypeError("reduce of empty array with no initial value");
  8851. }
  8852. } while (true);
  8853. }
  8854. for (; i < length; i++) {
  8855. if (i in self) {
  8856. result = fun.call(void 0, result, self[i], i, object);
  8857. }
  8858. }
  8859. return result;
  8860. };
  8861. }
  8862. if (!Array.prototype.reduceRight) {
  8863. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  8864. var object = toObject(this),
  8865. self = splitString && _toString(this) == "[object String]" ?
  8866. this.split("") :
  8867. object,
  8868. length = self.length >>> 0;
  8869. if (_toString(fun) != "[object Function]") {
  8870. throw new TypeError(fun + " is not a function");
  8871. }
  8872. if (!length && arguments.length == 1) {
  8873. throw new TypeError("reduceRight of empty array with no initial value");
  8874. }
  8875. var result, i = length - 1;
  8876. if (arguments.length >= 2) {
  8877. result = arguments[1];
  8878. } else {
  8879. do {
  8880. if (i in self) {
  8881. result = self[i--];
  8882. break;
  8883. }
  8884. if (--i < 0) {
  8885. throw new TypeError("reduceRight of empty array with no initial value");
  8886. }
  8887. } while (true);
  8888. }
  8889. do {
  8890. if (i in this) {
  8891. result = fun.call(void 0, result, self[i], i, object);
  8892. }
  8893. } while (i--);
  8894. return result;
  8895. };
  8896. }
  8897. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  8898. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  8899. var self = splitString && _toString(this) == "[object String]" ?
  8900. this.split("") :
  8901. toObject(this),
  8902. length = self.length >>> 0;
  8903. if (!length) {
  8904. return -1;
  8905. }
  8906. var i = 0;
  8907. if (arguments.length > 1) {
  8908. i = toInteger(arguments[1]);
  8909. }
  8910. i = i >= 0 ? i : Math.max(0, length + i);
  8911. for (; i < length; i++) {
  8912. if (i in self && self[i] === sought) {
  8913. return i;
  8914. }
  8915. }
  8916. return -1;
  8917. };
  8918. }
  8919. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  8920. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  8921. var self = splitString && _toString(this) == "[object String]" ?
  8922. this.split("") :
  8923. toObject(this),
  8924. length = self.length >>> 0;
  8925. if (!length) {
  8926. return -1;
  8927. }
  8928. var i = length - 1;
  8929. if (arguments.length > 1) {
  8930. i = Math.min(i, toInteger(arguments[1]));
  8931. }
  8932. i = i >= 0 ? i : length - Math.abs(i);
  8933. for (; i >= 0; i--) {
  8934. if (i in self && sought === self[i]) {
  8935. return i;
  8936. }
  8937. }
  8938. return -1;
  8939. };
  8940. }
  8941. if (!Object.getPrototypeOf) {
  8942. Object.getPrototypeOf = function getPrototypeOf(object) {
  8943. return object.__proto__ || (
  8944. object.constructor ?
  8945. object.constructor.prototype :
  8946. prototypeOfObject
  8947. );
  8948. };
  8949. }
  8950. if (!Object.getOwnPropertyDescriptor) {
  8951. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  8952. "non-object: ";
  8953. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  8954. if ((typeof object != "object" && typeof object != "function") || object === null)
  8955. throw new TypeError(ERR_NON_OBJECT + object);
  8956. if (!owns(object, property))
  8957. return;
  8958. var descriptor, getter, setter;
  8959. descriptor = { enumerable: true, configurable: true };
  8960. if (supportsAccessors) {
  8961. var prototype = object.__proto__;
  8962. object.__proto__ = prototypeOfObject;
  8963. var getter = lookupGetter(object, property);
  8964. var setter = lookupSetter(object, property);
  8965. object.__proto__ = prototype;
  8966. if (getter || setter) {
  8967. if (getter) descriptor.get = getter;
  8968. if (setter) descriptor.set = setter;
  8969. return descriptor;
  8970. }
  8971. }
  8972. descriptor.value = object[property];
  8973. return descriptor;
  8974. };
  8975. }
  8976. if (!Object.getOwnPropertyNames) {
  8977. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  8978. return Object.keys(object);
  8979. };
  8980. }
  8981. if (!Object.create) {
  8982. var createEmpty;
  8983. if (Object.prototype.__proto__ === null) {
  8984. createEmpty = function () {
  8985. return { "__proto__": null };
  8986. };
  8987. } else {
  8988. createEmpty = function () {
  8989. var empty = {};
  8990. for (var i in empty)
  8991. empty[i] = null;
  8992. empty.constructor =
  8993. empty.hasOwnProperty =
  8994. empty.propertyIsEnumerable =
  8995. empty.isPrototypeOf =
  8996. empty.toLocaleString =
  8997. empty.toString =
  8998. empty.valueOf =
  8999. empty.__proto__ = null;
  9000. return empty;
  9001. }
  9002. }
  9003. Object.create = function create(prototype, properties) {
  9004. var object;
  9005. if (prototype === null) {
  9006. object = createEmpty();
  9007. } else {
  9008. if (typeof prototype != "object")
  9009. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  9010. var Type = function () {};
  9011. Type.prototype = prototype;
  9012. object = new Type();
  9013. object.__proto__ = prototype;
  9014. }
  9015. if (properties !== void 0)
  9016. Object.defineProperties(object, properties);
  9017. return object;
  9018. };
  9019. }
  9020. function doesDefinePropertyWork(object) {
  9021. try {
  9022. Object.defineProperty(object, "sentinel", {});
  9023. return "sentinel" in object;
  9024. } catch (exception) {
  9025. }
  9026. }
  9027. if (Object.defineProperty) {
  9028. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  9029. var definePropertyWorksOnDom = typeof document == "undefined" ||
  9030. doesDefinePropertyWork(document.createElement("div"));
  9031. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  9032. var definePropertyFallback = Object.defineProperty;
  9033. }
  9034. }
  9035. if (!Object.defineProperty || definePropertyFallback) {
  9036. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  9037. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  9038. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  9039. "on this javascript engine";
  9040. Object.defineProperty = function defineProperty(object, property, descriptor) {
  9041. if ((typeof object != "object" && typeof object != "function") || object === null)
  9042. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  9043. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  9044. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  9045. if (definePropertyFallback) {
  9046. try {
  9047. return definePropertyFallback.call(Object, object, property, descriptor);
  9048. } catch (exception) {
  9049. }
  9050. }
  9051. if (owns(descriptor, "value")) {
  9052. if (supportsAccessors && (lookupGetter(object, property) ||
  9053. lookupSetter(object, property)))
  9054. {
  9055. var prototype = object.__proto__;
  9056. object.__proto__ = prototypeOfObject;
  9057. delete object[property];
  9058. object[property] = descriptor.value;
  9059. object.__proto__ = prototype;
  9060. } else {
  9061. object[property] = descriptor.value;
  9062. }
  9063. } else {
  9064. if (!supportsAccessors)
  9065. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  9066. if (owns(descriptor, "get"))
  9067. defineGetter(object, property, descriptor.get);
  9068. if (owns(descriptor, "set"))
  9069. defineSetter(object, property, descriptor.set);
  9070. }
  9071. return object;
  9072. };
  9073. }
  9074. if (!Object.defineProperties) {
  9075. Object.defineProperties = function defineProperties(object, properties) {
  9076. for (var property in properties) {
  9077. if (owns(properties, property))
  9078. Object.defineProperty(object, property, properties[property]);
  9079. }
  9080. return object;
  9081. };
  9082. }
  9083. if (!Object.seal) {
  9084. Object.seal = function seal(object) {
  9085. return object;
  9086. };
  9087. }
  9088. if (!Object.freeze) {
  9089. Object.freeze = function freeze(object) {
  9090. return object;
  9091. };
  9092. }
  9093. try {
  9094. Object.freeze(function () {});
  9095. } catch (exception) {
  9096. Object.freeze = (function freeze(freezeObject) {
  9097. return function freeze(object) {
  9098. if (typeof object == "function") {
  9099. return object;
  9100. } else {
  9101. return freezeObject(object);
  9102. }
  9103. };
  9104. })(Object.freeze);
  9105. }
  9106. if (!Object.preventExtensions) {
  9107. Object.preventExtensions = function preventExtensions(object) {
  9108. return object;
  9109. };
  9110. }
  9111. if (!Object.isSealed) {
  9112. Object.isSealed = function isSealed(object) {
  9113. return false;
  9114. };
  9115. }
  9116. if (!Object.isFrozen) {
  9117. Object.isFrozen = function isFrozen(object) {
  9118. return false;
  9119. };
  9120. }
  9121. if (!Object.isExtensible) {
  9122. Object.isExtensible = function isExtensible(object) {
  9123. if (Object(object) === object) {
  9124. throw new TypeError(); // TODO message
  9125. }
  9126. var name = '';
  9127. while (owns(object, name)) {
  9128. name += '?';
  9129. }
  9130. object[name] = true;
  9131. var returnValue = owns(object, name);
  9132. delete object[name];
  9133. return returnValue;
  9134. };
  9135. }
  9136. if (!Object.keys) {
  9137. var hasDontEnumBug = true,
  9138. dontEnums = [
  9139. "toString",
  9140. "toLocaleString",
  9141. "valueOf",
  9142. "hasOwnProperty",
  9143. "isPrototypeOf",
  9144. "propertyIsEnumerable",
  9145. "constructor"
  9146. ],
  9147. dontEnumsLength = dontEnums.length;
  9148. for (var key in {"toString": null}) {
  9149. hasDontEnumBug = false;
  9150. }
  9151. Object.keys = function keys(object) {
  9152. if (
  9153. (typeof object != "object" && typeof object != "function") ||
  9154. object === null
  9155. ) {
  9156. throw new TypeError("Object.keys called on a non-object");
  9157. }
  9158. var keys = [];
  9159. for (var name in object) {
  9160. if (owns(object, name)) {
  9161. keys.push(name);
  9162. }
  9163. }
  9164. if (hasDontEnumBug) {
  9165. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  9166. var dontEnum = dontEnums[i];
  9167. if (owns(object, dontEnum)) {
  9168. keys.push(dontEnum);
  9169. }
  9170. }
  9171. }
  9172. return keys;
  9173. };
  9174. }
  9175. if (!Date.now) {
  9176. Date.now = function now() {
  9177. return new Date().getTime();
  9178. };
  9179. }
  9180. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  9181. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  9182. "\u2029\uFEFF";
  9183. if (!String.prototype.trim || ws.trim()) {
  9184. ws = "[" + ws + "]";
  9185. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  9186. trimEndRegexp = new RegExp(ws + ws + "*$");
  9187. String.prototype.trim = function trim() {
  9188. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  9189. };
  9190. }
  9191. function toInteger(n) {
  9192. n = +n;
  9193. if (n !== n) { // isNaN
  9194. n = 0;
  9195. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  9196. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  9197. }
  9198. return n;
  9199. }
  9200. function isPrimitive(input) {
  9201. var type = typeof input;
  9202. return (
  9203. input === null ||
  9204. type === "undefined" ||
  9205. type === "boolean" ||
  9206. type === "number" ||
  9207. type === "string"
  9208. );
  9209. }
  9210. function toPrimitive(input) {
  9211. var val, valueOf, toString;
  9212. if (isPrimitive(input)) {
  9213. return input;
  9214. }
  9215. valueOf = input.valueOf;
  9216. if (typeof valueOf === "function") {
  9217. val = valueOf.call(input);
  9218. if (isPrimitive(val)) {
  9219. return val;
  9220. }
  9221. }
  9222. toString = input.toString;
  9223. if (typeof toString === "function") {
  9224. val = toString.call(input);
  9225. if (isPrimitive(val)) {
  9226. return val;
  9227. }
  9228. }
  9229. throw new TypeError();
  9230. }
  9231. var toObject = function (o) {
  9232. if (o == null) { // this matches both null and undefined
  9233. throw new TypeError("can't convert "+o+" to object");
  9234. }
  9235. return Object(o);
  9236. };
  9237. });