jshint.js 295 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336
  1. // 2.1.10
  2. var JSHINT;
  3. (function () {
  4. var require;
  5. require=(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
  6. // shim for using process in browser
  7. var process = module.exports = {};
  8. process.nextTick = (function () {
  9. var canSetImmediate = typeof window !== 'undefined'
  10. && window.setImmediate;
  11. var canPost = typeof window !== 'undefined'
  12. && window.postMessage && window.addEventListener
  13. ;
  14. if (canSetImmediate) {
  15. return function (f) { return window.setImmediate(f) };
  16. }
  17. if (canPost) {
  18. var queue = [];
  19. window.addEventListener('message', function (ev) {
  20. if (ev.source === window && ev.data === 'process-tick') {
  21. ev.stopPropagation();
  22. if (queue.length > 0) {
  23. var fn = queue.shift();
  24. fn();
  25. }
  26. }
  27. }, true);
  28. return function nextTick(fn) {
  29. queue.push(fn);
  30. window.postMessage('process-tick', '*');
  31. };
  32. }
  33. return function nextTick(fn) {
  34. setTimeout(fn, 0);
  35. };
  36. })();
  37. process.title = 'browser';
  38. process.browser = true;
  39. process.env = {};
  40. process.argv = [];
  41. process.binding = function (name) {
  42. throw new Error('process.binding is not supported');
  43. }
  44. // TODO(shtylman)
  45. process.cwd = function () { return '/' };
  46. process.chdir = function (dir) {
  47. throw new Error('process.chdir is not supported');
  48. };
  49. },{}],2:[function(require,module,exports){
  50. (function(process){if (!process.EventEmitter) process.EventEmitter = function () {};
  51. var EventEmitter = exports.EventEmitter = process.EventEmitter;
  52. var isArray = typeof Array.isArray === 'function'
  53. ? Array.isArray
  54. : function (xs) {
  55. return Object.prototype.toString.call(xs) === '[object Array]'
  56. }
  57. ;
  58. function indexOf (xs, x) {
  59. if (xs.indexOf) return xs.indexOf(x);
  60. for (var i = 0; i < xs.length; i++) {
  61. if (x === xs[i]) return i;
  62. }
  63. return -1;
  64. }
  65. // By default EventEmitters will print a warning if more than
  66. // 10 listeners are added to it. This is a useful default which
  67. // helps finding memory leaks.
  68. //
  69. // Obviously not all Emitters should be limited to 10. This function allows
  70. // that to be increased. Set to zero for unlimited.
  71. var defaultMaxListeners = 10;
  72. EventEmitter.prototype.setMaxListeners = function(n) {
  73. if (!this._events) this._events = {};
  74. this._events.maxListeners = n;
  75. };
  76. EventEmitter.prototype.emit = function(type) {
  77. // If there is no 'error' event listener then throw.
  78. if (type === 'error') {
  79. if (!this._events || !this._events.error ||
  80. (isArray(this._events.error) && !this._events.error.length))
  81. {
  82. if (arguments[1] instanceof Error) {
  83. throw arguments[1]; // Unhandled 'error' event
  84. } else {
  85. throw new Error("Uncaught, unspecified 'error' event.");
  86. }
  87. return false;
  88. }
  89. }
  90. if (!this._events) return false;
  91. var handler = this._events[type];
  92. if (!handler) return false;
  93. if (typeof handler == 'function') {
  94. switch (arguments.length) {
  95. // fast cases
  96. case 1:
  97. handler.call(this);
  98. break;
  99. case 2:
  100. handler.call(this, arguments[1]);
  101. break;
  102. case 3:
  103. handler.call(this, arguments[1], arguments[2]);
  104. break;
  105. // slower
  106. default:
  107. var args = Array.prototype.slice.call(arguments, 1);
  108. handler.apply(this, args);
  109. }
  110. return true;
  111. } else if (isArray(handler)) {
  112. var args = Array.prototype.slice.call(arguments, 1);
  113. var listeners = handler.slice();
  114. for (var i = 0, l = listeners.length; i < l; i++) {
  115. listeners[i].apply(this, args);
  116. }
  117. return true;
  118. } else {
  119. return false;
  120. }
  121. };
  122. // EventEmitter is defined in src/node_events.cc
  123. // EventEmitter.prototype.emit() is also defined there.
  124. EventEmitter.prototype.addListener = function(type, listener) {
  125. if ('function' !== typeof listener) {
  126. throw new Error('addListener only takes instances of Function');
  127. }
  128. if (!this._events) this._events = {};
  129. // To avoid recursion in the case that type == "newListeners"! Before
  130. // adding it to the listeners, first emit "newListeners".
  131. this.emit('newListener', type, listener);
  132. if (!this._events[type]) {
  133. // Optimize the case of one listener. Don't need the extra array object.
  134. this._events[type] = listener;
  135. } else if (isArray(this._events[type])) {
  136. // Check for listener leak
  137. if (!this._events[type].warned) {
  138. var m;
  139. if (this._events.maxListeners !== undefined) {
  140. m = this._events.maxListeners;
  141. } else {
  142. m = defaultMaxListeners;
  143. }
  144. if (m && m > 0 && this._events[type].length > m) {
  145. this._events[type].warned = true;
  146. console.error('(node) warning: possible EventEmitter memory ' +
  147. 'leak detected. %d listeners added. ' +
  148. 'Use emitter.setMaxListeners() to increase limit.',
  149. this._events[type].length);
  150. console.trace();
  151. }
  152. }
  153. // If we've already got an array, just append.
  154. this._events[type].push(listener);
  155. } else {
  156. // Adding the second element, need to change to array.
  157. this._events[type] = [this._events[type], listener];
  158. }
  159. return this;
  160. };
  161. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  162. EventEmitter.prototype.once = function(type, listener) {
  163. var self = this;
  164. self.on(type, function g() {
  165. self.removeListener(type, g);
  166. listener.apply(this, arguments);
  167. });
  168. return this;
  169. };
  170. EventEmitter.prototype.removeListener = function(type, listener) {
  171. if ('function' !== typeof listener) {
  172. throw new Error('removeListener only takes instances of Function');
  173. }
  174. // does not use listeners(), so no side effect of creating _events[type]
  175. if (!this._events || !this._events[type]) return this;
  176. var list = this._events[type];
  177. if (isArray(list)) {
  178. var i = indexOf(list, listener);
  179. if (i < 0) return this;
  180. list.splice(i, 1);
  181. if (list.length == 0)
  182. delete this._events[type];
  183. } else if (this._events[type] === listener) {
  184. delete this._events[type];
  185. }
  186. return this;
  187. };
  188. EventEmitter.prototype.removeAllListeners = function(type) {
  189. if (arguments.length === 0) {
  190. this._events = {};
  191. return this;
  192. }
  193. // does not use listeners(), so no side effect of creating _events[type]
  194. if (type && this._events && this._events[type]) this._events[type] = null;
  195. return this;
  196. };
  197. EventEmitter.prototype.listeners = function(type) {
  198. if (!this._events) this._events = {};
  199. if (!this._events[type]) this._events[type] = [];
  200. if (!isArray(this._events[type])) {
  201. this._events[type] = [this._events[type]];
  202. }
  203. return this._events[type];
  204. };
  205. })(require("__browserify_process"))
  206. },{"__browserify_process":1}],3:[function(require,module,exports){
  207. (function(){// jshint -W001
  208. "use strict";
  209. // Identifiers provided by the ECMAScript standard.
  210. exports.reservedVars = {
  211. arguments : false,
  212. NaN : false
  213. };
  214. exports.ecmaIdentifiers = {
  215. Array : false,
  216. Boolean : false,
  217. Date : false,
  218. decodeURI : false,
  219. decodeURIComponent : false,
  220. encodeURI : false,
  221. encodeURIComponent : false,
  222. Error : false,
  223. "eval" : false,
  224. EvalError : false,
  225. Function : false,
  226. hasOwnProperty : false,
  227. isFinite : false,
  228. isNaN : false,
  229. JSON : false,
  230. Math : false,
  231. Map : false,
  232. Number : false,
  233. Object : false,
  234. parseInt : false,
  235. parseFloat : false,
  236. RangeError : false,
  237. ReferenceError : false,
  238. RegExp : false,
  239. Set : false,
  240. String : false,
  241. SyntaxError : false,
  242. TypeError : false,
  243. URIError : false,
  244. WeakMap : false
  245. };
  246. // Global variables commonly provided by a web browser environment.
  247. exports.browser = {
  248. Audio : false,
  249. Blob : false,
  250. addEventListener : false,
  251. applicationCache : false,
  252. atob : false,
  253. blur : false,
  254. btoa : false,
  255. clearInterval : false,
  256. clearTimeout : false,
  257. close : false,
  258. closed : false,
  259. CustomEvent : false,
  260. DOMParser : false,
  261. defaultStatus : false,
  262. document : false,
  263. Element : false,
  264. ElementTimeControl : false,
  265. event : false,
  266. FileReader : false,
  267. FormData : false,
  268. focus : false,
  269. frames : false,
  270. getComputedStyle : false,
  271. HTMLElement : false,
  272. HTMLAnchorElement : false,
  273. HTMLBaseElement : false,
  274. HTMLBlockquoteElement: false,
  275. HTMLBodyElement : false,
  276. HTMLBRElement : false,
  277. HTMLButtonElement : false,
  278. HTMLCanvasElement : false,
  279. HTMLDirectoryElement : false,
  280. HTMLDivElement : false,
  281. HTMLDListElement : false,
  282. HTMLFieldSetElement : false,
  283. HTMLFontElement : false,
  284. HTMLFormElement : false,
  285. HTMLFrameElement : false,
  286. HTMLFrameSetElement : false,
  287. HTMLHeadElement : false,
  288. HTMLHeadingElement : false,
  289. HTMLHRElement : false,
  290. HTMLHtmlElement : false,
  291. HTMLIFrameElement : false,
  292. HTMLImageElement : false,
  293. HTMLInputElement : false,
  294. HTMLIsIndexElement : false,
  295. HTMLLabelElement : false,
  296. HTMLLayerElement : false,
  297. HTMLLegendElement : false,
  298. HTMLLIElement : false,
  299. HTMLLinkElement : false,
  300. HTMLMapElement : false,
  301. HTMLMenuElement : false,
  302. HTMLMetaElement : false,
  303. HTMLModElement : false,
  304. HTMLObjectElement : false,
  305. HTMLOListElement : false,
  306. HTMLOptGroupElement : false,
  307. HTMLOptionElement : false,
  308. HTMLParagraphElement : false,
  309. HTMLParamElement : false,
  310. HTMLPreElement : false,
  311. HTMLQuoteElement : false,
  312. HTMLScriptElement : false,
  313. HTMLSelectElement : false,
  314. HTMLStyleElement : false,
  315. HTMLTableCaptionElement: false,
  316. HTMLTableCellElement : false,
  317. HTMLTableColElement : false,
  318. HTMLTableElement : false,
  319. HTMLTableRowElement : false,
  320. HTMLTableSectionElement: false,
  321. HTMLTextAreaElement : false,
  322. HTMLTitleElement : false,
  323. HTMLUListElement : false,
  324. HTMLVideoElement : false,
  325. history : false,
  326. Image : false,
  327. length : false,
  328. localStorage : false,
  329. location : false,
  330. MessageChannel : false,
  331. MessageEvent : false,
  332. MessagePort : false,
  333. MouseEvent : false,
  334. moveBy : false,
  335. moveTo : false,
  336. MutationObserver : false,
  337. name : false,
  338. Node : false,
  339. NodeFilter : false,
  340. navigator : false,
  341. onbeforeunload : true,
  342. onblur : true,
  343. onerror : true,
  344. onfocus : true,
  345. onload : true,
  346. onresize : true,
  347. onunload : true,
  348. open : false,
  349. openDatabase : false,
  350. opener : false,
  351. Option : false,
  352. parent : false,
  353. print : false,
  354. removeEventListener : false,
  355. resizeBy : false,
  356. resizeTo : false,
  357. screen : false,
  358. scroll : false,
  359. scrollBy : false,
  360. scrollTo : false,
  361. sessionStorage : false,
  362. setInterval : false,
  363. setTimeout : false,
  364. SharedWorker : false,
  365. status : false,
  366. SVGAElement : false,
  367. SVGAltGlyphDefElement: false,
  368. SVGAltGlyphElement : false,
  369. SVGAltGlyphItemElement: false,
  370. SVGAngle : false,
  371. SVGAnimateColorElement: false,
  372. SVGAnimateElement : false,
  373. SVGAnimateMotionElement: false,
  374. SVGAnimateTransformElement: false,
  375. SVGAnimatedAngle : false,
  376. SVGAnimatedBoolean : false,
  377. SVGAnimatedEnumeration: false,
  378. SVGAnimatedInteger : false,
  379. SVGAnimatedLength : false,
  380. SVGAnimatedLengthList: false,
  381. SVGAnimatedNumber : false,
  382. SVGAnimatedNumberList: false,
  383. SVGAnimatedPathData : false,
  384. SVGAnimatedPoints : false,
  385. SVGAnimatedPreserveAspectRatio: false,
  386. SVGAnimatedRect : false,
  387. SVGAnimatedString : false,
  388. SVGAnimatedTransformList: false,
  389. SVGAnimationElement : false,
  390. SVGCSSRule : false,
  391. SVGCircleElement : false,
  392. SVGClipPathElement : false,
  393. SVGColor : false,
  394. SVGColorProfileElement: false,
  395. SVGColorProfileRule : false,
  396. SVGComponentTransferFunctionElement: false,
  397. SVGCursorElement : false,
  398. SVGDefsElement : false,
  399. SVGDescElement : false,
  400. SVGDocument : false,
  401. SVGElement : false,
  402. SVGElementInstance : false,
  403. SVGElementInstanceList: false,
  404. SVGEllipseElement : false,
  405. SVGExternalResourcesRequired: false,
  406. SVGFEBlendElement : false,
  407. SVGFEColorMatrixElement: false,
  408. SVGFEComponentTransferElement: false,
  409. SVGFECompositeElement: false,
  410. SVGFEConvolveMatrixElement: false,
  411. SVGFEDiffuseLightingElement: false,
  412. SVGFEDisplacementMapElement: false,
  413. SVGFEDistantLightElement: false,
  414. SVGFEFloodElement : false,
  415. SVGFEFuncAElement : false,
  416. SVGFEFuncBElement : false,
  417. SVGFEFuncGElement : false,
  418. SVGFEFuncRElement : false,
  419. SVGFEGaussianBlurElement: false,
  420. SVGFEImageElement : false,
  421. SVGFEMergeElement : false,
  422. SVGFEMergeNodeElement: false,
  423. SVGFEMorphologyElement: false,
  424. SVGFEOffsetElement : false,
  425. SVGFEPointLightElement: false,
  426. SVGFESpecularLightingElement: false,
  427. SVGFESpotLightElement: false,
  428. SVGFETileElement : false,
  429. SVGFETurbulenceElement: false,
  430. SVGFilterElement : false,
  431. SVGFilterPrimitiveStandardAttributes: false,
  432. SVGFitToViewBox : false,
  433. SVGFontElement : false,
  434. SVGFontFaceElement : false,
  435. SVGFontFaceFormatElement: false,
  436. SVGFontFaceNameElement: false,
  437. SVGFontFaceSrcElement: false,
  438. SVGFontFaceUriElement: false,
  439. SVGForeignObjectElement: false,
  440. SVGGElement : false,
  441. SVGGlyphElement : false,
  442. SVGGlyphRefElement : false,
  443. SVGGradientElement : false,
  444. SVGHKernElement : false,
  445. SVGICCColor : false,
  446. SVGImageElement : false,
  447. SVGLangSpace : false,
  448. SVGLength : false,
  449. SVGLengthList : false,
  450. SVGLineElement : false,
  451. SVGLinearGradientElement: false,
  452. SVGLocatable : false,
  453. SVGMPathElement : false,
  454. SVGMarkerElement : false,
  455. SVGMaskElement : false,
  456. SVGMatrix : false,
  457. SVGMetadataElement : false,
  458. SVGMissingGlyphElement: false,
  459. SVGNumber : false,
  460. SVGNumberList : false,
  461. SVGPaint : false,
  462. SVGPathElement : false,
  463. SVGPathSeg : false,
  464. SVGPathSegArcAbs : false,
  465. SVGPathSegArcRel : false,
  466. SVGPathSegClosePath : false,
  467. SVGPathSegCurvetoCubicAbs: false,
  468. SVGPathSegCurvetoCubicRel: false,
  469. SVGPathSegCurvetoCubicSmoothAbs: false,
  470. SVGPathSegCurvetoCubicSmoothRel: false,
  471. SVGPathSegCurvetoQuadraticAbs: false,
  472. SVGPathSegCurvetoQuadraticRel: false,
  473. SVGPathSegCurvetoQuadraticSmoothAbs: false,
  474. SVGPathSegCurvetoQuadraticSmoothRel: false,
  475. SVGPathSegLinetoAbs : false,
  476. SVGPathSegLinetoHorizontalAbs: false,
  477. SVGPathSegLinetoHorizontalRel: false,
  478. SVGPathSegLinetoRel : false,
  479. SVGPathSegLinetoVerticalAbs: false,
  480. SVGPathSegLinetoVerticalRel: false,
  481. SVGPathSegList : false,
  482. SVGPathSegMovetoAbs : false,
  483. SVGPathSegMovetoRel : false,
  484. SVGPatternElement : false,
  485. SVGPoint : false,
  486. SVGPointList : false,
  487. SVGPolygonElement : false,
  488. SVGPolylineElement : false,
  489. SVGPreserveAspectRatio: false,
  490. SVGRadialGradientElement: false,
  491. SVGRect : false,
  492. SVGRectElement : false,
  493. SVGRenderingIntent : false,
  494. SVGSVGElement : false,
  495. SVGScriptElement : false,
  496. SVGSetElement : false,
  497. SVGStopElement : false,
  498. SVGStringList : false,
  499. SVGStylable : false,
  500. SVGStyleElement : false,
  501. SVGSwitchElement : false,
  502. SVGSymbolElement : false,
  503. SVGTRefElement : false,
  504. SVGTSpanElement : false,
  505. SVGTests : false,
  506. SVGTextContentElement: false,
  507. SVGTextElement : false,
  508. SVGTextPathElement : false,
  509. SVGTextPositioningElement: false,
  510. SVGTitleElement : false,
  511. SVGTransform : false,
  512. SVGTransformList : false,
  513. SVGTransformable : false,
  514. SVGURIReference : false,
  515. SVGUnitTypes : false,
  516. SVGUseElement : false,
  517. SVGVKernElement : false,
  518. SVGViewElement : false,
  519. SVGViewSpec : false,
  520. SVGZoomAndPan : false,
  521. TimeEvent : false,
  522. top : false,
  523. WebSocket : false,
  524. window : false,
  525. Worker : false,
  526. XMLHttpRequest : false,
  527. XMLSerializer : false,
  528. XPathEvaluator : false,
  529. XPathException : false,
  530. XPathExpression : false,
  531. XPathNamespace : false,
  532. XPathNSResolver : false,
  533. XPathResult : false
  534. };
  535. exports.devel = {
  536. alert : false,
  537. confirm: false,
  538. console: false,
  539. Debug : false,
  540. opera : false,
  541. prompt : false
  542. };
  543. exports.worker = {
  544. importScripts: true,
  545. postMessage : true,
  546. self : true
  547. };
  548. // Widely adopted global names that are not part of ECMAScript standard
  549. exports.nonstandard = {
  550. escape : false,
  551. unescape: false
  552. };
  553. // Globals provided by popular JavaScript environments.
  554. exports.couch = {
  555. "require" : false,
  556. respond : false,
  557. getRow : false,
  558. emit : false,
  559. send : false,
  560. start : false,
  561. sum : false,
  562. log : false,
  563. exports : false,
  564. module : false,
  565. provides : false
  566. };
  567. exports.node = {
  568. __filename : false,
  569. __dirname : false,
  570. Buffer : false,
  571. console : false,
  572. exports : true, // In Node it is ok to exports = module.exports = foo();
  573. GLOBAL : false,
  574. global : false,
  575. module : false,
  576. process : false,
  577. require : false,
  578. setTimeout : false,
  579. clearTimeout : false,
  580. setInterval : false,
  581. clearInterval : false,
  582. setImmediate : false, // v0.9.1+
  583. clearImmediate: false // v0.9.1+
  584. };
  585. exports.phantom = {
  586. phantom : true,
  587. require : true,
  588. WebPage : true,
  589. console : true, // in examples, but undocumented
  590. exports : true // v1.7+
  591. };
  592. exports.rhino = {
  593. defineClass : false,
  594. deserialize : false,
  595. gc : false,
  596. help : false,
  597. importPackage: false,
  598. "java" : false,
  599. load : false,
  600. loadClass : false,
  601. print : false,
  602. quit : false,
  603. readFile : false,
  604. readUrl : false,
  605. runCommand : false,
  606. seal : false,
  607. serialize : false,
  608. spawn : false,
  609. sync : false,
  610. toint32 : false,
  611. version : false
  612. };
  613. exports.shelljs = {
  614. target : false,
  615. echo : false,
  616. exit : false,
  617. cd : false,
  618. pwd : false,
  619. ls : false,
  620. find : false,
  621. cp : false,
  622. rm : false,
  623. mv : false,
  624. mkdir : false,
  625. test : false,
  626. cat : false,
  627. sed : false,
  628. grep : false,
  629. which : false,
  630. dirs : false,
  631. pushd : false,
  632. popd : false,
  633. env : false,
  634. exec : false,
  635. chmod : false,
  636. config : false,
  637. error : false,
  638. tempdir : false
  639. };
  640. exports.typed = {
  641. ArrayBuffer : false,
  642. ArrayBufferView : false,
  643. DataView : false,
  644. Float32Array : false,
  645. Float64Array : false,
  646. Int16Array : false,
  647. Int32Array : false,
  648. Int8Array : false,
  649. Uint16Array : false,
  650. Uint32Array : false,
  651. Uint8Array : false,
  652. Uint8ClampedArray : false
  653. };
  654. exports.wsh = {
  655. ActiveXObject : true,
  656. Enumerator : true,
  657. GetObject : true,
  658. ScriptEngine : true,
  659. ScriptEngineBuildVersion : true,
  660. ScriptEngineMajorVersion : true,
  661. ScriptEngineMinorVersion : true,
  662. VBArray : true,
  663. WSH : true,
  664. WScript : true,
  665. XDomainRequest : true
  666. };
  667. // Globals provided by popular JavaScript libraries.
  668. exports.dojo = {
  669. dojo : false,
  670. dijit : false,
  671. dojox : false,
  672. define : false,
  673. "require": false
  674. };
  675. exports.jquery = {
  676. "$" : false,
  677. jQuery : false
  678. };
  679. exports.mootools = {
  680. "$" : false,
  681. "$$" : false,
  682. Asset : false,
  683. Browser : false,
  684. Chain : false,
  685. Class : false,
  686. Color : false,
  687. Cookie : false,
  688. Core : false,
  689. Document : false,
  690. DomReady : false,
  691. DOMEvent : false,
  692. DOMReady : false,
  693. Drag : false,
  694. Element : false,
  695. Elements : false,
  696. Event : false,
  697. Events : false,
  698. Fx : false,
  699. Group : false,
  700. Hash : false,
  701. HtmlTable : false,
  702. Iframe : false,
  703. IframeShim : false,
  704. InputValidator: false,
  705. instanceOf : false,
  706. Keyboard : false,
  707. Locale : false,
  708. Mask : false,
  709. MooTools : false,
  710. Native : false,
  711. Options : false,
  712. OverText : false,
  713. Request : false,
  714. Scroller : false,
  715. Slick : false,
  716. Slider : false,
  717. Sortables : false,
  718. Spinner : false,
  719. Swiff : false,
  720. Tips : false,
  721. Type : false,
  722. typeOf : false,
  723. URI : false,
  724. Window : false
  725. };
  726. exports.prototypejs = {
  727. "$" : false,
  728. "$$" : false,
  729. "$A" : false,
  730. "$F" : false,
  731. "$H" : false,
  732. "$R" : false,
  733. "$break" : false,
  734. "$continue" : false,
  735. "$w" : false,
  736. Abstract : false,
  737. Ajax : false,
  738. Class : false,
  739. Enumerable : false,
  740. Element : false,
  741. Event : false,
  742. Field : false,
  743. Form : false,
  744. Hash : false,
  745. Insertion : false,
  746. ObjectRange : false,
  747. PeriodicalExecuter: false,
  748. Position : false,
  749. Prototype : false,
  750. Selector : false,
  751. Template : false,
  752. Toggle : false,
  753. Try : false,
  754. Autocompleter : false,
  755. Builder : false,
  756. Control : false,
  757. Draggable : false,
  758. Draggables : false,
  759. Droppables : false,
  760. Effect : false,
  761. Sortable : false,
  762. SortableObserver : false,
  763. Sound : false,
  764. Scriptaculous : false
  765. };
  766. exports.yui = {
  767. YUI : false,
  768. Y : false,
  769. YUI_config: false
  770. };
  771. })()
  772. },{}],4:[function(require,module,exports){
  773. /*
  774. * Regular expressions. Some of these are stupidly long.
  775. */
  776. /*jshint maxlen:1000 */
  777. "use string";
  778. // Unsafe comment or string (ax)
  779. exports.unsafeString =
  780. /@cc|<\/?|script|\]\s*\]|<\s*!|&lt/i;
  781. // Unsafe characters that are silently deleted by one or more browsers (cx)
  782. exports.unsafeChars =
  783. /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
  784. // Characters in strings that need escaping (nx and nxg)
  785. exports.needEsc =
  786. /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
  787. exports.needEscGlobal =
  788. /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  789. // Star slash (lx)
  790. exports.starSlash = /\*\//;
  791. // Identifier (ix)
  792. exports.identifier = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/;
  793. // JavaScript URL (jx)
  794. exports.javascriptURL = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i;
  795. // Catches /* falls through */ comments (ft)
  796. exports.fallsThrough = /^\s*\/\*\s*falls?\sthrough\s*\*\/\s*$/;
  797. },{}],5:[function(require,module,exports){
  798. "use strict";
  799. var state = {
  800. syntax: {},
  801. reset: function () {
  802. this.tokens = {
  803. prev: null,
  804. next: null,
  805. curr: null
  806. };
  807. this.option = {};
  808. this.ignored = {};
  809. this.directive = {};
  810. this.jsonMode = false;
  811. this.jsonWarnings = [];
  812. this.lines = [];
  813. this.tab = "";
  814. this.cache = {}; // Node.JS doesn't have Map. Sniff.
  815. }
  816. };
  817. exports.state = state;
  818. },{}],6:[function(require,module,exports){
  819. (function(){"use strict";
  820. exports.register = function (linter) {
  821. // Check for properties named __proto__. This special property was
  822. // deprecated and then re-introduced for ES6.
  823. linter.on("Identifier", function style_scanProto(data) {
  824. if (linter.getOption("proto")) {
  825. return;
  826. }
  827. if (data.name === "__proto__") {
  828. linter.warn("W103", {
  829. line: data.line,
  830. char: data.char,
  831. data: [ data.name ]
  832. });
  833. }
  834. });
  835. // Check for properties named __iterator__. This is a special property
  836. // available only in browsers with JavaScript 1.7 implementation.
  837. linter.on("Identifier", function style_scanIterator(data) {
  838. if (linter.getOption("iterator")) {
  839. return;
  840. }
  841. if (data.name === "__iterator__") {
  842. linter.warn("W104", {
  843. line: data.line,
  844. char: data.char,
  845. data: [ data.name ]
  846. });
  847. }
  848. });
  849. // Check for dangling underscores.
  850. linter.on("Identifier", function style_scanDangling(data) {
  851. if (!linter.getOption("nomen")) {
  852. return;
  853. }
  854. // Underscore.js
  855. if (data.name === "_") {
  856. return;
  857. }
  858. // In Node, __dirname and __filename should be ignored.
  859. if (linter.getOption("node")) {
  860. if (/^(__dirname|__filename)$/.test(data.name) && !data.isProperty) {
  861. return;
  862. }
  863. }
  864. if (/^(_+.*|.*_+)$/.test(data.name)) {
  865. linter.warn("W105", {
  866. line: data.line,
  867. char: data.from,
  868. data: [ "dangling '_'", data.name ]
  869. });
  870. }
  871. });
  872. // Check that all identifiers are using camelCase notation.
  873. // Exceptions: names like MY_VAR and _myVar.
  874. linter.on("Identifier", function style_scanCamelCase(data) {
  875. if (!linter.getOption("camelcase")) {
  876. return;
  877. }
  878. if (data.name.replace(/^_+/, "").indexOf("_") > -1 && !data.name.match(/^[A-Z0-9_]*$/)) {
  879. linter.warn("W106", {
  880. line: data.line,
  881. char: data.from,
  882. data: [ data.name ]
  883. });
  884. }
  885. });
  886. // Enforce consistency in style of quoting.
  887. linter.on("String", function style_scanQuotes(data) {
  888. var quotmark = linter.getOption("quotmark");
  889. var code;
  890. if (!quotmark) {
  891. return;
  892. }
  893. // If quotmark is set to 'single' warn about all double-quotes.
  894. if (quotmark === "single" && data.quote !== "'") {
  895. code = "W109";
  896. }
  897. // If quotmark is set to 'double' warn about all single-quotes.
  898. if (quotmark === "double" && data.quote !== "\"") {
  899. code = "W108";
  900. }
  901. // If quotmark is set to true, remember the first quotation style
  902. // and then warn about all others.
  903. if (quotmark === true) {
  904. if (!linter.getCache("quotmark")) {
  905. linter.setCache("quotmark", data.quote);
  906. }
  907. if (linter.getCache("quotmark") !== data.quote) {
  908. code = "W110";
  909. }
  910. }
  911. if (code) {
  912. linter.warn(code, {
  913. line: data.line,
  914. char: data.char,
  915. });
  916. }
  917. });
  918. linter.on("Number", function style_scanNumbers(data) {
  919. if (data.value.charAt(0) === ".") {
  920. // Warn about a leading decimal point.
  921. linter.warn("W008", {
  922. line: data.line,
  923. char: data.char,
  924. data: [ data.value ]
  925. });
  926. }
  927. if (data.value.substr(data.value.length - 1) === ".") {
  928. // Warn about a trailing decimal point.
  929. linter.warn("W047", {
  930. line: data.line,
  931. char: data.char,
  932. data: [ data.value ]
  933. });
  934. }
  935. if (/^00+/.test(data.value)) {
  936. // Multiple leading zeroes.
  937. linter.warn("W046", {
  938. line: data.line,
  939. char: data.char,
  940. data: [ data.value ]
  941. });
  942. }
  943. });
  944. // Warn about script URLs.
  945. linter.on("String", function style_scanJavaScriptURLs(data) {
  946. var re = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i;
  947. if (linter.getOption("scripturl")) {
  948. return;
  949. }
  950. if (re.test(data.value)) {
  951. linter.warn("W107", {
  952. line: data.line,
  953. char: data.char
  954. });
  955. }
  956. });
  957. };
  958. })()
  959. },{}],7:[function(require,module,exports){
  960. (function(){"use strict";
  961. var _ = require("underscore");
  962. var errors = {
  963. // JSHint options
  964. E001: "Bad option: '{a}'.",
  965. E002: "Bad option value.",
  966. // JSHint input
  967. E003: "Expected a JSON value.",
  968. E004: "Input is neither a string nor an array of strings.",
  969. E005: "Input is empty.",
  970. E006: "Unexpected early end of program.",
  971. // Strict mode
  972. E007: "Missing \"use strict\" statement.",
  973. E008: "Strict violation.",
  974. E009: "Option 'validthis' can't be used in a global scope.",
  975. E010: "'with' is not allowed in strict mode.",
  976. // Constants
  977. E011: "const '{a}' has already been declared.",
  978. E012: "const '{a}' is initialized to 'undefined'.",
  979. E013: "Attempting to override '{a}' which is a constant.",
  980. // Regular expressions
  981. E014: "A regular expression literal can be confused with '/='.",
  982. E015: "Unclosed regular expression.",
  983. E016: "Invalid regular expression.",
  984. // Tokens
  985. E017: "Unclosed comment.",
  986. E018: "Unbegun comment.",
  987. E019: "Unmatched '{a}'.",
  988. E020: "Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.",
  989. E021: "Expected '{a}' and instead saw '{b}'.",
  990. E022: "Line breaking error '{a}'.",
  991. E023: "Missing '{a}'.",
  992. E024: "Unexpected '{a}'.",
  993. E025: "Missing ':' on a case clause.",
  994. E026: "Missing '}' to match '{' from line {a}.",
  995. E027: "Missing ']' to match '[' form line {a}.",
  996. E028: "Illegal comma.",
  997. E029: "Unclosed string.",
  998. // Everything else
  999. E030: "Expected an identifier and instead saw '{a}'.",
  1000. E031: "Bad assignment.", // FIXME: Rephrase
  1001. E032: "Expected a small integer or 'false' and instead saw '{a}'.",
  1002. E033: "Expected an operator and instead saw '{a}'.",
  1003. E034: "get/set are ES5 features.",
  1004. E035: "Missing property name.",
  1005. E036: "Expected to see a statement and instead saw a block.",
  1006. E037: null, // Vacant
  1007. E038: null, // Vacant
  1008. E039: "Function declarations are not invocable. Wrap the whole function invocation in parens.",
  1009. E040: "Each value should have its own case label.",
  1010. E041: "Unrecoverable syntax error.",
  1011. E042: "Stopping.",
  1012. E043: "Too many errors.",
  1013. E044: "'{a}' is already defined and can't be redefined.",
  1014. E045: "Invalid for each loop.",
  1015. E046: "A yield statement shall be within a generator function (with syntax: `function*`)",
  1016. E047: "A generator function shall contain a yield statement.",
  1017. E048: "Let declaration not directly within block.",
  1018. E049: "A {a} cannot be named '{b}'.",
  1019. E050: "Mozilla requires the yield expression to be parenthesized here.",
  1020. E051: "Regular parameters cannot come after default parameters."
  1021. };
  1022. var warnings = {
  1023. W001: "'hasOwnProperty' is a really bad name.",
  1024. W002: "Value of '{a}' may be overwritten in IE 8 and earlier.",
  1025. W003: "'{a}' was used before it was defined.",
  1026. W004: "'{a}' is already defined.",
  1027. W005: "A dot following a number can be confused with a decimal point.",
  1028. W006: "Confusing minuses.",
  1029. W007: "Confusing pluses.",
  1030. W008: "A leading decimal point can be confused with a dot: '{a}'.",
  1031. W009: "The array literal notation [] is preferrable.",
  1032. W010: "The object literal notation {} is preferrable.",
  1033. W011: "Unexpected space after '{a}'.",
  1034. W012: "Unexpected space before '{a}'.",
  1035. W013: "Missing space after '{a}'.",
  1036. W014: "Bad line breaking before '{a}'.",
  1037. W015: "Expected '{a}' to have an indentation at {b} instead at {c}.",
  1038. W016: "Unexpected use of '{a}'.",
  1039. W017: "Bad operand.",
  1040. W018: "Confusing use of '{a}'.",
  1041. W019: "Use the isNaN function to compare with NaN.",
  1042. W020: "Read only.",
  1043. W021: "'{a}' is a function.",
  1044. W022: "Do not assign to the exception parameter.",
  1045. W023: "Expected an identifier in an assignment and instead saw a function invocation.",
  1046. W024: "Expected an identifier and instead saw '{a}' (a reserved word).",
  1047. W025: "Missing name in function declaration.",
  1048. W026: "Inner functions should be listed at the top of the outer function.",
  1049. W027: "Unreachable '{a}' after '{b}'.",
  1050. W028: "Label '{a}' on {b} statement.",
  1051. W030: "Expected an assignment or function call and instead saw an expression.",
  1052. W031: "Do not use 'new' for side effects.",
  1053. W032: "Unnecessary semicolon.",
  1054. W033: "Missing semicolon.",
  1055. W034: "Unnecessary directive \"{a}\".",
  1056. W035: "Empty block.",
  1057. W036: "Unexpected /*member '{a}'.",
  1058. W037: "'{a}' is a statement label.",
  1059. W038: "'{a}' used out of scope.",
  1060. W039: "'{a}' is not allowed.",
  1061. W040: "Possible strict violation.",
  1062. W041: "Use '{a}' to compare with '{b}'.",
  1063. W042: "Avoid EOL escaping.",
  1064. W043: "Bad escaping of EOL. Use option multistr if needed.",
  1065. W044: "Bad or unnecessary escaping.",
  1066. W045: "Bad number '{a}'.",
  1067. W046: "Don't use extra leading zeros '{a}'.",
  1068. W047: "A trailing decimal point can be confused with a dot: '{a}'.",
  1069. W048: "Unexpected control character in regular expression.",
  1070. W049: "Unexpected escaped character '{a}' in regular expression.",
  1071. W050: "JavaScript URL.",
  1072. W051: "Variables should not be deleted.",
  1073. W052: "Unexpected '{a}'.",
  1074. W053: "Do not use {a} as a constructor.",
  1075. W054: "The Function constructor is a form of eval.",
  1076. W055: "A constructor name should start with an uppercase letter.",
  1077. W056: "Bad constructor.",
  1078. W057: "Weird construction. Is 'new' unnecessary?",
  1079. W058: "Missing '()' invoking a constructor.",
  1080. W059: "Avoid arguments.{a}.",
  1081. W060: "document.write can be a form of eval.",
  1082. W061: "eval can be harmful.",
  1083. W062: "Wrap an immediate function invocation in parens " +
  1084. "to assist the reader in understanding that the expression " +
  1085. "is the result of a function, and not the function itself.",
  1086. W063: "Math is not a function.",
  1087. W064: "Missing 'new' prefix when invoking a constructor.",
  1088. W065: "Missing radix parameter.",
  1089. W066: "Implied eval. Consider passing a function instead of a string.",
  1090. W067: "Bad invocation.",
  1091. W068: "Wrapping non-IIFE function literals in parens is unnecessary.",
  1092. W069: "['{a}'] is better written in dot notation.",
  1093. W070: "Extra comma. (it breaks older versions of IE)",
  1094. W071: "This function has too many statements. ({a})",
  1095. W072: "This function has too many parameters. ({a})",
  1096. W073: "Blocks are nested too deeply. ({a})",
  1097. W074: "This function's cyclomatic complexity is too high. ({a})",
  1098. W075: "Duplicate key '{a}'.",
  1099. W076: "Unexpected parameter '{a}' in get {b} function.",
  1100. W077: "Expected a single parameter in set {a} function.",
  1101. W078: "Setter is defined without getter.",
  1102. W079: "Redefinition of '{a}'.",
  1103. W080: "It's not necessary to initialize '{a}' to 'undefined'.",
  1104. W081: "Too many var statements.",
  1105. W082: "Function declarations should not be placed in blocks. " +
  1106. "Use a function expression or move the statement to the top of " +
  1107. "the outer function.",
  1108. W083: "Don't make functions within a loop.",
  1109. W084: "Expected a conditional expression and instead saw an assignment.",
  1110. W085: "Don't use 'with'.",
  1111. W086: "Expected a 'break' statement before '{a}'.",
  1112. W087: "Forgotten 'debugger' statement?",
  1113. W088: "Creating global 'for' variable. Should be 'for (var {a} ...'.",
  1114. W089: "The body of a for in should be wrapped in an if statement to filter " +
  1115. "unwanted properties from the prototype.",
  1116. W090: "'{a}' is not a statement label.",
  1117. W091: "'{a}' is out of scope.",
  1118. W092: "Wrap the /regexp/ literal in parens to disambiguate the slash operator.",
  1119. W093: "Did you mean to return a conditional instead of an assignment?",
  1120. W094: "Unexpected comma.",
  1121. W095: "Expected a string and instead saw {a}.",
  1122. W096: "The '{a}' key may produce unexpected results.",
  1123. W097: "Use the function form of \"use strict\".",
  1124. W098: "'{a}' is defined but never used.",
  1125. W099: "Mixed spaces and tabs.",
  1126. W100: "This character may get silently deleted by one or more browsers.",
  1127. W101: "Line is too long.",
  1128. W102: "Trailing whitespace.",
  1129. W103: "The '{a}' property is deprecated.",
  1130. W104: "'{a}' is only available in JavaScript 1.7.",
  1131. W105: "Unexpected {a} in '{b}'.",
  1132. W106: "Identifier '{a}' is not in camel case.",
  1133. W107: "Script URL.",
  1134. W108: "Strings must use doublequote.",
  1135. W109: "Strings must use singlequote.",
  1136. W110: "Mixed double and single quotes.",
  1137. W112: "Unclosed string.",
  1138. W113: "Control character in string: {a}.",
  1139. W114: "Avoid {a}.",
  1140. W115: "Octal literals are not allowed in strict mode.",
  1141. W116: "Expected '{a}' and instead saw '{b}'.",
  1142. W117: "'{a}' is not defined.",
  1143. W118: "'{a}' is only available in Mozilla JavaScript extensions (use moz option).",
  1144. W119: "'{a}' is only available in ES6 (use esnext option).",
  1145. W120: "You might be leaking a variable ({a}) here."
  1146. };
  1147. var info = {
  1148. I001: "Comma warnings can be turned off with 'laxcomma'.",
  1149. I002: "Reserved words as properties can be used under the 'es5' option.",
  1150. I003: "ES5 option is now set per default"
  1151. };
  1152. exports.errors = {};
  1153. exports.warnings = {};
  1154. exports.info = {};
  1155. _.each(errors, function (desc, code) {
  1156. exports.errors[code] = { code: code, desc: desc };
  1157. });
  1158. _.each(warnings, function (desc, code) {
  1159. exports.warnings[code] = { code: code, desc: desc };
  1160. });
  1161. _.each(info, function (desc, code) {
  1162. exports.info[code] = { code: code, desc: desc };
  1163. });
  1164. })()
  1165. },{"underscore":8}],9:[function(require,module,exports){
  1166. (function(){/*
  1167. * Lexical analysis and token construction.
  1168. */
  1169. "use strict";
  1170. var _ = require("underscore");
  1171. var events = require("events");
  1172. var reg = require("./reg.js");
  1173. var state = require("./state.js").state;
  1174. // Some of these token types are from JavaScript Parser API
  1175. // while others are specific to JSHint parser.
  1176. // JS Parser API: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  1177. var Token = {
  1178. Identifier: 1,
  1179. Punctuator: 2,
  1180. NumericLiteral: 3,
  1181. StringLiteral: 4,
  1182. Comment: 5,
  1183. Keyword: 6,
  1184. NullLiteral: 7,
  1185. BooleanLiteral: 8,
  1186. RegExp: 9
  1187. };
  1188. // This is auto generated from the unicode tables.
  1189. // The tables are at:
  1190. // http://www.fileformat.info/info/unicode/category/Lu/list.htm
  1191. // http://www.fileformat.info/info/unicode/category/Ll/list.htm
  1192. // http://www.fileformat.info/info/unicode/category/Lt/list.htm
  1193. // http://www.fileformat.info/info/unicode/category/Lm/list.htm
  1194. // http://www.fileformat.info/info/unicode/category/Lo/list.htm
  1195. // http://www.fileformat.info/info/unicode/category/Nl/list.htm
  1196. var unicodeLetterTable = [
  1197. 170, 170, 181, 181, 186, 186, 192, 214,
  1198. 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750,
  1199. 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908,
  1200. 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366,
  1201. 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610,
  1202. 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775,
  1203. 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957,
  1204. 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069,
  1205. 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2308, 2361,
  1206. 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431,
  1207. 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482,
  1208. 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529,
  1209. 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608,
  1210. 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654,
  1211. 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736,
  1212. 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785,
  1213. 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867,
  1214. 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929,
  1215. 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970,
  1216. 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001,
  1217. 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123,
  1218. 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212,
  1219. 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261,
  1220. 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344,
  1221. 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455,
  1222. 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526,
  1223. 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716,
  1224. 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743,
  1225. 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760,
  1226. 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805,
  1227. 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138,
  1228. 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198,
  1229. 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4304, 4346,
  1230. 4348, 4348, 4352, 4680, 4682, 4685, 4688, 4694, 4696, 4696,
  1231. 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789,
  1232. 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880,
  1233. 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740,
  1234. 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900,
  1235. 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000,
  1236. 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312,
  1237. 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516,
  1238. 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823,
  1239. 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7104, 7141,
  1240. 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409,
  1241. 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013,
  1242. 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061,
  1243. 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140,
  1244. 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188,
  1245. 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455,
  1246. 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486,
  1247. 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521,
  1248. 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358,
  1249. 11360, 11492, 11499, 11502, 11520, 11557, 11568, 11621,
  1250. 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694,
  1251. 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726,
  1252. 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295,
  1253. 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438,
  1254. 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589,
  1255. 12593, 12686, 12704, 12730, 12784, 12799, 13312, 13312,
  1256. 19893, 19893, 19968, 19968, 40907, 40907, 40960, 42124,
  1257. 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539,
  1258. 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783,
  1259. 42786, 42888, 42891, 42894, 42896, 42897, 42912, 42921,
  1260. 43002, 43009, 43011, 43013, 43015, 43018, 43020, 43042,
  1261. 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259,
  1262. 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442,
  1263. 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595,
  1264. 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697,
  1265. 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714,
  1266. 43739, 43741, 43777, 43782, 43785, 43790, 43793, 43798,
  1267. 43808, 43814, 43816, 43822, 43968, 44002, 44032, 44032,
  1268. 55203, 55203, 55216, 55238, 55243, 55291, 63744, 64045,
  1269. 64048, 64109, 64112, 64217, 64256, 64262, 64275, 64279,
  1270. 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316,
  1271. 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433,
  1272. 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019,
  1273. 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370,
  1274. 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495,
  1275. 65498, 65500, 65536, 65547, 65549, 65574, 65576, 65594,
  1276. 65596, 65597, 65599, 65613, 65616, 65629, 65664, 65786,
  1277. 65856, 65908, 66176, 66204, 66208, 66256, 66304, 66334,
  1278. 66352, 66378, 66432, 66461, 66464, 66499, 66504, 66511,
  1279. 66513, 66517, 66560, 66717, 67584, 67589, 67592, 67592,
  1280. 67594, 67637, 67639, 67640, 67644, 67644, 67647, 67669,
  1281. 67840, 67861, 67872, 67897, 68096, 68096, 68112, 68115,
  1282. 68117, 68119, 68121, 68147, 68192, 68220, 68352, 68405,
  1283. 68416, 68437, 68448, 68466, 68608, 68680, 69635, 69687,
  1284. 69763, 69807, 73728, 74606, 74752, 74850, 77824, 78894,
  1285. 92160, 92728, 110592, 110593, 119808, 119892, 119894, 119964,
  1286. 119966, 119967, 119970, 119970, 119973, 119974, 119977, 119980,
  1287. 119982, 119993, 119995, 119995, 119997, 120003, 120005, 120069,
  1288. 120071, 120074, 120077, 120084, 120086, 120092, 120094, 120121,
  1289. 120123, 120126, 120128, 120132, 120134, 120134, 120138, 120144,
  1290. 120146, 120485, 120488, 120512, 120514, 120538, 120540, 120570,
  1291. 120572, 120596, 120598, 120628, 120630, 120654, 120656, 120686,
  1292. 120688, 120712, 120714, 120744, 120746, 120770, 120772, 120779,
  1293. 131072, 131072, 173782, 173782, 173824, 173824, 177972, 177972,
  1294. 177984, 177984, 178205, 178205, 194560, 195101
  1295. ];
  1296. var identifierStartTable = [];
  1297. for (var i = 0; i < 128; i++) {
  1298. identifierStartTable[i] =
  1299. i === 36 || // $
  1300. i >= 65 && i <= 90 || // A-Z
  1301. i === 95 || // _
  1302. i >= 97 && i <= 122; // a-z
  1303. }
  1304. var identifierPartTable = [];
  1305. for (var i = 0; i < 128; i++) {
  1306. identifierPartTable[i] =
  1307. identifierStartTable[i] || // $, _, A-Z, a-z
  1308. i >= 48 && i <= 57; // 0-9
  1309. }
  1310. // Object that handles postponed lexing verifications that checks the parsed
  1311. // environment state.
  1312. function asyncTrigger() {
  1313. var _checks = [];
  1314. return {
  1315. push: function (fn) {
  1316. _checks.push(fn);
  1317. },
  1318. check: function () {
  1319. for (var check = 0; check < _checks.length; ++check) {
  1320. _checks[check]();
  1321. }
  1322. _checks.splice(0, _checks.length);
  1323. }
  1324. };
  1325. }
  1326. /*
  1327. * Lexer for JSHint.
  1328. *
  1329. * This object does a char-by-char scan of the provided source code
  1330. * and produces a sequence of tokens.
  1331. *
  1332. * var lex = new Lexer("var i = 0;");
  1333. * lex.start();
  1334. * lex.token(); // returns the next token
  1335. *
  1336. * You have to use the token() method to move the lexer forward
  1337. * but you don't have to use its return value to get tokens. In addition
  1338. * to token() method returning the next token, the Lexer object also
  1339. * emits events.
  1340. *
  1341. * lex.on("Identifier", function (data) {
  1342. * if (data.name.indexOf("_") >= 0) {
  1343. * // Produce a warning.
  1344. * }
  1345. * });
  1346. *
  1347. * Note that the token() method returns tokens in a JSLint-compatible
  1348. * format while the event emitter uses a slightly modified version of
  1349. * Mozilla's JavaScript Parser API. Eventually, we will move away from
  1350. * JSLint format.
  1351. */
  1352. function Lexer(source) {
  1353. var lines = source;
  1354. if (typeof lines === "string") {
  1355. lines = lines
  1356. .replace(/\r\n/g, "\n")
  1357. .replace(/\r/g, "\n")
  1358. .split("\n");
  1359. }
  1360. // If the first line is a shebang (#!), make it a blank and move on.
  1361. // Shebangs are used by Node scripts.
  1362. if (lines[0] && lines[0].substr(0, 2) === "#!") {
  1363. lines[0] = "";
  1364. }
  1365. this.emitter = new events.EventEmitter();
  1366. this.source = source;
  1367. this.setLines(lines);
  1368. this.prereg = true;
  1369. this.line = 0;
  1370. this.char = 1;
  1371. this.from = 1;
  1372. this.input = "";
  1373. for (var i = 0; i < state.option.indent; i += 1) {
  1374. state.tab += " ";
  1375. }
  1376. }
  1377. Lexer.prototype = {
  1378. _lines: [],
  1379. getLines: function () {
  1380. this._lines = state.lines;
  1381. return this._lines;
  1382. },
  1383. setLines: function (val) {
  1384. this._lines = val;
  1385. state.lines = this._lines;
  1386. },
  1387. /*
  1388. * Return the next i character without actually moving the
  1389. * char pointer.
  1390. */
  1391. peek: function (i) {
  1392. return this.input.charAt(i || 0);
  1393. },
  1394. /*
  1395. * Move the char pointer forward i times.
  1396. */
  1397. skip: function (i) {
  1398. i = i || 1;
  1399. this.char += i;
  1400. this.input = this.input.slice(i);
  1401. },
  1402. /*
  1403. * Subscribe to a token event. The API for this method is similar
  1404. * Underscore.js i.e. you can subscribe to multiple events with
  1405. * one call:
  1406. *
  1407. * lex.on("Identifier Number", function (data) {
  1408. * // ...
  1409. * });
  1410. */
  1411. on: function (names, listener) {
  1412. names.split(" ").forEach(function (name) {
  1413. this.emitter.on(name, listener);
  1414. }.bind(this));
  1415. },
  1416. /*
  1417. * Trigger a token event. All arguments will be passed to each
  1418. * listener.
  1419. */
  1420. trigger: function () {
  1421. this.emitter.emit.apply(this.emitter, Array.prototype.slice.call(arguments));
  1422. },
  1423. /*
  1424. * Postpone a token event. the checking condition is set as
  1425. * last parameter, and the trigger function is called in a
  1426. * stored callback. To be later called using the check() function
  1427. * by the parser. This avoids parser's peek() to give the lexer
  1428. * a false context.
  1429. */
  1430. triggerAsync: function (type, args, checks, fn) {
  1431. checks.push(function () {
  1432. if (fn()) {
  1433. this.trigger(type, args);
  1434. }
  1435. }.bind(this));
  1436. },
  1437. /*
  1438. * Extract a punctuator out of the next sequence of characters
  1439. * or return 'null' if its not possible.
  1440. *
  1441. * This method's implementation was heavily influenced by the
  1442. * scanPunctuator function in the Esprima parser's source code.
  1443. */
  1444. scanPunctuator: function () {
  1445. var ch1 = this.peek();
  1446. var ch2, ch3, ch4;
  1447. switch (ch1) {
  1448. // Most common single-character punctuators
  1449. case ".":
  1450. if ((/^[0-9]$/).test(this.peek(1))) {
  1451. return null;
  1452. }
  1453. if (this.peek(1) === "." && this.peek(2) === ".") {
  1454. return {
  1455. type: Token.Punctuator,
  1456. value: "..."
  1457. };
  1458. }
  1459. /* falls through */
  1460. case "(":
  1461. case ")":
  1462. case ";":
  1463. case ",":
  1464. case "{":
  1465. case "}":
  1466. case "[":
  1467. case "]":
  1468. case ":":
  1469. case "~":
  1470. case "?":
  1471. return {
  1472. type: Token.Punctuator,
  1473. value: ch1
  1474. };
  1475. // A pound sign (for Node shebangs)
  1476. case "#":
  1477. return {
  1478. type: Token.Punctuator,
  1479. value: ch1
  1480. };
  1481. // We're at the end of input
  1482. case "":
  1483. return null;
  1484. }
  1485. // Peek more characters
  1486. ch2 = this.peek(1);
  1487. ch3 = this.peek(2);
  1488. ch4 = this.peek(3);
  1489. // 4-character punctuator: >>>=
  1490. if (ch1 === ">" && ch2 === ">" && ch3 === ">" && ch4 === "=") {
  1491. return {
  1492. type: Token.Punctuator,
  1493. value: ">>>="
  1494. };
  1495. }
  1496. // 3-character punctuators: === !== >>> <<= >>=
  1497. if (ch1 === "=" && ch2 === "=" && ch3 === "=") {
  1498. return {
  1499. type: Token.Punctuator,
  1500. value: "==="
  1501. };
  1502. }
  1503. if (ch1 === "!" && ch2 === "=" && ch3 === "=") {
  1504. return {
  1505. type: Token.Punctuator,
  1506. value: "!=="
  1507. };
  1508. }
  1509. if (ch1 === ">" && ch2 === ">" && ch3 === ">") {
  1510. return {
  1511. type: Token.Punctuator,
  1512. value: ">>>"
  1513. };
  1514. }
  1515. if (ch1 === "<" && ch2 === "<" && ch3 === "=") {
  1516. return {
  1517. type: Token.Punctuator,
  1518. value: "<<="
  1519. };
  1520. }
  1521. if (ch1 === ">" && ch2 === ">" && ch3 === "=") {
  1522. return {
  1523. type: Token.Punctuator,
  1524. value: ">>="
  1525. };
  1526. }
  1527. // Fat arrow punctuator
  1528. if (ch1 === "=" && ch2 === ">") {
  1529. return {
  1530. type: Token.Punctuator,
  1531. value: ch1 + ch2
  1532. };
  1533. }
  1534. // 2-character punctuators: <= >= == != ++ -- << >> && ||
  1535. // += -= *= %= &= |= ^= (but not /=, see below)
  1536. if (ch1 === ch2 && ("+-<>&|".indexOf(ch1) >= 0)) {
  1537. return {
  1538. type: Token.Punctuator,
  1539. value: ch1 + ch2
  1540. };
  1541. }
  1542. if ("<>=!+-*%&|^".indexOf(ch1) >= 0) {
  1543. if (ch2 === "=") {
  1544. return {
  1545. type: Token.Punctuator,
  1546. value: ch1 + ch2
  1547. };
  1548. }
  1549. return {
  1550. type: Token.Punctuator,
  1551. value: ch1
  1552. };
  1553. }
  1554. // Special case: /=. We need to make sure that this is an
  1555. // operator and not a regular expression.
  1556. if (ch1 === "/") {
  1557. if (ch2 === "=" && /\/=(?!(\S*\/[gim]?))/.test(this.input)) {
  1558. // /= is not a part of a regular expression, return it as a
  1559. // punctuator.
  1560. return {
  1561. type: Token.Punctuator,
  1562. value: "/="
  1563. };
  1564. }
  1565. return {
  1566. type: Token.Punctuator,
  1567. value: "/"
  1568. };
  1569. }
  1570. return null;
  1571. },
  1572. /*
  1573. * Extract a comment out of the next sequence of characters and/or
  1574. * lines or return 'null' if its not possible. Since comments can
  1575. * span across multiple lines this method has to move the char
  1576. * pointer.
  1577. *
  1578. * In addition to normal JavaScript comments (// and /*) this method
  1579. * also recognizes JSHint- and JSLint-specific comments such as
  1580. * /*jshint, /*jslint, /*globals and so on.
  1581. */
  1582. scanComments: function () {
  1583. var ch1 = this.peek();
  1584. var ch2 = this.peek(1);
  1585. var rest = this.input.substr(2);
  1586. var startLine = this.line;
  1587. var startChar = this.char;
  1588. // Create a comment token object and make sure it
  1589. // has all the data JSHint needs to work with special
  1590. // comments.
  1591. function commentToken(label, body, opt) {
  1592. var special = ["jshint", "jslint", "members", "member", "globals", "global", "exported"];
  1593. var isSpecial = false;
  1594. var value = label + body;
  1595. var commentType = "plain";
  1596. opt = opt || {};
  1597. if (opt.isMultiline) {
  1598. value += "*/";
  1599. }
  1600. special.forEach(function (str) {
  1601. if (isSpecial) {
  1602. return;
  1603. }
  1604. // Don't recognize any special comments other than jshint for single-line
  1605. // comments. This introduced many problems with legit comments.
  1606. if (label === "//" && str !== "jshint") {
  1607. return;
  1608. }
  1609. if (body.substr(0, str.length) === str) {
  1610. isSpecial = true;
  1611. label = label + str;
  1612. body = body.substr(str.length);
  1613. }
  1614. if (!isSpecial && body.charAt(0) === " " && body.substr(1, str.length) === str) {
  1615. isSpecial = true;
  1616. label = label + " " + str;
  1617. body = body.substr(str.length + 1);
  1618. }
  1619. if (!isSpecial) {
  1620. return;
  1621. }
  1622. switch (str) {
  1623. case "member":
  1624. commentType = "members";
  1625. break;
  1626. case "global":
  1627. commentType = "globals";
  1628. break;
  1629. default:
  1630. commentType = str;
  1631. }
  1632. });
  1633. return {
  1634. type: Token.Comment,
  1635. commentType: commentType,
  1636. value: value,
  1637. body: body,
  1638. isSpecial: isSpecial,
  1639. isMultiline: opt.isMultiline || false,
  1640. isMalformed: opt.isMalformed || false
  1641. };
  1642. }
  1643. // End of unbegun comment. Raise an error and skip that input.
  1644. if (ch1 === "*" && ch2 === "/") {
  1645. this.trigger("error", {
  1646. code: "E018",
  1647. line: startLine,
  1648. character: startChar
  1649. });
  1650. this.skip(2);
  1651. return null;
  1652. }
  1653. // Comments must start either with // or /*
  1654. if (ch1 !== "/" || (ch2 !== "*" && ch2 !== "/")) {
  1655. return null;
  1656. }
  1657. // One-line comment
  1658. if (ch2 === "/") {
  1659. this.skip(this.input.length); // Skip to the EOL.
  1660. return commentToken("//", rest);
  1661. }
  1662. var body = "";
  1663. /* Multi-line comment */
  1664. if (ch2 === "*") {
  1665. this.skip(2);
  1666. while (this.peek() !== "*" || this.peek(1) !== "/") {
  1667. if (this.peek() === "") { // End of Line
  1668. body += "\n";
  1669. // If we hit EOF and our comment is still unclosed,
  1670. // trigger an error and end the comment implicitly.
  1671. if (!this.nextLine()) {
  1672. this.trigger("error", {
  1673. code: "E017",
  1674. line: startLine,
  1675. character: startChar
  1676. });
  1677. return commentToken("/*", body, {
  1678. isMultiline: true,
  1679. isMalformed: true
  1680. });
  1681. }
  1682. } else {
  1683. body += this.peek();
  1684. this.skip();
  1685. }
  1686. }
  1687. this.skip(2);
  1688. return commentToken("/*", body, { isMultiline: true });
  1689. }
  1690. },
  1691. /*
  1692. * Extract a keyword out of the next sequence of characters or
  1693. * return 'null' if its not possible.
  1694. */
  1695. scanKeyword: function () {
  1696. var result = /^[a-zA-Z_$][a-zA-Z0-9_$]*/.exec(this.input);
  1697. var keywords = [
  1698. "if", "in", "do", "var", "for", "new",
  1699. "try", "let", "this", "else", "case",
  1700. "void", "with", "enum", "while", "break",
  1701. "catch", "throw", "const", "yield", "class",
  1702. "super", "return", "typeof", "delete",
  1703. "switch", "export", "import", "default",
  1704. "finally", "extends", "function", "continue",
  1705. "debugger", "instanceof"
  1706. ];
  1707. if (result && keywords.indexOf(result[0]) >= 0) {
  1708. return {
  1709. type: Token.Keyword,
  1710. value: result[0]
  1711. };
  1712. }
  1713. return null;
  1714. },
  1715. /*
  1716. * Extract a JavaScript identifier out of the next sequence of
  1717. * characters or return 'null' if its not possible. In addition,
  1718. * to Identifier this method can also produce BooleanLiteral
  1719. * (true/false) and NullLiteral (null).
  1720. */
  1721. scanIdentifier: function () {
  1722. var id = "";
  1723. var index = 0;
  1724. var type, char;
  1725. // Detects any character in the Unicode categories "Uppercase
  1726. // letter (Lu)", "Lowercase letter (Ll)", "Titlecase letter
  1727. // (Lt)", "Modifier letter (Lm)", "Other letter (Lo)", or
  1728. // "Letter number (Nl)".
  1729. //
  1730. // Both approach and unicodeLetterTable were borrowed from
  1731. // Google's Traceur.
  1732. function isUnicodeLetter(code) {
  1733. for (var i = 0; i < unicodeLetterTable.length;) {
  1734. if (code < unicodeLetterTable[i++]) {
  1735. return false;
  1736. }
  1737. if (code <= unicodeLetterTable[i++]) {
  1738. return true;
  1739. }
  1740. }
  1741. return false;
  1742. }
  1743. function isHexDigit(str) {
  1744. return (/^[0-9a-fA-F]$/).test(str);
  1745. }
  1746. var readUnicodeEscapeSequence = function () {
  1747. /*jshint validthis:true */
  1748. index += 1;
  1749. if (this.peek(index) !== "u") {
  1750. return null;
  1751. }
  1752. var ch1 = this.peek(index + 1);
  1753. var ch2 = this.peek(index + 2);
  1754. var ch3 = this.peek(index + 3);
  1755. var ch4 = this.peek(index + 4);
  1756. var code;
  1757. if (isHexDigit(ch1) && isHexDigit(ch2) && isHexDigit(ch3) && isHexDigit(ch4)) {
  1758. code = parseInt(ch1 + ch2 + ch3 + ch4, 16);
  1759. if (isUnicodeLetter(code)) {
  1760. index += 5;
  1761. return "\\u" + ch1 + ch2 + ch3 + ch4;
  1762. }
  1763. return null;
  1764. }
  1765. return null;
  1766. }.bind(this);
  1767. var getIdentifierStart = function () {
  1768. /*jshint validthis:true */
  1769. var chr = this.peek(index);
  1770. var code = chr.charCodeAt(0);
  1771. if (code === 92) {
  1772. return readUnicodeEscapeSequence();
  1773. }
  1774. if (code < 128) {
  1775. if (identifierStartTable[code]) {
  1776. index += 1;
  1777. return chr;
  1778. }
  1779. return null;
  1780. }
  1781. if (isUnicodeLetter(code)) {
  1782. index += 1;
  1783. return chr;
  1784. }
  1785. return null;
  1786. }.bind(this);
  1787. var getIdentifierPart = function () {
  1788. /*jshint validthis:true */
  1789. var chr = this.peek(index);
  1790. var code = chr.charCodeAt(0);
  1791. if (code === 92) {
  1792. return readUnicodeEscapeSequence();
  1793. }
  1794. if (code < 128) {
  1795. if (identifierPartTable[code]) {
  1796. index += 1;
  1797. return chr;
  1798. }
  1799. return null;
  1800. }
  1801. if (isUnicodeLetter(code)) {
  1802. index += 1;
  1803. return chr;
  1804. }
  1805. return null;
  1806. }.bind(this);
  1807. char = getIdentifierStart();
  1808. if (char === null) {
  1809. return null;
  1810. }
  1811. id = char;
  1812. for (;;) {
  1813. char = getIdentifierPart();
  1814. if (char === null) {
  1815. break;
  1816. }
  1817. id += char;
  1818. }
  1819. switch (id) {
  1820. case "true":
  1821. case "false":
  1822. type = Token.BooleanLiteral;
  1823. break;
  1824. case "null":
  1825. type = Token.NullLiteral;
  1826. break;
  1827. default:
  1828. type = Token.Identifier;
  1829. }
  1830. return {
  1831. type: type,
  1832. value: id
  1833. };
  1834. },
  1835. /*
  1836. * Extract a numeric literal out of the next sequence of
  1837. * characters or return 'null' if its not possible. This method
  1838. * supports all numeric literals described in section 7.8.3
  1839. * of the EcmaScript 5 specification.
  1840. *
  1841. * This method's implementation was heavily influenced by the
  1842. * scanNumericLiteral function in the Esprima parser's source code.
  1843. */
  1844. scanNumericLiteral: function () {
  1845. var index = 0;
  1846. var value = "";
  1847. var length = this.input.length;
  1848. var char = this.peek(index);
  1849. var bad;
  1850. function isDecimalDigit(str) {
  1851. return (/^[0-9]$/).test(str);
  1852. }
  1853. function isOctalDigit(str) {
  1854. return (/^[0-7]$/).test(str);
  1855. }
  1856. function isHexDigit(str) {
  1857. return (/^[0-9a-fA-F]$/).test(str);
  1858. }
  1859. function isIdentifierStart(ch) {
  1860. return (ch === "$") || (ch === "_") || (ch === "\\") ||
  1861. (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z");
  1862. }
  1863. // Numbers must start either with a decimal digit or a point.
  1864. if (char !== "." && !isDecimalDigit(char)) {
  1865. return null;
  1866. }
  1867. if (char !== ".") {
  1868. value = this.peek(index);
  1869. index += 1;
  1870. char = this.peek(index);
  1871. if (value === "0") {
  1872. // Base-16 numbers.
  1873. if (char === "x" || char === "X") {
  1874. index += 1;
  1875. value += char;
  1876. while (index < length) {
  1877. char = this.peek(index);
  1878. if (!isHexDigit(char)) {
  1879. break;
  1880. }
  1881. value += char;
  1882. index += 1;
  1883. }
  1884. if (value.length <= 2) { // 0x
  1885. return {
  1886. type: Token.NumericLiteral,
  1887. value: value,
  1888. isMalformed: true
  1889. };
  1890. }
  1891. if (index < length) {
  1892. char = this.peek(index);
  1893. if (isIdentifierStart(char)) {
  1894. return null;
  1895. }
  1896. }
  1897. return {
  1898. type: Token.NumericLiteral,
  1899. value: value,
  1900. base: 16,
  1901. isMalformed: false
  1902. };
  1903. }
  1904. // Base-8 numbers.
  1905. if (isOctalDigit(char)) {
  1906. index += 1;
  1907. value += char;
  1908. bad = false;
  1909. while (index < length) {
  1910. char = this.peek(index);
  1911. // Numbers like '019' (note the 9) are not valid octals
  1912. // but we still parse them and mark as malformed.
  1913. if (isDecimalDigit(char)) {
  1914. bad = true;
  1915. } else if (!isOctalDigit(char)) {
  1916. break;
  1917. }
  1918. value += char;
  1919. index += 1;
  1920. }
  1921. if (index < length) {
  1922. char = this.peek(index);
  1923. if (isIdentifierStart(char)) {
  1924. return null;
  1925. }
  1926. }
  1927. return {
  1928. type: Token.NumericLiteral,
  1929. value: value,
  1930. base: 8,
  1931. isMalformed: false
  1932. };
  1933. }
  1934. // Decimal numbers that start with '0' such as '09' are illegal
  1935. // but we still parse them and return as malformed.
  1936. if (isDecimalDigit(char)) {
  1937. index += 1;
  1938. value += char;
  1939. }
  1940. }
  1941. while (index < length) {
  1942. char = this.peek(index);
  1943. if (!isDecimalDigit(char)) {
  1944. break;
  1945. }
  1946. value += char;
  1947. index += 1;
  1948. }
  1949. }
  1950. // Decimal digits.
  1951. if (char === ".") {
  1952. value += char;
  1953. index += 1;
  1954. while (index < length) {
  1955. char = this.peek(index);
  1956. if (!isDecimalDigit(char)) {
  1957. break;
  1958. }
  1959. value += char;
  1960. index += 1;
  1961. }
  1962. }
  1963. // Exponent part.
  1964. if (char === "e" || char === "E") {
  1965. value += char;
  1966. index += 1;
  1967. char = this.peek(index);
  1968. if (char === "+" || char === "-") {
  1969. value += this.peek(index);
  1970. index += 1;
  1971. }
  1972. char = this.peek(index);
  1973. if (isDecimalDigit(char)) {
  1974. value += char;
  1975. index += 1;
  1976. while (index < length) {
  1977. char = this.peek(index);
  1978. if (!isDecimalDigit(char)) {
  1979. break;
  1980. }
  1981. value += char;
  1982. index += 1;
  1983. }
  1984. } else {
  1985. return null;
  1986. }
  1987. }
  1988. if (index < length) {
  1989. char = this.peek(index);
  1990. if (isIdentifierStart(char)) {
  1991. return null;
  1992. }
  1993. }
  1994. return {
  1995. type: Token.NumericLiteral,
  1996. value: value,
  1997. base: 10,
  1998. isMalformed: !isFinite(value)
  1999. };
  2000. },
  2001. /*
  2002. * Extract a string out of the next sequence of characters and/or
  2003. * lines or return 'null' if its not possible. Since strings can
  2004. * span across multiple lines this method has to move the char
  2005. * pointer.
  2006. *
  2007. * This method recognizes pseudo-multiline JavaScript strings:
  2008. *
  2009. * var str = "hello\
  2010. * world";
  2011. */
  2012. scanStringLiteral: function (checks) {
  2013. /*jshint loopfunc:true */
  2014. var quote = this.peek();
  2015. // String must start with a quote.
  2016. if (quote !== "\"" && quote !== "'") {
  2017. return null;
  2018. }
  2019. // In JSON strings must always use double quotes.
  2020. this.triggerAsync("warning", {
  2021. code: "W108",
  2022. line: this.line,
  2023. character: this.char // +1?
  2024. }, checks, function () { return state.jsonMode && quote !== "\""; });
  2025. var value = "";
  2026. var startLine = this.line;
  2027. var startChar = this.char;
  2028. var allowNewLine = false;
  2029. this.skip();
  2030. while (this.peek() !== quote) {
  2031. while (this.peek() === "") { // End Of Line
  2032. // If an EOL is not preceded by a backslash, show a warning
  2033. // and proceed like it was a legit multi-line string where
  2034. // author simply forgot to escape the newline symbol.
  2035. //
  2036. // Another approach is to implicitly close a string on EOL
  2037. // but it generates too many false positives.
  2038. if (!allowNewLine) {
  2039. this.trigger("warning", {
  2040. code: "W112",
  2041. line: this.line,
  2042. character: this.char
  2043. });
  2044. } else {
  2045. allowNewLine = false;
  2046. // Otherwise show a warning if multistr option was not set.
  2047. // For JSON, show warning no matter what.
  2048. this.triggerAsync("warning", {
  2049. code: "W043",
  2050. line: this.line,
  2051. character: this.char
  2052. }, checks, function () { return !state.option.multistr; });
  2053. this.triggerAsync("warning", {
  2054. code: "W042",
  2055. line: this.line,
  2056. character: this.char
  2057. }, checks, function () { return state.jsonMode && state.option.multistr; });
  2058. }
  2059. // If we get an EOF inside of an unclosed string, show an
  2060. // error and implicitly close it at the EOF point.
  2061. if (!this.nextLine()) {
  2062. this.trigger("error", {
  2063. code: "E029",
  2064. line: startLine,
  2065. character: startChar
  2066. });
  2067. return {
  2068. type: Token.StringLiteral,
  2069. value: value,
  2070. isUnclosed: true,
  2071. quote: quote
  2072. };
  2073. }
  2074. }
  2075. allowNewLine = false;
  2076. var char = this.peek();
  2077. var jump = 1; // A length of a jump, after we're done
  2078. // parsing this character.
  2079. if (char < " ") {
  2080. // Warn about a control character in a string.
  2081. this.trigger("warning", {
  2082. code: "W113",
  2083. line: this.line,
  2084. character: this.char,
  2085. data: [ "<non-printable>" ]
  2086. });
  2087. }
  2088. // Special treatment for some escaped characters.
  2089. if (char === "\\") {
  2090. this.skip();
  2091. char = this.peek();
  2092. switch (char) {
  2093. case "'":
  2094. this.triggerAsync("warning", {
  2095. code: "W114",
  2096. line: this.line,
  2097. character: this.char,
  2098. data: [ "\\'" ]
  2099. }, checks, function () {return state.jsonMode; });
  2100. break;
  2101. case "b":
  2102. char = "\b";
  2103. break;
  2104. case "f":
  2105. char = "\f";
  2106. break;
  2107. case "n":
  2108. char = "\n";
  2109. break;
  2110. case "r":
  2111. char = "\r";
  2112. break;
  2113. case "t":
  2114. char = "\t";
  2115. break;
  2116. case "0":
  2117. char = "\0";
  2118. // Octal literals fail in strict mode.
  2119. // Check if the number is between 00 and 07.
  2120. var n = parseInt(this.peek(1), 10);
  2121. this.triggerAsync("warning", {
  2122. code: "W115",
  2123. line: this.line,
  2124. character: this.char
  2125. }, checks,
  2126. function () { return n >= 0 && n <= 7 && state.directive["use strict"]; });
  2127. break;
  2128. case "u":
  2129. char = String.fromCharCode(parseInt(this.input.substr(1, 4), 16));
  2130. jump = 5;
  2131. break;
  2132. case "v":
  2133. this.triggerAsync("warning", {
  2134. code: "W114",
  2135. line: this.line,
  2136. character: this.char,
  2137. data: [ "\\v" ]
  2138. }, checks, function () { return state.jsonMode; });
  2139. char = "\v";
  2140. break;
  2141. case "x":
  2142. var x = parseInt(this.input.substr(1, 2), 16);
  2143. this.triggerAsync("warning", {
  2144. code: "W114",
  2145. line: this.line,
  2146. character: this.char,
  2147. data: [ "\\x-" ]
  2148. }, checks, function () { return state.jsonMode; });
  2149. char = String.fromCharCode(x);
  2150. jump = 3;
  2151. break;
  2152. case "\\":
  2153. case "\"":
  2154. case "/":
  2155. break;
  2156. case "":
  2157. allowNewLine = true;
  2158. char = "";
  2159. break;
  2160. case "!":
  2161. if (value.slice(value.length - 2) === "<") {
  2162. break;
  2163. }
  2164. /*falls through */
  2165. default:
  2166. // Weird escaping.
  2167. this.trigger("warning", {
  2168. code: "W044",
  2169. line: this.line,
  2170. character: this.char
  2171. });
  2172. }
  2173. }
  2174. value += char;
  2175. this.skip(jump);
  2176. }
  2177. this.skip();
  2178. return {
  2179. type: Token.StringLiteral,
  2180. value: value,
  2181. isUnclosed: false,
  2182. quote: quote
  2183. };
  2184. },
  2185. /*
  2186. * Extract a regular expression out of the next sequence of
  2187. * characters and/or lines or return 'null' if its not possible.
  2188. *
  2189. * This method is platform dependent: it accepts almost any
  2190. * regular expression values but then tries to compile and run
  2191. * them using system's RegExp object. This means that there are
  2192. * rare edge cases where one JavaScript engine complains about
  2193. * your regular expression while others don't.
  2194. */
  2195. scanRegExp: function () {
  2196. var index = 0;
  2197. var length = this.input.length;
  2198. var char = this.peek();
  2199. var value = char;
  2200. var body = "";
  2201. var flags = [];
  2202. var malformed = false;
  2203. var isCharSet = false;
  2204. var terminated;
  2205. var scanUnexpectedChars = function () {
  2206. // Unexpected control character
  2207. if (char < " ") {
  2208. malformed = true;
  2209. this.trigger("warning", {
  2210. code: "W048",
  2211. line: this.line,
  2212. character: this.char
  2213. });
  2214. }
  2215. // Unexpected escaped character
  2216. if (char === "<") {
  2217. malformed = true;
  2218. this.trigger("warning", {
  2219. code: "W049",
  2220. line: this.line,
  2221. character: this.char,
  2222. data: [ char ]
  2223. });
  2224. }
  2225. }.bind(this);
  2226. // Regular expressions must start with '/'
  2227. if (!this.prereg || char !== "/") {
  2228. return null;
  2229. }
  2230. index += 1;
  2231. terminated = false;
  2232. // Try to get everything in between slashes. A couple of
  2233. // cases aside (see scanUnexpectedChars) we don't really
  2234. // care whether the resulting expression is valid or not.
  2235. // We will check that later using the RegExp object.
  2236. while (index < length) {
  2237. char = this.peek(index);
  2238. value += char;
  2239. body += char;
  2240. if (isCharSet) {
  2241. if (char === "]") {
  2242. if (this.peek(index - 1) !== "\\" || this.peek(index - 2) === "\\") {
  2243. isCharSet = false;
  2244. }
  2245. }
  2246. if (char === "\\") {
  2247. index += 1;
  2248. char = this.peek(index);
  2249. body += char;
  2250. value += char;
  2251. scanUnexpectedChars();
  2252. }
  2253. index += 1;
  2254. continue;
  2255. }
  2256. if (char === "\\") {
  2257. index += 1;
  2258. char = this.peek(index);
  2259. body += char;
  2260. value += char;
  2261. scanUnexpectedChars();
  2262. if (char === "/") {
  2263. index += 1;
  2264. continue;
  2265. }
  2266. if (char === "[") {
  2267. index += 1;
  2268. continue;
  2269. }
  2270. }
  2271. if (char === "[") {
  2272. isCharSet = true;
  2273. index += 1;
  2274. continue;
  2275. }
  2276. if (char === "/") {
  2277. body = body.substr(0, body.length - 1);
  2278. terminated = true;
  2279. index += 1;
  2280. break;
  2281. }
  2282. index += 1;
  2283. }
  2284. // A regular expression that was never closed is an
  2285. // error from which we cannot recover.
  2286. if (!terminated) {
  2287. this.trigger("error", {
  2288. code: "E015",
  2289. line: this.line,
  2290. character: this.from
  2291. });
  2292. return void this.trigger("fatal", {
  2293. line: this.line,
  2294. from: this.from
  2295. });
  2296. }
  2297. // Parse flags (if any).
  2298. while (index < length) {
  2299. char = this.peek(index);
  2300. if (!/[gim]/.test(char)) {
  2301. break;
  2302. }
  2303. flags.push(char);
  2304. value += char;
  2305. index += 1;
  2306. }
  2307. // Check regular expression for correctness.
  2308. try {
  2309. new RegExp(body, flags.join(""));
  2310. } catch (err) {
  2311. malformed = true;
  2312. this.trigger("error", {
  2313. code: "E016",
  2314. line: this.line,
  2315. character: this.char,
  2316. data: [ err.message ] // Platform dependent!
  2317. });
  2318. }
  2319. return {
  2320. type: Token.RegExp,
  2321. value: value,
  2322. flags: flags,
  2323. isMalformed: malformed
  2324. };
  2325. },
  2326. /*
  2327. * Scan for any occurence of mixed tabs and spaces. If smarttabs option
  2328. * is on, ignore tabs followed by spaces.
  2329. *
  2330. * Tabs followed by one space followed by a block comment are allowed.
  2331. */
  2332. scanMixedSpacesAndTabs: function () {
  2333. var at, match;
  2334. if (state.option.smarttabs) {
  2335. // Negative look-behind for "//"
  2336. match = this.input.match(/(\/\/|^\s?\*)? \t/);
  2337. at = match && !match[1] ? 0 : -1;
  2338. } else {
  2339. at = this.input.search(/ \t|\t [^\*]/);
  2340. }
  2341. return at;
  2342. },
  2343. /*
  2344. * Scan for characters that get silently deleted by one or more browsers.
  2345. */
  2346. scanUnsafeChars: function () {
  2347. return this.input.search(reg.unsafeChars);
  2348. },
  2349. /*
  2350. * Produce the next raw token or return 'null' if no tokens can be matched.
  2351. * This method skips over all space characters.
  2352. */
  2353. next: function (checks) {
  2354. this.from = this.char;
  2355. // Move to the next non-space character.
  2356. var start;
  2357. if (/\s/.test(this.peek())) {
  2358. start = this.char;
  2359. while (/\s/.test(this.peek())) {
  2360. this.from += 1;
  2361. this.skip();
  2362. }
  2363. if (this.peek() === "") { // EOL
  2364. if (!/^\s*$/.test(this.getLines()[this.line - 1]) && state.option.trailing) {
  2365. this.trigger("warning", { code: "W102", line: this.line, character: start });
  2366. }
  2367. }
  2368. }
  2369. // Methods that work with multi-line structures and move the
  2370. // character pointer.
  2371. var match = this.scanComments() ||
  2372. this.scanStringLiteral(checks);
  2373. if (match) {
  2374. return match;
  2375. }
  2376. // Methods that don't move the character pointer.
  2377. match =
  2378. this.scanRegExp() ||
  2379. this.scanPunctuator() ||
  2380. this.scanKeyword() ||
  2381. this.scanIdentifier() ||
  2382. this.scanNumericLiteral();
  2383. if (match) {
  2384. this.skip(match.value.length);
  2385. return match;
  2386. }
  2387. // No token could be matched, give up.
  2388. return null;
  2389. },
  2390. /*
  2391. * Switch to the next line and reset all char pointers. Once
  2392. * switched, this method also checks for mixed spaces and tabs
  2393. * and other minor warnings.
  2394. */
  2395. nextLine: function () {
  2396. var char;
  2397. if (this.line >= this.getLines().length) {
  2398. return false;
  2399. }
  2400. this.input = this.getLines()[this.line];
  2401. this.line += 1;
  2402. this.char = 1;
  2403. this.from = 1;
  2404. char = this.scanMixedSpacesAndTabs();
  2405. if (char >= 0) {
  2406. this.trigger("warning", { code: "W099", line: this.line, character: char + 1 });
  2407. }
  2408. this.input = this.input.replace(/\t/g, state.tab);
  2409. char = this.scanUnsafeChars();
  2410. if (char >= 0) {
  2411. this.trigger("warning", { code: "W100", line: this.line, character: char });
  2412. }
  2413. // If there is a limit on line length, warn when lines get too
  2414. // long.
  2415. if (state.option.maxlen && state.option.maxlen < this.input.length) {
  2416. this.trigger("warning", { code: "W101", line: this.line, character: this.input.length });
  2417. }
  2418. return true;
  2419. },
  2420. /*
  2421. * This is simply a synonym for nextLine() method with a friendlier
  2422. * public name.
  2423. */
  2424. start: function () {
  2425. this.nextLine();
  2426. },
  2427. /*
  2428. * Produce the next token. This function is called by advance() to get
  2429. * the next token. It retuns a token in a JSLint-compatible format.
  2430. */
  2431. token: function () {
  2432. /*jshint loopfunc:true */
  2433. var checks = asyncTrigger();
  2434. var token;
  2435. function isReserved(token, isProperty) {
  2436. if (!token.reserved) {
  2437. return false;
  2438. }
  2439. var meta = token.meta;
  2440. if (meta && meta.isFutureReservedWord && state.option.inES5()) {
  2441. // ES3 FutureReservedWord in an ES5 environment.
  2442. if (!meta.es5) {
  2443. return false;
  2444. }
  2445. // Some ES5 FutureReservedWord identifiers are active only
  2446. // within a strict mode environment.
  2447. if (meta.strictOnly) {
  2448. if (!state.option.strict && !state.directive["use strict"]) {
  2449. return false;
  2450. }
  2451. }
  2452. if (isProperty) {
  2453. return false;
  2454. }
  2455. }
  2456. return true;
  2457. }
  2458. // Produce a token object.
  2459. var create = function (type, value, isProperty) {
  2460. /*jshint validthis:true */
  2461. var obj;
  2462. if (type !== "(endline)" && type !== "(end)") {
  2463. this.prereg = false;
  2464. }
  2465. if (type === "(punctuator)") {
  2466. switch (value) {
  2467. case ".":
  2468. case ")":
  2469. case "~":
  2470. case "#":
  2471. case "]":
  2472. this.prereg = false;
  2473. break;
  2474. default:
  2475. this.prereg = true;
  2476. }
  2477. obj = Object.create(state.syntax[value] || state.syntax["(error)"]);
  2478. }
  2479. if (type === "(identifier)") {
  2480. if (value === "return" || value === "case" || value === "typeof") {
  2481. this.prereg = true;
  2482. }
  2483. if (_.has(state.syntax, value)) {
  2484. obj = Object.create(state.syntax[value] || state.syntax["(error)"]);
  2485. // If this can't be a reserved keyword, reset the object.
  2486. if (!isReserved(obj, isProperty && type === "(identifier)")) {
  2487. obj = null;
  2488. }
  2489. }
  2490. }
  2491. if (!obj) {
  2492. obj = Object.create(state.syntax[type]);
  2493. }
  2494. obj.identifier = (type === "(identifier)");
  2495. obj.type = obj.type || type;
  2496. obj.value = value;
  2497. obj.line = this.line;
  2498. obj.character = this.char;
  2499. obj.from = this.from;
  2500. if (isProperty && obj.identifier) {
  2501. obj.isProperty = isProperty;
  2502. }
  2503. obj.check = checks.check;
  2504. return obj;
  2505. }.bind(this);
  2506. for (;;) {
  2507. if (!this.input.length) {
  2508. return create(this.nextLine() ? "(endline)" : "(end)", "");
  2509. }
  2510. token = this.next(checks);
  2511. if (!token) {
  2512. if (this.input.length) {
  2513. // Unexpected character.
  2514. this.trigger("error", {
  2515. code: "E024",
  2516. line: this.line,
  2517. character: this.char,
  2518. data: [ this.peek() ]
  2519. });
  2520. this.input = "";
  2521. }
  2522. continue;
  2523. }
  2524. switch (token.type) {
  2525. case Token.StringLiteral:
  2526. this.triggerAsync("String", {
  2527. line: this.line,
  2528. char: this.char,
  2529. from: this.from,
  2530. value: token.value,
  2531. quote: token.quote
  2532. }, checks, function () { return true; });
  2533. return create("(string)", token.value);
  2534. case Token.Identifier:
  2535. this.trigger("Identifier", {
  2536. line: this.line,
  2537. char: this.char,
  2538. from: this.form,
  2539. name: token.value,
  2540. isProperty: state.tokens.curr.id === "."
  2541. });
  2542. /* falls through */
  2543. case Token.Keyword:
  2544. case Token.NullLiteral:
  2545. case Token.BooleanLiteral:
  2546. return create("(identifier)", token.value, state.tokens.curr.id === ".");
  2547. case Token.NumericLiteral:
  2548. if (token.isMalformed) {
  2549. this.trigger("warning", {
  2550. code: "W045",
  2551. line: this.line,
  2552. character: this.char,
  2553. data: [ token.value ]
  2554. });
  2555. }
  2556. this.triggerAsync("warning", {
  2557. code: "W114",
  2558. line: this.line,
  2559. character: this.char,
  2560. data: [ "0x-" ]
  2561. }, checks, function () { return token.base === 16 && state.jsonMode; });
  2562. this.triggerAsync("warning", {
  2563. code: "W115",
  2564. line: this.line,
  2565. character: this.char
  2566. }, checks, function () {
  2567. return state.directive["use strict"] && token.base === 8;
  2568. });
  2569. this.trigger("Number", {
  2570. line: this.line,
  2571. char: this.char,
  2572. from: this.from,
  2573. value: token.value,
  2574. base: token.base,
  2575. isMalformed: token.malformed
  2576. });
  2577. return create("(number)", token.value);
  2578. case Token.RegExp:
  2579. return create("(regexp)", token.value);
  2580. case Token.Comment:
  2581. state.tokens.curr.comment = true;
  2582. if (token.isSpecial) {
  2583. return {
  2584. value: token.value,
  2585. body: token.body,
  2586. type: token.commentType,
  2587. isSpecial: token.isSpecial,
  2588. line: this.line,
  2589. character: this.char,
  2590. from: this.from
  2591. };
  2592. }
  2593. break;
  2594. case "":
  2595. break;
  2596. default:
  2597. return create("(punctuator)", token.value);
  2598. }
  2599. }
  2600. }
  2601. };
  2602. exports.Lexer = Lexer;
  2603. })()
  2604. },{"events":2,"./reg.js":4,"./state.js":5,"underscore":8}],10:[function(require,module,exports){
  2605. (function(global){/*global window, global*/
  2606. var util = require("util")
  2607. var assert = require("assert")
  2608. var slice = Array.prototype.slice
  2609. var console
  2610. var times = {}
  2611. if (typeof global !== "undefined" && global.console) {
  2612. console = global.console
  2613. } else if (typeof window !== "undefined" && window.console) {
  2614. console = window.console
  2615. } else {
  2616. console = window.console = {}
  2617. }
  2618. var functions = [
  2619. [log, "log"]
  2620. , [info, "info"]
  2621. , [warn, "warn"]
  2622. , [error, "error"]
  2623. , [time, "time"]
  2624. , [timeEnd, "timeEnd"]
  2625. , [trace, "trace"]
  2626. , [dir, "dir"]
  2627. , [assert, "assert"]
  2628. ]
  2629. for (var i = 0; i < functions.length; i++) {
  2630. var tuple = functions[i]
  2631. var f = tuple[0]
  2632. var name = tuple[1]
  2633. if (!console[name]) {
  2634. console[name] = f
  2635. }
  2636. }
  2637. module.exports = console
  2638. function log() {}
  2639. function info() {
  2640. console.log.apply(console, arguments)
  2641. }
  2642. function warn() {
  2643. console.log.apply(console, arguments)
  2644. }
  2645. function error() {
  2646. console.warn.apply(console, arguments)
  2647. }
  2648. function time(label) {
  2649. times[label] = Date.now()
  2650. }
  2651. function timeEnd(label) {
  2652. var time = times[label]
  2653. if (!time) {
  2654. throw new Error("No such label: " + label)
  2655. }
  2656. var duration = Date.now() - time
  2657. console.log(label + ": " + duration + "ms")
  2658. }
  2659. function trace() {
  2660. var err = new Error()
  2661. err.name = "Trace"
  2662. err.message = util.format.apply(null, arguments)
  2663. console.error(err.stack)
  2664. }
  2665. function dir(object) {
  2666. console.log(util.inspect(object) + "\n")
  2667. }
  2668. function assert(expression) {
  2669. if (!expression) {
  2670. var arr = slice.call(arguments, 1)
  2671. assert.ok(false, util.format.apply(null, arr))
  2672. }
  2673. }
  2674. })(window)
  2675. },{"util":11,"assert":12}],"jshint":[function(require,module,exports){
  2676. module.exports=require('PeVhMp');
  2677. },{}],"PeVhMp":[function(require,module,exports){
  2678. (function(){/*!
  2679. * JSHint, by JSHint Community.
  2680. *
  2681. * This file (and this file only) is licensed under the same slightly modified
  2682. * MIT license that JSLint is. It stops evil-doers everywhere:
  2683. *
  2684. * Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
  2685. *
  2686. * Permission is hereby granted, free of charge, to any person obtaining
  2687. * a copy of this software and associated documentation files (the "Software"),
  2688. * to deal in the Software without restriction, including without limitation
  2689. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  2690. * and/or sell copies of the Software, and to permit persons to whom
  2691. * the Software is furnished to do so, subject to the following conditions:
  2692. *
  2693. * The above copyright notice and this permission notice shall be included
  2694. * in all copies or substantial portions of the Software.
  2695. *
  2696. * The Software shall be used for Good, not Evil.
  2697. *
  2698. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2699. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2700. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2701. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2702. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  2703. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  2704. * DEALINGS IN THE SOFTWARE.
  2705. *
  2706. */
  2707. /*jshint quotmark:double */
  2708. /*global console:true */
  2709. /*exported console */
  2710. var _ = require("underscore");
  2711. var events = require("events");
  2712. var vars = require("./vars.js");
  2713. var messages = require("./messages.js");
  2714. var Lexer = require("./lex.js").Lexer;
  2715. var reg = require("./reg.js");
  2716. var state = require("./state.js").state;
  2717. var style = require("./style.js");
  2718. // We need this module here because environments such as IE and Rhino
  2719. // don't necessarilly expose the 'console' API and browserify uses
  2720. // it to log things. It's a sad state of affair, really.
  2721. var console = require("console-browserify");
  2722. // We build the application inside a function so that we produce only a singleton
  2723. // variable. That function will be invoked immediately, and its return value is
  2724. // the JSHINT function itself.
  2725. var JSHINT = (function () {
  2726. "use strict";
  2727. var anonname, // The guessed name for anonymous functions.
  2728. api, // Extension API
  2729. // These are operators that should not be used with the ! operator.
  2730. bang = {
  2731. "<" : true,
  2732. "<=" : true,
  2733. "==" : true,
  2734. "===": true,
  2735. "!==": true,
  2736. "!=" : true,
  2737. ">" : true,
  2738. ">=" : true,
  2739. "+" : true,
  2740. "-" : true,
  2741. "*" : true,
  2742. "/" : true,
  2743. "%" : true
  2744. },
  2745. // These are the JSHint boolean options.
  2746. boolOptions = {
  2747. asi : true, // if automatic semicolon insertion should be tolerated
  2748. bitwise : true, // if bitwise operators should not be allowed
  2749. boss : true, // if advanced usage of assignments should be allowed
  2750. browser : true, // if the standard browser globals should be predefined
  2751. camelcase : true, // if identifiers should be required in camel case
  2752. couch : true, // if CouchDB globals should be predefined
  2753. curly : true, // if curly braces around all blocks should be required
  2754. debug : true, // if debugger statements should be allowed
  2755. devel : true, // if logging globals should be predefined (console, alert, etc.)
  2756. dojo : true, // if Dojo Toolkit globals should be predefined
  2757. eqeqeq : true, // if === should be required
  2758. eqnull : true, // if == null comparisons should be tolerated
  2759. es3 : true, // if ES3 syntax should be allowed
  2760. es5 : true, // if ES5 syntax should be allowed (is now set per default)
  2761. esnext : true, // if es.next specific syntax should be allowed
  2762. moz : true, // if mozilla specific syntax should be allowed
  2763. evil : true, // if eval should be allowed
  2764. expr : true, // if ExpressionStatement should be allowed as Programs
  2765. forin : true, // if for in statements must filter
  2766. funcscope : true, // if only function scope should be used for scope tests
  2767. gcl : true, // if JSHint should be compatible with Google Closure Linter
  2768. globalstrict: true, // if global "use strict"; should be allowed (also enables 'strict')
  2769. immed : true, // if immediate invocations must be wrapped in parens
  2770. iterator : true, // if the `__iterator__` property should be allowed
  2771. jquery : true, // if jQuery globals should be predefined
  2772. lastsemic : true, // if semicolons may be ommitted for the trailing
  2773. // statements inside of a one-line blocks.
  2774. laxbreak : true, // if line breaks should not be checked
  2775. laxcomma : true, // if line breaks should not be checked around commas
  2776. loopfunc : true, // if functions should be allowed to be defined within
  2777. // loops
  2778. mootools : true, // if MooTools globals should be predefined
  2779. multistr : true, // allow multiline strings
  2780. newcap : true, // if constructor names must be capitalized
  2781. noarg : true, // if arguments.caller and arguments.callee should be
  2782. // disallowed
  2783. node : true, // if the Node.js environment globals should be
  2784. // predefined
  2785. noempty : true, // if empty blocks should be disallowed
  2786. nonew : true, // if using `new` for side-effects should be disallowed
  2787. nonstandard : true, // if non-standard (but widely adopted) globals should
  2788. // be predefined
  2789. nomen : true, // if names should be checked
  2790. onevar : true, // if only one var statement per function should be
  2791. // allowed
  2792. passfail : true, // if the scan should stop on first error
  2793. phantom : true, // if PhantomJS symbols should be allowed
  2794. plusplus : true, // if increment/decrement should not be allowed
  2795. proto : true, // if the `__proto__` property should be allowed
  2796. prototypejs : true, // if Prototype and Scriptaculous globals should be
  2797. // predefined
  2798. rhino : true, // if the Rhino environment globals should be predefined
  2799. shelljs : true, // if ShellJS globals should be predefined
  2800. typed : true, // if typed array globals should be predefined
  2801. undef : true, // if variables should be declared before used
  2802. scripturl : true, // if script-targeted URLs should be tolerated
  2803. shadow : true, // if variable shadowing should be tolerated
  2804. smarttabs : true, // if smarttabs should be tolerated
  2805. // (http://www.emacswiki.org/emacs/SmartTabs)
  2806. strict : true, // require the "use strict"; pragma
  2807. sub : true, // if all forms of subscript notation are tolerated
  2808. supernew : true, // if `new function () { ... };` and `new Object;`
  2809. // should be tolerated
  2810. trailing : true, // if trailing whitespace rules apply
  2811. validthis : true, // if 'this' inside a non-constructor function is valid.
  2812. // This is a function scoped option only.
  2813. withstmt : true, // if with statements should be allowed
  2814. white : true, // if strict whitespace rules apply
  2815. worker : true, // if Web Worker script symbols should be allowed
  2816. wsh : true, // if the Windows Scripting Host environment globals
  2817. // should be predefined
  2818. yui : true, // YUI variables should be predefined
  2819. // Obsolete options
  2820. onecase : true, // if one case switch statements should be allowed
  2821. regexp : true, // if the . should not be allowed in regexp literals
  2822. regexdash : true // if unescaped first/last dash (-) inside brackets
  2823. // should be tolerated
  2824. },
  2825. // These are the JSHint options that can take any value
  2826. // (we use this object to detect invalid options)
  2827. valOptions = {
  2828. maxlen : false,
  2829. indent : false,
  2830. maxerr : false,
  2831. predef : false,
  2832. quotmark : false, //'single'|'double'|true
  2833. scope : false,
  2834. maxstatements: false, // {int} max statements per function
  2835. maxdepth : false, // {int} max nested block depth per function
  2836. maxparams : false, // {int} max params per function
  2837. maxcomplexity: false, // {int} max cyclomatic complexity per function
  2838. unused : true, // warn if variables are unused. Available options:
  2839. // false - don't check for unused variables
  2840. // true - "vars" + check last function param
  2841. // "vars" - skip checking unused function params
  2842. // "strict" - "vars" + check all function params
  2843. latedef : false // warn if the variable is used before its definition
  2844. // false - don't emit any warnings
  2845. // true - warn if any variable is used before its definition
  2846. // "nofunc" - warn for any variable but function declarations
  2847. },
  2848. // These are JSHint boolean options which are shared with JSLint
  2849. // where the definition in JSHint is opposite JSLint
  2850. invertedOptions = {
  2851. bitwise : true,
  2852. forin : true,
  2853. newcap : true,
  2854. nomen : true,
  2855. plusplus: true,
  2856. regexp : true,
  2857. undef : true,
  2858. white : true,
  2859. // Inverted and renamed, use JSHint name here
  2860. eqeqeq : true,
  2861. onevar : true,
  2862. strict : true
  2863. },
  2864. // These are JSHint boolean options which are shared with JSLint
  2865. // where the name has been changed but the effect is unchanged
  2866. renamedOptions = {
  2867. eqeq : "eqeqeq",
  2868. vars : "onevar",
  2869. windows: "wsh",
  2870. sloppy : "strict"
  2871. },
  2872. declared, // Globals that were declared using /*global ... */ syntax.
  2873. exported, // Variables that are used outside of the current file.
  2874. functionicity = [
  2875. "closure", "exception", "global", "label",
  2876. "outer", "unused", "var"
  2877. ],
  2878. funct, // The current function
  2879. functions, // All of the functions
  2880. global, // The global scope
  2881. implied, // Implied globals
  2882. inblock,
  2883. indent,
  2884. lookahead,
  2885. lex,
  2886. member,
  2887. membersOnly,
  2888. noreach,
  2889. predefined, // Global variables defined by option
  2890. scope, // The current scope
  2891. stack,
  2892. unuseds,
  2893. urls,
  2894. warnings,
  2895. extraModules = [],
  2896. emitter = new events.EventEmitter();
  2897. function checkOption(name, t) {
  2898. name = name.trim();
  2899. if (/^[+-]W\d{3}$/g.test(name)) {
  2900. return true;
  2901. }
  2902. if (valOptions[name] === undefined && boolOptions[name] === undefined) {
  2903. if (t.type !== "jslint") {
  2904. error("E001", t, name);
  2905. return false;
  2906. }
  2907. }
  2908. return true;
  2909. }
  2910. function isString(obj) {
  2911. return Object.prototype.toString.call(obj) === "[object String]";
  2912. }
  2913. function isIdentifier(tkn, value) {
  2914. if (!tkn)
  2915. return false;
  2916. if (!tkn.identifier || tkn.value !== value)
  2917. return false;
  2918. return true;
  2919. }
  2920. function isReserved(token) {
  2921. if (!token.reserved) {
  2922. return false;
  2923. }
  2924. var meta = token.meta;
  2925. if (meta && meta.isFutureReservedWord && state.option.inES5()) {
  2926. // ES3 FutureReservedWord in an ES5 environment.
  2927. if (!meta.es5) {
  2928. return false;
  2929. }
  2930. // Some ES5 FutureReservedWord identifiers are active only
  2931. // within a strict mode environment.
  2932. if (meta.strictOnly) {
  2933. if (!state.option.strict && !state.directive["use strict"]) {
  2934. return false;
  2935. }
  2936. }
  2937. if (token.isProperty) {
  2938. return false;
  2939. }
  2940. }
  2941. return true;
  2942. }
  2943. function supplant(str, data) {
  2944. return str.replace(/\{([^{}]*)\}/g, function (a, b) {
  2945. var r = data[b];
  2946. return typeof r === "string" || typeof r === "number" ? r : a;
  2947. });
  2948. }
  2949. function combine(t, o) {
  2950. var n;
  2951. for (n in o) {
  2952. if (_.has(o, n) && !_.has(JSHINT.blacklist, n)) {
  2953. t[n] = o[n];
  2954. }
  2955. }
  2956. }
  2957. function updatePredefined() {
  2958. Object.keys(JSHINT.blacklist).forEach(function (key) {
  2959. delete predefined[key];
  2960. });
  2961. }
  2962. function assume() {
  2963. if (state.option.es5) {
  2964. warning("I003");
  2965. }
  2966. if (state.option.couch) {
  2967. combine(predefined, vars.couch);
  2968. }
  2969. if (state.option.rhino) {
  2970. combine(predefined, vars.rhino);
  2971. }
  2972. if (state.option.shelljs) {
  2973. combine(predefined, vars.shelljs);
  2974. combine(predefined, vars.node);
  2975. }
  2976. if (state.option.typed) {
  2977. combine(predefined, vars.typed);
  2978. }
  2979. if (state.option.phantom) {
  2980. combine(predefined, vars.phantom);
  2981. }
  2982. if (state.option.prototypejs) {
  2983. combine(predefined, vars.prototypejs);
  2984. }
  2985. if (state.option.node) {
  2986. combine(predefined, vars.node);
  2987. combine(predefined, vars.typed);
  2988. }
  2989. if (state.option.devel) {
  2990. combine(predefined, vars.devel);
  2991. }
  2992. if (state.option.dojo) {
  2993. combine(predefined, vars.dojo);
  2994. }
  2995. if (state.option.browser) {
  2996. combine(predefined, vars.browser);
  2997. combine(predefined, vars.typed);
  2998. }
  2999. if (state.option.nonstandard) {
  3000. combine(predefined, vars.nonstandard);
  3001. }
  3002. if (state.option.jquery) {
  3003. combine(predefined, vars.jquery);
  3004. }
  3005. if (state.option.mootools) {
  3006. combine(predefined, vars.mootools);
  3007. }
  3008. if (state.option.worker) {
  3009. combine(predefined, vars.worker);
  3010. }
  3011. if (state.option.wsh) {
  3012. combine(predefined, vars.wsh);
  3013. }
  3014. if (state.option.globalstrict && state.option.strict !== false) {
  3015. state.option.strict = true;
  3016. }
  3017. if (state.option.yui) {
  3018. combine(predefined, vars.yui);
  3019. }
  3020. // Let's assume that chronologically ES3 < ES5 < ES6/ESNext < Moz
  3021. state.option.inMoz = function (strict) {
  3022. if (strict) {
  3023. return state.option.moz && !state.option.esnext;
  3024. }
  3025. return state.option.moz;
  3026. };
  3027. state.option.inESNext = function (strict) {
  3028. if (strict) {
  3029. return !state.option.moz && state.option.esnext;
  3030. }
  3031. return state.option.moz || state.option.esnext;
  3032. };
  3033. state.option.inES5 = function (/* strict */) {
  3034. return !state.option.es3;
  3035. };
  3036. state.option.inES3 = function (strict) {
  3037. if (strict) {
  3038. return !state.option.moz && !state.option.esnext && state.option.es3;
  3039. }
  3040. return state.option.es3;
  3041. };
  3042. }
  3043. // Produce an error warning.
  3044. function quit(code, line, chr) {
  3045. var percentage = Math.floor((line / state.lines.length) * 100);
  3046. var message = messages.errors[code].desc;
  3047. throw {
  3048. name: "JSHintError",
  3049. line: line,
  3050. character: chr,
  3051. message: message + " (" + percentage + "% scanned).",
  3052. raw: message,
  3053. code: code
  3054. };
  3055. }
  3056. function isundef(scope, code, token, a) {
  3057. return JSHINT.undefs.push([scope, code, token, a]);
  3058. }
  3059. function warning(code, t, a, b, c, d) {
  3060. var ch, l, w, msg;
  3061. if (/^W\d{3}$/.test(code)) {
  3062. if (state.ignored[code])
  3063. return;
  3064. msg = messages.warnings[code];
  3065. } else if (/E\d{3}/.test(code)) {
  3066. msg = messages.errors[code];
  3067. } else if (/I\d{3}/.test(code)) {
  3068. msg = messages.info[code];
  3069. }
  3070. t = t || state.tokens.next;
  3071. if (t.id === "(end)") { // `~
  3072. t = state.tokens.curr;
  3073. }
  3074. l = t.line || 0;
  3075. ch = t.from || 0;
  3076. w = {
  3077. id: "(error)",
  3078. raw: msg.desc,
  3079. code: msg.code,
  3080. evidence: state.lines[l - 1] || "",
  3081. line: l,
  3082. character: ch,
  3083. scope: JSHINT.scope,
  3084. a: a,
  3085. b: b,
  3086. c: c,
  3087. d: d
  3088. };
  3089. w.reason = supplant(msg.desc, w);
  3090. JSHINT.errors.push(w);
  3091. if (state.option.passfail) {
  3092. quit("E042", l, ch);
  3093. }
  3094. warnings += 1;
  3095. if (warnings >= state.option.maxerr) {
  3096. quit("E043", l, ch);
  3097. }
  3098. return w;
  3099. }
  3100. function warningAt(m, l, ch, a, b, c, d) {
  3101. return warning(m, {
  3102. line: l,
  3103. from: ch
  3104. }, a, b, c, d);
  3105. }
  3106. function error(m, t, a, b, c, d) {
  3107. warning(m, t, a, b, c, d);
  3108. }
  3109. function errorAt(m, l, ch, a, b, c, d) {
  3110. return error(m, {
  3111. line: l,
  3112. from: ch
  3113. }, a, b, c, d);
  3114. }
  3115. // Tracking of "internal" scripts, like eval containing a static string
  3116. function addInternalSrc(elem, src) {
  3117. var i;
  3118. i = {
  3119. id: "(internal)",
  3120. elem: elem,
  3121. value: src
  3122. };
  3123. JSHINT.internals.push(i);
  3124. return i;
  3125. }
  3126. function addlabel(t, type, tkn, islet) {
  3127. // Define t in the current function in the current scope.
  3128. if (type === "exception") {
  3129. if (_.has(funct["(context)"], t)) {
  3130. if (funct[t] !== true && !state.option.node) {
  3131. warning("W002", state.tokens.next, t);
  3132. }
  3133. }
  3134. }
  3135. if (_.has(funct, t) && !funct["(global)"]) {
  3136. if (funct[t] === true) {
  3137. if (state.option.latedef) {
  3138. if ((state.option.latedef === true && _.contains([funct[t], type], "unction")) ||
  3139. !_.contains([funct[t], type], "unction")) {
  3140. warning("W003", state.tokens.next, t);
  3141. }
  3142. }
  3143. } else {
  3144. if (!state.option.shadow && type !== "exception" ||
  3145. (funct["(blockscope)"].getlabel(t))) {
  3146. warning("W004", state.tokens.next, t);
  3147. }
  3148. }
  3149. }
  3150. // a double definition of a let variable in same block throws a TypeError
  3151. if (funct["(blockscope)"] && funct["(blockscope)"].current.has(t)) {
  3152. error("E044", state.tokens.next, t);
  3153. }
  3154. // if the identifier is from a let, adds it only to the current blockscope
  3155. if (islet) {
  3156. funct["(blockscope)"].current.add(t, type, state.tokens.curr);
  3157. } else {
  3158. funct[t] = type;
  3159. if (tkn) {
  3160. funct["(tokens)"][t] = tkn;
  3161. }
  3162. if (funct["(global)"]) {
  3163. global[t] = funct;
  3164. if (_.has(implied, t)) {
  3165. if (state.option.latedef) {
  3166. if ((state.option.latedef === true && _.contains([funct[t], type], "unction")) ||
  3167. !_.contains([funct[t], type], "unction")) {
  3168. warning("W003", state.tokens.next, t);
  3169. }
  3170. }
  3171. delete implied[t];
  3172. }
  3173. } else {
  3174. scope[t] = funct;
  3175. }
  3176. }
  3177. }
  3178. function doOption() {
  3179. var nt = state.tokens.next;
  3180. var body = nt.body.split(",").map(function (s) { return s.trim(); });
  3181. var predef = {};
  3182. if (nt.type === "globals") {
  3183. body.forEach(function (g) {
  3184. g = g.split(":");
  3185. var key = (g[0] || "").trim();
  3186. var val = (g[1] || "").trim();
  3187. if (key.charAt(0) === "-") {
  3188. key = key.slice(1);
  3189. val = false;
  3190. JSHINT.blacklist[key] = key;
  3191. updatePredefined();
  3192. } else {
  3193. predef[key] = (val === "true");
  3194. }
  3195. });
  3196. combine(predefined, predef);
  3197. for (var key in predef) {
  3198. if (_.has(predef, key)) {
  3199. declared[key] = nt;
  3200. }
  3201. }
  3202. }
  3203. if (nt.type === "exported") {
  3204. body.forEach(function (e) {
  3205. exported[e] = true;
  3206. });
  3207. }
  3208. if (nt.type === "members") {
  3209. membersOnly = membersOnly || {};
  3210. body.forEach(function (m) {
  3211. var ch1 = m.charAt(0);
  3212. var ch2 = m.charAt(m.length - 1);
  3213. if (ch1 === ch2 && (ch1 === "\"" || ch1 === "'")) {
  3214. m = m
  3215. .substr(1, m.length - 2)
  3216. .replace("\\b", "\b")
  3217. .replace("\\t", "\t")
  3218. .replace("\\n", "\n")
  3219. .replace("\\v", "\v")
  3220. .replace("\\f", "\f")
  3221. .replace("\\r", "\r")
  3222. .replace("\\\\", "\\")
  3223. .replace("\\\"", "\"");
  3224. }
  3225. membersOnly[m] = false;
  3226. });
  3227. }
  3228. var numvals = [
  3229. "maxstatements",
  3230. "maxparams",
  3231. "maxdepth",
  3232. "maxcomplexity",
  3233. "maxerr",
  3234. "maxlen",
  3235. "indent"
  3236. ];
  3237. if (nt.type === "jshint" || nt.type === "jslint") {
  3238. body.forEach(function (g) {
  3239. g = g.split(":");
  3240. var key = (g[0] || "").trim();
  3241. var val = (g[1] || "").trim();
  3242. if (!checkOption(key, nt)) {
  3243. return;
  3244. }
  3245. if (numvals.indexOf(key) >= 0) {
  3246. // GH988 - numeric options can be disabled by setting them to `false`
  3247. if (val !== "false") {
  3248. val = +val;
  3249. if (typeof val !== "number" || !isFinite(val) || val <= 0 || Math.floor(val) !== val) {
  3250. error("E032", nt, g[1].trim());
  3251. return;
  3252. }
  3253. if (key === "indent") {
  3254. state.option["(explicitIndent)"] = true;
  3255. }
  3256. state.option[key] = val;
  3257. } else {
  3258. if (key === "indent") {
  3259. state.option["(explicitIndent)"] = false;
  3260. } else {
  3261. state.option[key] = false;
  3262. }
  3263. }
  3264. return;
  3265. }
  3266. if (key === "validthis") {
  3267. // `validthis` is valid only within a function scope.
  3268. if (funct["(global)"]) {
  3269. error("E009");
  3270. } else {
  3271. if (val === "true" || val === "false") {
  3272. state.option.validthis = (val === "true");
  3273. } else {
  3274. error("E002", nt);
  3275. }
  3276. }
  3277. return;
  3278. }
  3279. if (key === "quotmark") {
  3280. switch (val) {
  3281. case "true":
  3282. case "false":
  3283. state.option.quotmark = (val === "true");
  3284. break;
  3285. case "double":
  3286. case "single":
  3287. state.option.quotmark = val;
  3288. break;
  3289. default:
  3290. error("E002", nt);
  3291. }
  3292. return;
  3293. }
  3294. if (key === "unused") {
  3295. switch (val) {
  3296. case "true":
  3297. state.option.unused = true;
  3298. break;
  3299. case "false":
  3300. state.option.unused = false;
  3301. break;
  3302. case "vars":
  3303. case "strict":
  3304. state.option.unused = val;
  3305. break;
  3306. default:
  3307. error("E002", nt);
  3308. }
  3309. return;
  3310. }
  3311. if (key === "latedef") {
  3312. switch (val) {
  3313. case "true":
  3314. state.option.latedef = true;
  3315. break;
  3316. case "false":
  3317. state.option.latedef = false;
  3318. break;
  3319. case "nofunc":
  3320. state.option.latedef = "nofunc";
  3321. break;
  3322. default:
  3323. error("E002", nt);
  3324. }
  3325. return;
  3326. }
  3327. var match = /^([+-])(W\d{3})$/g.exec(key);
  3328. if (match) {
  3329. // ignore for -W..., unignore for +W...
  3330. state.ignored[match[2]] = (match[1] === "-");
  3331. return;
  3332. }
  3333. var tn;
  3334. if (val === "true" || val === "false") {
  3335. if (nt.type === "jslint") {
  3336. tn = renamedOptions[key] || key;
  3337. state.option[tn] = (val === "true");
  3338. if (invertedOptions[tn] !== undefined) {
  3339. state.option[tn] = !state.option[tn];
  3340. }
  3341. } else {
  3342. state.option[key] = (val === "true");
  3343. }
  3344. if (key === "newcap") {
  3345. state.option["(explicitNewcap)"] = true;
  3346. }
  3347. return;
  3348. }
  3349. error("E002", nt);
  3350. });
  3351. assume();
  3352. }
  3353. }
  3354. // We need a peek function. If it has an argument, it peeks that much farther
  3355. // ahead. It is used to distinguish
  3356. // for ( var i in ...
  3357. // from
  3358. // for ( var i = ...
  3359. function peek(p) {
  3360. var i = p || 0, j = 0, t;
  3361. while (j <= i) {
  3362. t = lookahead[j];
  3363. if (!t) {
  3364. t = lookahead[j] = lex.token();
  3365. }
  3366. j += 1;
  3367. }
  3368. return t;
  3369. }
  3370. // Produce the next token. It looks for programming errors.
  3371. function advance(id, t) {
  3372. switch (state.tokens.curr.id) {
  3373. case "(number)":
  3374. if (state.tokens.next.id === ".") {
  3375. warning("W005", state.tokens.curr);
  3376. }
  3377. break;
  3378. case "-":
  3379. if (state.tokens.next.id === "-" || state.tokens.next.id === "--") {
  3380. warning("W006");
  3381. }
  3382. break;
  3383. case "+":
  3384. if (state.tokens.next.id === "+" || state.tokens.next.id === "++") {
  3385. warning("W007");
  3386. }
  3387. break;
  3388. }
  3389. if (state.tokens.curr.type === "(string)" || state.tokens.curr.identifier) {
  3390. anonname = state.tokens.curr.value;
  3391. }
  3392. if (id && state.tokens.next.id !== id) {
  3393. if (t) {
  3394. if (state.tokens.next.id === "(end)") {
  3395. error("E019", t, t.id);
  3396. } else {
  3397. error("E020", state.tokens.next, id, t.id, t.line, state.tokens.next.value);
  3398. }
  3399. } else if (state.tokens.next.type !== "(identifier)" || state.tokens.next.value !== id) {
  3400. warning("W116", state.tokens.next, id, state.tokens.next.value);
  3401. }
  3402. }
  3403. state.tokens.prev = state.tokens.curr;
  3404. state.tokens.curr = state.tokens.next;
  3405. for (;;) {
  3406. state.tokens.next = lookahead.shift() || lex.token();
  3407. if (!state.tokens.next) { // No more tokens left, give up
  3408. quit("E041", state.tokens.curr.line);
  3409. }
  3410. if (state.tokens.next.id === "(end)" || state.tokens.next.id === "(error)") {
  3411. return;
  3412. }
  3413. if (state.tokens.next.check) {
  3414. state.tokens.next.check();
  3415. }
  3416. if (state.tokens.next.isSpecial) {
  3417. doOption();
  3418. } else {
  3419. if (state.tokens.next.id !== "(endline)") {
  3420. break;
  3421. }
  3422. }
  3423. }
  3424. }
  3425. function isInfix(token) {
  3426. return token.infix || (!token.identifier && !!token.led);
  3427. }
  3428. function isEndOfExpr() {
  3429. var curr = state.tokens.curr;
  3430. var next = state.tokens.next;
  3431. if (next.id === ";" || next.id === "}" || next.id === ":") {
  3432. return true;
  3433. }
  3434. if (isInfix(next) === isInfix(curr) || (curr.id === "yield" && state.option.inMoz(true))) {
  3435. return curr.line !== next.line;
  3436. }
  3437. return false;
  3438. }
  3439. // This is the heart of JSHINT, the Pratt parser. In addition to parsing, it
  3440. // is looking for ad hoc lint patterns. We add .fud to Pratt's model, which is
  3441. // like .nud except that it is only used on the first token of a statement.
  3442. // Having .fud makes it much easier to define statement-oriented languages like
  3443. // JavaScript. I retained Pratt's nomenclature.
  3444. // .nud Null denotation
  3445. // .fud First null denotation
  3446. // .led Left denotation
  3447. // lbp Left binding power
  3448. // rbp Right binding power
  3449. // They are elements of the parsing method called Top Down Operator Precedence.
  3450. function expression(rbp, initial) {
  3451. var left, isArray = false, isObject = false, isLetExpr = false;
  3452. // if current expression is a let expression
  3453. if (!initial && state.tokens.next.value === "let" && peek(0).value === "(") {
  3454. if (!state.option.inMoz(true)) {
  3455. warning("W118", state.tokens.next, "let expressions");
  3456. }
  3457. isLetExpr = true;
  3458. // create a new block scope we use only for the current expression
  3459. funct["(blockscope)"].stack();
  3460. advance("let");
  3461. advance("(");
  3462. state.syntax["let"].fud.call(state.syntax["let"].fud, false);
  3463. advance(")");
  3464. }
  3465. if (state.tokens.next.id === "(end)")
  3466. error("E006", state.tokens.curr);
  3467. advance();
  3468. if (initial) {
  3469. anonname = "anonymous";
  3470. funct["(verb)"] = state.tokens.curr.value;
  3471. }
  3472. if (initial === true && state.tokens.curr.fud) {
  3473. left = state.tokens.curr.fud();
  3474. } else {
  3475. if (state.tokens.curr.nud) {
  3476. left = state.tokens.curr.nud();
  3477. } else {
  3478. error("E030", state.tokens.curr, state.tokens.curr.id);
  3479. }
  3480. while (rbp < state.tokens.next.lbp && !isEndOfExpr()) {
  3481. isArray = state.tokens.curr.value === "Array";
  3482. isObject = state.tokens.curr.value === "Object";
  3483. // #527, new Foo.Array(), Foo.Array(), new Foo.Object(), Foo.Object()
  3484. // Line breaks in IfStatement heads exist to satisfy the checkJSHint
  3485. // "Line too long." error.
  3486. if (left && (left.value || (left.first && left.first.value))) {
  3487. // If the left.value is not "new", or the left.first.value is a "."
  3488. // then safely assume that this is not "new Array()" and possibly
  3489. // not "new Object()"...
  3490. if (left.value !== "new" ||
  3491. (left.first && left.first.value && left.first.value === ".")) {
  3492. isArray = false;
  3493. // ...In the case of Object, if the left.value and state.tokens.curr.value
  3494. // are not equal, then safely assume that this not "new Object()"
  3495. if (left.value !== state.tokens.curr.value) {
  3496. isObject = false;
  3497. }
  3498. }
  3499. }
  3500. advance();
  3501. if (isArray && state.tokens.curr.id === "(" && state.tokens.next.id === ")") {
  3502. warning("W009", state.tokens.curr);
  3503. }
  3504. if (isObject && state.tokens.curr.id === "(" && state.tokens.next.id === ")") {
  3505. warning("W010", state.tokens.curr);
  3506. }
  3507. if (left && state.tokens.curr.led) {
  3508. left = state.tokens.curr.led(left);
  3509. } else {
  3510. error("E033", state.tokens.curr, state.tokens.curr.id);
  3511. }
  3512. }
  3513. }
  3514. if (isLetExpr) {
  3515. funct["(blockscope)"].unstack();
  3516. }
  3517. return left;
  3518. }
  3519. // Functions for conformance of style.
  3520. function adjacent(left, right) {
  3521. left = left || state.tokens.curr;
  3522. right = right || state.tokens.next;
  3523. if (state.option.white) {
  3524. if (left.character !== right.from && left.line === right.line) {
  3525. left.from += (left.character - left.from);
  3526. warning("W011", left, left.value);
  3527. }
  3528. }
  3529. }
  3530. function nobreak(left, right) {
  3531. left = left || state.tokens.curr;
  3532. right = right || state.tokens.next;
  3533. if (state.option.white && (left.character !== right.from || left.line !== right.line)) {
  3534. warning("W012", right, right.value);
  3535. }
  3536. }
  3537. function nospace(left, right) {
  3538. left = left || state.tokens.curr;
  3539. right = right || state.tokens.next;
  3540. if (state.option.white && !left.comment) {
  3541. if (left.line === right.line) {
  3542. adjacent(left, right);
  3543. }
  3544. }
  3545. }
  3546. function nonadjacent(left, right) {
  3547. if (state.option.white) {
  3548. left = left || state.tokens.curr;
  3549. right = right || state.tokens.next;
  3550. if (left.value === ";" && right.value === ";") {
  3551. return;
  3552. }
  3553. if (left.line === right.line && left.character === right.from) {
  3554. left.from += (left.character - left.from);
  3555. warning("W013", left, left.value);
  3556. }
  3557. }
  3558. }
  3559. function nobreaknonadjacent(left, right) {
  3560. left = left || state.tokens.curr;
  3561. right = right || state.tokens.next;
  3562. if (!state.option.laxbreak && left.line !== right.line) {
  3563. warning("W014", right, right.value);
  3564. } else if (state.option.white) {
  3565. left = left || state.tokens.curr;
  3566. right = right || state.tokens.next;
  3567. if (left.character === right.from) {
  3568. left.from += (left.character - left.from);
  3569. warning("W013", left, left.value);
  3570. }
  3571. }
  3572. }
  3573. function indentation(bias) {
  3574. if (!state.option.white && !state.option["(explicitIndent)"]) {
  3575. return;
  3576. }
  3577. if (state.tokens.next.id === "(end)") {
  3578. return;
  3579. }
  3580. var i = indent + (bias || 0);
  3581. if (state.tokens.next.from !== i) {
  3582. warning("W015", state.tokens.next, state.tokens.next.value, i, state.tokens.next.from);
  3583. }
  3584. }
  3585. function nolinebreak(t) {
  3586. t = t || state.tokens.curr;
  3587. if (t.line !== state.tokens.next.line) {
  3588. warning("E022", t, t.value);
  3589. }
  3590. }
  3591. function nobreakcomma(left, right) {
  3592. if (left.line !== right.line) {
  3593. if (!state.option.laxcomma) {
  3594. if (comma.first) {
  3595. warning("I001");
  3596. comma.first = false;
  3597. }
  3598. warning("W014", left, right.value);
  3599. }
  3600. } else if (!left.comment && left.character !== right.from && state.option.white) {
  3601. left.from += (left.character - left.from);
  3602. warning("W011", left, left.value);
  3603. }
  3604. }
  3605. function comma(opts) {
  3606. opts = opts || {};
  3607. if (!opts.peek) {
  3608. nobreakcomma(state.tokens.curr, state.tokens.next);
  3609. advance(",");
  3610. } else {
  3611. nobreakcomma(state.tokens.prev, state.tokens.curr);
  3612. }
  3613. // TODO: This is a temporary solution to fight against false-positives in
  3614. // arrays and objects with trailing commas (see GH-363). The best solution
  3615. // would be to extract all whitespace rules out of parser.
  3616. if (state.tokens.next.value !== "]" && state.tokens.next.value !== "}") {
  3617. nonadjacent(state.tokens.curr, state.tokens.next);
  3618. }
  3619. if (state.tokens.next.identifier && !(opts.property && state.option.inES5())) {
  3620. // Keywords that cannot follow a comma operator.
  3621. switch (state.tokens.next.value) {
  3622. case "break":
  3623. case "case":
  3624. case "catch":
  3625. case "continue":
  3626. case "default":
  3627. case "do":
  3628. case "else":
  3629. case "finally":
  3630. case "for":
  3631. case "if":
  3632. case "in":
  3633. case "instanceof":
  3634. case "return":
  3635. case "switch":
  3636. case "throw":
  3637. case "try":
  3638. case "var":
  3639. case "let":
  3640. case "while":
  3641. case "with":
  3642. error("E024", state.tokens.next, state.tokens.next.value);
  3643. return false;
  3644. }
  3645. }
  3646. if (state.tokens.next.type === "(punctuator)") {
  3647. switch (state.tokens.next.value) {
  3648. case "}":
  3649. case "]":
  3650. case ",":
  3651. if (opts.allowTrailing) {
  3652. return true;
  3653. }
  3654. /* falls through */
  3655. case ")":
  3656. error("E024", state.tokens.next, state.tokens.next.value);
  3657. return false;
  3658. }
  3659. }
  3660. return true;
  3661. }
  3662. // Functional constructors for making the symbols that will be inherited by
  3663. // tokens.
  3664. function symbol(s, p) {
  3665. var x = state.syntax[s];
  3666. if (!x || typeof x !== "object") {
  3667. state.syntax[s] = x = {
  3668. id: s,
  3669. lbp: p,
  3670. value: s
  3671. };
  3672. }
  3673. return x;
  3674. }
  3675. function delim(s) {
  3676. return symbol(s, 0);
  3677. }
  3678. function stmt(s, f) {
  3679. var x = delim(s);
  3680. x.identifier = x.reserved = true;
  3681. x.fud = f;
  3682. return x;
  3683. }
  3684. function blockstmt(s, f) {
  3685. var x = stmt(s, f);
  3686. x.block = true;
  3687. return x;
  3688. }
  3689. function reserveName(x) {
  3690. var c = x.id.charAt(0);
  3691. if ((c >= "a" && c <= "z") || (c >= "A" && c <= "Z")) {
  3692. x.identifier = x.reserved = true;
  3693. }
  3694. return x;
  3695. }
  3696. function prefix(s, f) {
  3697. var x = symbol(s, 150);
  3698. reserveName(x);
  3699. x.nud = (typeof f === "function") ? f : function () {
  3700. this.right = expression(150);
  3701. this.arity = "unary";
  3702. if (this.id === "++" || this.id === "--") {
  3703. if (state.option.plusplus) {
  3704. warning("W016", this, this.id);
  3705. } else if ((!this.right.identifier || isReserved(this.right)) &&
  3706. this.right.id !== "." && this.right.id !== "[") {
  3707. warning("W017", this);
  3708. }
  3709. }
  3710. return this;
  3711. };
  3712. return x;
  3713. }
  3714. function type(s, f) {
  3715. var x = delim(s);
  3716. x.type = s;
  3717. x.nud = f;
  3718. return x;
  3719. }
  3720. function reserve(name, func) {
  3721. var x = type(name, func);
  3722. x.identifier = true;
  3723. x.reserved = true;
  3724. return x;
  3725. }
  3726. function FutureReservedWord(name, meta) {
  3727. var x = type(name, (meta && meta.nud) || function () {
  3728. return this;
  3729. });
  3730. meta = meta || {};
  3731. meta.isFutureReservedWord = true;
  3732. x.value = name;
  3733. x.identifier = true;
  3734. x.reserved = true;
  3735. x.meta = meta;
  3736. return x;
  3737. }
  3738. function reservevar(s, v) {
  3739. return reserve(s, function () {
  3740. if (typeof v === "function") {
  3741. v(this);
  3742. }
  3743. return this;
  3744. });
  3745. }
  3746. function infix(s, f, p, w) {
  3747. var x = symbol(s, p);
  3748. reserveName(x);
  3749. x.infix = true;
  3750. x.led = function (left) {
  3751. if (!w) {
  3752. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  3753. nonadjacent(state.tokens.curr, state.tokens.next);
  3754. }
  3755. if (s === "in" && left.id === "!") {
  3756. warning("W018", left, "!");
  3757. }
  3758. if (typeof f === "function") {
  3759. return f(left, this);
  3760. } else {
  3761. this.left = left;
  3762. this.right = expression(p);
  3763. return this;
  3764. }
  3765. };
  3766. return x;
  3767. }
  3768. function application(s) {
  3769. var x = symbol(s, 42);
  3770. x.led = function (left) {
  3771. if (!state.option.inESNext()) {
  3772. warning("W104", state.tokens.curr, "arrow function syntax (=>)");
  3773. }
  3774. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  3775. nonadjacent(state.tokens.curr, state.tokens.next);
  3776. this.left = left;
  3777. this.right = doFunction(undefined, undefined, false, left);
  3778. return this;
  3779. };
  3780. return x;
  3781. }
  3782. function relation(s, f) {
  3783. var x = symbol(s, 100);
  3784. x.led = function (left) {
  3785. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  3786. nonadjacent(state.tokens.curr, state.tokens.next);
  3787. var right = expression(100);
  3788. if (isIdentifier(left, "NaN") || isIdentifier(right, "NaN")) {
  3789. warning("W019", this);
  3790. } else if (f) {
  3791. f.apply(this, [left, right]);
  3792. }
  3793. if (!left || !right) {
  3794. quit("E041", state.tokens.curr.line);
  3795. }
  3796. if (left.id === "!") {
  3797. warning("W018", left, "!");
  3798. }
  3799. if (right.id === "!") {
  3800. warning("W018", right, "!");
  3801. }
  3802. this.left = left;
  3803. this.right = right;
  3804. return this;
  3805. };
  3806. return x;
  3807. }
  3808. function isPoorRelation(node) {
  3809. return node &&
  3810. ((node.type === "(number)" && +node.value === 0) ||
  3811. (node.type === "(string)" && node.value === "") ||
  3812. (node.type === "null" && !state.option.eqnull) ||
  3813. node.type === "true" ||
  3814. node.type === "false" ||
  3815. node.type === "undefined");
  3816. }
  3817. function assignop(s, f, p) {
  3818. var x = infix(s, typeof f === "function" ? f : function (left, that) {
  3819. that.left = left;
  3820. if (left) {
  3821. if (predefined[left.value] === false &&
  3822. scope[left.value]["(global)"] === true) {
  3823. warning("W020", left);
  3824. } else if (left["function"]) {
  3825. warning("W021", left, left.value);
  3826. }
  3827. if (funct[left.value] === "const") {
  3828. error("E013", left, left.value);
  3829. }
  3830. if (left.id === ".") {
  3831. if (!left.left) {
  3832. warning("E031", that);
  3833. } else if (left.left.value === "arguments" && !state.directive["use strict"]) {
  3834. warning("E031", that);
  3835. }
  3836. that.right = expression(10);
  3837. return that;
  3838. } else if (left.id === "[") {
  3839. if (state.tokens.curr.left.first) {
  3840. state.tokens.curr.left.first.forEach(function (t) {
  3841. if (funct[t.value] === "const") {
  3842. error("E013", t, t.value);
  3843. }
  3844. });
  3845. } else if (!left.left) {
  3846. warning("E031", that);
  3847. } else if (left.left.value === "arguments" && !state.directive["use strict"]) {
  3848. warning("E031", that);
  3849. }
  3850. that.right = expression(10);
  3851. return that;
  3852. } else if (left.identifier && !isReserved(left)) {
  3853. if (funct[left.value] === "exception") {
  3854. warning("W022", left);
  3855. }
  3856. that.right = expression(10);
  3857. return that;
  3858. }
  3859. if (left === state.syntax["function"]) {
  3860. warning("W023", state.tokens.curr);
  3861. }
  3862. }
  3863. error("E031", that);
  3864. }, p);
  3865. x.exps = true;
  3866. x.assign = true;
  3867. return x;
  3868. }
  3869. function bitwise(s, f, p) {
  3870. var x = symbol(s, p);
  3871. reserveName(x);
  3872. x.led = (typeof f === "function") ? f : function (left) {
  3873. if (state.option.bitwise) {
  3874. warning("W016", this, this.id);
  3875. }
  3876. this.left = left;
  3877. this.right = expression(p);
  3878. return this;
  3879. };
  3880. return x;
  3881. }
  3882. function bitwiseassignop(s) {
  3883. return assignop(s, function (left, that) {
  3884. if (state.option.bitwise) {
  3885. warning("W016", that, that.id);
  3886. }
  3887. nonadjacent(state.tokens.prev, state.tokens.curr);
  3888. nonadjacent(state.tokens.curr, state.tokens.next);
  3889. if (left) {
  3890. if (left.id === "." || left.id === "[" ||
  3891. (left.identifier && !isReserved(left))) {
  3892. expression(10);
  3893. return that;
  3894. }
  3895. if (left === state.syntax["function"]) {
  3896. warning("W023", state.tokens.curr);
  3897. }
  3898. return that;
  3899. }
  3900. error("E031", that);
  3901. }, 20);
  3902. }
  3903. function suffix(s) {
  3904. var x = symbol(s, 150);
  3905. x.led = function (left) {
  3906. if (state.option.plusplus) {
  3907. warning("W016", this, this.id);
  3908. } else if ((!left.identifier || isReserved(left)) && left.id !== "." && left.id !== "[") {
  3909. warning("W017", this);
  3910. }
  3911. this.left = left;
  3912. return this;
  3913. };
  3914. return x;
  3915. }
  3916. // fnparam means that this identifier is being defined as a function
  3917. // argument (see identifier())
  3918. // prop means that this identifier is that of an object property
  3919. function optionalidentifier(fnparam, prop) {
  3920. if (!state.tokens.next.identifier) {
  3921. return;
  3922. }
  3923. advance();
  3924. var curr = state.tokens.curr;
  3925. var val = state.tokens.curr.value;
  3926. if (!isReserved(curr)) {
  3927. return val;
  3928. }
  3929. if (prop) {
  3930. if (state.option.inES5()) {
  3931. return val;
  3932. }
  3933. }
  3934. if (fnparam && val === "undefined") {
  3935. return val;
  3936. }
  3937. // Display an info message about reserved words as properties
  3938. // and ES5 but do it only once.
  3939. if (prop && !api.getCache("displayed:I002")) {
  3940. api.setCache("displayed:I002", true);
  3941. warning("I002");
  3942. }
  3943. warning("W024", state.tokens.curr, state.tokens.curr.id);
  3944. return val;
  3945. }
  3946. // fnparam means that this identifier is being defined as a function
  3947. // argument
  3948. // prop means that this identifier is that of an object property
  3949. function identifier(fnparam, prop) {
  3950. var i = optionalidentifier(fnparam, prop);
  3951. if (i) {
  3952. return i;
  3953. }
  3954. if (state.tokens.curr.id === "function" && state.tokens.next.id === "(") {
  3955. warning("W025");
  3956. } else {
  3957. error("E030", state.tokens.next, state.tokens.next.value);
  3958. }
  3959. }
  3960. function reachable(s) {
  3961. var i = 0, t;
  3962. if (state.tokens.next.id !== ";" || noreach) {
  3963. return;
  3964. }
  3965. for (;;) {
  3966. t = peek(i);
  3967. if (t.reach) {
  3968. return;
  3969. }
  3970. if (t.id !== "(endline)") {
  3971. if (t.id === "function") {
  3972. if (!state.option.latedef) {
  3973. break;
  3974. }
  3975. warning("W026", t);
  3976. break;
  3977. }
  3978. warning("W027", t, t.value, s);
  3979. break;
  3980. }
  3981. i += 1;
  3982. }
  3983. }
  3984. function statement(noindent) {
  3985. var values;
  3986. var i = indent, r, s = scope, t = state.tokens.next;
  3987. if (t.id === ";") {
  3988. advance(";");
  3989. return;
  3990. }
  3991. // Is this a labelled statement?
  3992. var res = isReserved(t);
  3993. // We're being more tolerant here: if someone uses
  3994. // a FutureReservedWord as a label, we warn but proceed
  3995. // anyway.
  3996. if (res && t.meta && t.meta.isFutureReservedWord && peek().id === ":") {
  3997. warning("W024", t, t.id);
  3998. res = false;
  3999. }
  4000. // detect a destructuring assignment
  4001. if (_.has(["[", "{"], t.value)) {
  4002. if (lookupBlockType().isDestAssign) {
  4003. if (!state.option.inESNext()) {
  4004. warning("W104", state.tokens.curr, "destructuring expression");
  4005. }
  4006. values = destructuringExpression();
  4007. values.forEach(function (tok) {
  4008. isundef(funct, "W117", tok.token, tok.id);
  4009. });
  4010. advance("=");
  4011. destructuringExpressionMatch(values, expression(10, true));
  4012. advance(";");
  4013. return;
  4014. }
  4015. }
  4016. if (t.identifier && !res && peek().id === ":") {
  4017. advance();
  4018. advance(":");
  4019. scope = Object.create(s);
  4020. addlabel(t.value, "label");
  4021. if (!state.tokens.next.labelled && state.tokens.next.value !== "{") {
  4022. warning("W028", state.tokens.next, t.value, state.tokens.next.value);
  4023. }
  4024. state.tokens.next.label = t.value;
  4025. t = state.tokens.next;
  4026. }
  4027. // Is it a lonely block?
  4028. if (t.id === "{") {
  4029. block(true, true);
  4030. return;
  4031. }
  4032. // Parse the statement.
  4033. if (!noindent) {
  4034. indentation();
  4035. }
  4036. r = expression(0, true);
  4037. // Look for the final semicolon.
  4038. if (!t.block) {
  4039. if (!state.option.expr && (!r || !r.exps)) {
  4040. warning("W030", state.tokens.curr);
  4041. } else if (state.option.nonew && r && r.left && r.id === "(" && r.left.id === "new") {
  4042. warning("W031", t);
  4043. }
  4044. if (state.tokens.next.id !== ";") {
  4045. if (!state.option.asi) {
  4046. // If this is the last statement in a block that ends on
  4047. // the same line *and* option lastsemic is on, ignore the warning.
  4048. // Otherwise, complain about missing semicolon.
  4049. if (!state.option.lastsemic || state.tokens.next.id !== "}" ||
  4050. state.tokens.next.line !== state.tokens.curr.line) {
  4051. warningAt("W033", state.tokens.curr.line, state.tokens.curr.character);
  4052. }
  4053. }
  4054. } else {
  4055. adjacent(state.tokens.curr, state.tokens.next);
  4056. advance(";");
  4057. nonadjacent(state.tokens.curr, state.tokens.next);
  4058. }
  4059. }
  4060. // Restore the indentation.
  4061. indent = i;
  4062. scope = s;
  4063. return r;
  4064. }
  4065. function statements(startLine) {
  4066. var a = [], p;
  4067. while (!state.tokens.next.reach && state.tokens.next.id !== "(end)") {
  4068. if (state.tokens.next.id === ";") {
  4069. p = peek();
  4070. if (!p || (p.id !== "(" && p.id !== "[")) {
  4071. warning("W032");
  4072. }
  4073. advance(";");
  4074. } else {
  4075. a.push(statement(startLine === state.tokens.next.line));
  4076. }
  4077. }
  4078. return a;
  4079. }
  4080. /*
  4081. * read all directives
  4082. * recognizes a simple form of asi, but always
  4083. * warns, if it is used
  4084. */
  4085. function directives() {
  4086. var i, p, pn;
  4087. for (;;) {
  4088. if (state.tokens.next.id === "(string)") {
  4089. p = peek(0);
  4090. if (p.id === "(endline)") {
  4091. i = 1;
  4092. do {
  4093. pn = peek(i);
  4094. i = i + 1;
  4095. } while (pn.id === "(endline)");
  4096. if (pn.id !== ";") {
  4097. if (pn.id !== "(string)" && pn.id !== "(number)" &&
  4098. pn.id !== "(regexp)" && pn.identifier !== true &&
  4099. pn.id !== "}") {
  4100. break;
  4101. }
  4102. warning("W033", state.tokens.next);
  4103. } else {
  4104. p = pn;
  4105. }
  4106. } else if (p.id === "}") {
  4107. // Directive with no other statements, warn about missing semicolon
  4108. warning("W033", p);
  4109. } else if (p.id !== ";") {
  4110. break;
  4111. }
  4112. indentation();
  4113. advance();
  4114. if (state.directive[state.tokens.curr.value]) {
  4115. warning("W034", state.tokens.curr, state.tokens.curr.value);
  4116. }
  4117. if (state.tokens.curr.value === "use strict") {
  4118. if (!state.option["(explicitNewcap)"])
  4119. state.option.newcap = true;
  4120. state.option.undef = true;
  4121. }
  4122. // there's no directive negation, so always set to true
  4123. state.directive[state.tokens.curr.value] = true;
  4124. if (p.id === ";") {
  4125. advance(";");
  4126. }
  4127. continue;
  4128. }
  4129. break;
  4130. }
  4131. }
  4132. /*
  4133. * Parses a single block. A block is a sequence of statements wrapped in
  4134. * braces.
  4135. *
  4136. * ordinary - true for everything but function bodies and try blocks.
  4137. * stmt - true if block can be a single statement (e.g. in if/for/while).
  4138. * isfunc - true if block is a function body
  4139. */
  4140. function block(ordinary, stmt, isfunc, isfatarrow) {
  4141. var a,
  4142. b = inblock,
  4143. old_indent = indent,
  4144. m,
  4145. s = scope,
  4146. t,
  4147. line,
  4148. d;
  4149. inblock = ordinary;
  4150. if (!ordinary || !state.option.funcscope)
  4151. scope = Object.create(scope);
  4152. nonadjacent(state.tokens.curr, state.tokens.next);
  4153. t = state.tokens.next;
  4154. var metrics = funct["(metrics)"];
  4155. metrics.nestedBlockDepth += 1;
  4156. metrics.verifyMaxNestedBlockDepthPerFunction();
  4157. if (state.tokens.next.id === "{") {
  4158. advance("{");
  4159. // create a new block scope
  4160. funct["(blockscope)"].stack();
  4161. line = state.tokens.curr.line;
  4162. if (state.tokens.next.id !== "}") {
  4163. indent += state.option.indent;
  4164. while (!ordinary && state.tokens.next.from > indent) {
  4165. indent += state.option.indent;
  4166. }
  4167. if (isfunc) {
  4168. m = {};
  4169. for (d in state.directive) {
  4170. if (_.has(state.directive, d)) {
  4171. m[d] = state.directive[d];
  4172. }
  4173. }
  4174. directives();
  4175. if (state.option.strict && funct["(context)"]["(global)"]) {
  4176. if (!m["use strict"] && !state.directive["use strict"]) {
  4177. warning("E007");
  4178. }
  4179. }
  4180. }
  4181. a = statements(line);
  4182. metrics.statementCount += a.length;
  4183. if (isfunc) {
  4184. state.directive = m;
  4185. }
  4186. indent -= state.option.indent;
  4187. if (line !== state.tokens.next.line) {
  4188. indentation();
  4189. }
  4190. } else if (line !== state.tokens.next.line) {
  4191. indentation();
  4192. }
  4193. advance("}", t);
  4194. funct["(blockscope)"].unstack();
  4195. indent = old_indent;
  4196. } else if (!ordinary) {
  4197. if (isfunc) {
  4198. m = {};
  4199. if (stmt && !isfatarrow && !state.option.inMoz(true)) {
  4200. error("W118", state.tokens.curr, "function closure expressions");
  4201. }
  4202. if (!stmt) {
  4203. for (d in state.directive) {
  4204. if (_.has(state.directive, d)) {
  4205. m[d] = state.directive[d];
  4206. }
  4207. }
  4208. }
  4209. expression(10);
  4210. if (state.option.strict && funct["(context)"]["(global)"]) {
  4211. if (!m["use strict"] && !state.directive["use strict"]) {
  4212. warning("E007");
  4213. }
  4214. }
  4215. } else {
  4216. error("E021", state.tokens.next, "{", state.tokens.next.value);
  4217. }
  4218. } else {
  4219. // check to avoid let declaration not within a block
  4220. funct["(nolet)"] = true;
  4221. if (!stmt || state.option.curly) {
  4222. warning("W116", state.tokens.next, "{", state.tokens.next.value);
  4223. }
  4224. noreach = true;
  4225. indent += state.option.indent;
  4226. // test indentation only if statement is in new line
  4227. a = [statement(state.tokens.next.line === state.tokens.curr.line)];
  4228. indent -= state.option.indent;
  4229. noreach = false;
  4230. delete funct["(nolet)"];
  4231. }
  4232. funct["(verb)"] = null;
  4233. if (!ordinary || !state.option.funcscope) scope = s;
  4234. inblock = b;
  4235. if (ordinary && state.option.noempty && (!a || a.length === 0)) {
  4236. warning("W035");
  4237. }
  4238. metrics.nestedBlockDepth -= 1;
  4239. return a;
  4240. }
  4241. function countMember(m) {
  4242. if (membersOnly && typeof membersOnly[m] !== "boolean") {
  4243. warning("W036", state.tokens.curr, m);
  4244. }
  4245. if (typeof member[m] === "number") {
  4246. member[m] += 1;
  4247. } else {
  4248. member[m] = 1;
  4249. }
  4250. }
  4251. function note_implied(tkn) {
  4252. var name = tkn.value, line = tkn.line, a = implied[name];
  4253. if (typeof a === "function") {
  4254. a = false;
  4255. }
  4256. if (!a) {
  4257. a = [line];
  4258. implied[name] = a;
  4259. } else if (a[a.length - 1] !== line) {
  4260. a.push(line);
  4261. }
  4262. }
  4263. // Build the syntax table by declaring the syntactic elements of the language.
  4264. type("(number)", function () {
  4265. return this;
  4266. });
  4267. type("(string)", function () {
  4268. return this;
  4269. });
  4270. state.syntax["(identifier)"] = {
  4271. type: "(identifier)",
  4272. lbp: 0,
  4273. identifier: true,
  4274. nud: function () {
  4275. var v = this.value,
  4276. s = scope[v],
  4277. f;
  4278. if (typeof s === "function") {
  4279. // Protection against accidental inheritance.
  4280. s = undefined;
  4281. } else if (typeof s === "boolean") {
  4282. f = funct;
  4283. funct = functions[0];
  4284. addlabel(v, "var");
  4285. s = funct;
  4286. funct = f;
  4287. }
  4288. var block;
  4289. if (_.has(funct, "(blockscope)")) {
  4290. block = funct["(blockscope)"].getlabel(v);
  4291. }
  4292. // The name is in scope and defined in the current function.
  4293. if (funct === s || block) {
  4294. // Change 'unused' to 'var', and reject labels.
  4295. // the name is in a block scope
  4296. switch (block ? block[v]["(type)"] : funct[v]) {
  4297. case "unused":
  4298. if (block) block[v]["(type)"] = "var";
  4299. else funct[v] = "var";
  4300. break;
  4301. case "unction":
  4302. if (block) block[v]["(type)"] = "function";
  4303. else funct[v] = "function";
  4304. this["function"] = true;
  4305. break;
  4306. case "function":
  4307. this["function"] = true;
  4308. break;
  4309. case "label":
  4310. warning("W037", state.tokens.curr, v);
  4311. break;
  4312. }
  4313. } else if (funct["(global)"]) {
  4314. // The name is not defined in the function. If we are in the global
  4315. // scope, then we have an undefined variable.
  4316. //
  4317. // Operators typeof and delete do not raise runtime errors even if
  4318. // the base object of a reference is null so no need to display warning
  4319. // if we're inside of typeof or delete.
  4320. if (typeof predefined[v] !== "boolean") {
  4321. // Attempting to subscript a null reference will throw an
  4322. // error, even within the typeof and delete operators
  4323. if (!(anonname === "typeof" || anonname === "delete") ||
  4324. (state.tokens.next && (state.tokens.next.value === "." ||
  4325. state.tokens.next.value === "["))) {
  4326. // if we're in a list comprehension, variables are declared
  4327. // locally and used before being defined. So we check
  4328. // the presence of the given variable in the comp array
  4329. // before declaring it undefined.
  4330. if (!funct["(comparray)"].check(v)) {
  4331. isundef(funct, "W117", state.tokens.curr, v);
  4332. }
  4333. }
  4334. }
  4335. note_implied(state.tokens.curr);
  4336. } else {
  4337. // If the name is already defined in the current
  4338. // function, but not as outer, then there is a scope error.
  4339. switch (funct[v]) {
  4340. case "closure":
  4341. case "function":
  4342. case "var":
  4343. case "unused":
  4344. warning("W038", state.tokens.curr, v);
  4345. break;
  4346. case "label":
  4347. warning("W037", state.tokens.curr, v);
  4348. break;
  4349. case "outer":
  4350. case "global":
  4351. break;
  4352. default:
  4353. // If the name is defined in an outer function, make an outer entry,
  4354. // and if it was unused, make it var.
  4355. if (s === true) {
  4356. funct[v] = true;
  4357. } else if (s === null) {
  4358. warning("W039", state.tokens.curr, v);
  4359. note_implied(state.tokens.curr);
  4360. } else if (typeof s !== "object") {
  4361. // Operators typeof and delete do not raise runtime errors even
  4362. // if the base object of a reference is null so no need to
  4363. //
  4364. // display warning if we're inside of typeof or delete.
  4365. // Attempting to subscript a null reference will throw an
  4366. // error, even within the typeof and delete operators
  4367. if (!(anonname === "typeof" || anonname === "delete") ||
  4368. (state.tokens.next &&
  4369. (state.tokens.next.value === "." || state.tokens.next.value === "["))) {
  4370. isundef(funct, "W117", state.tokens.curr, v);
  4371. }
  4372. funct[v] = true;
  4373. note_implied(state.tokens.curr);
  4374. } else {
  4375. switch (s[v]) {
  4376. case "function":
  4377. case "unction":
  4378. this["function"] = true;
  4379. s[v] = "closure";
  4380. funct[v] = s["(global)"] ? "global" : "outer";
  4381. break;
  4382. case "var":
  4383. case "unused":
  4384. s[v] = "closure";
  4385. funct[v] = s["(global)"] ? "global" : "outer";
  4386. break;
  4387. case "closure":
  4388. funct[v] = s["(global)"] ? "global" : "outer";
  4389. break;
  4390. case "label":
  4391. warning("W037", state.tokens.curr, v);
  4392. }
  4393. }
  4394. }
  4395. }
  4396. return this;
  4397. },
  4398. led: function () {
  4399. error("E033", state.tokens.next, state.tokens.next.value);
  4400. }
  4401. };
  4402. type("(regexp)", function () {
  4403. return this;
  4404. });
  4405. // ECMAScript parser
  4406. delim("(endline)");
  4407. delim("(begin)");
  4408. delim("(end)").reach = true;
  4409. delim("(error)").reach = true;
  4410. delim("}").reach = true;
  4411. delim(")");
  4412. delim("]");
  4413. delim("\"").reach = true;
  4414. delim("'").reach = true;
  4415. delim(";");
  4416. delim(":").reach = true;
  4417. delim("#");
  4418. reserve("else");
  4419. reserve("case").reach = true;
  4420. reserve("catch");
  4421. reserve("default").reach = true;
  4422. reserve("finally");
  4423. reservevar("arguments", function (x) {
  4424. if (state.directive["use strict"] && funct["(global)"]) {
  4425. warning("E008", x);
  4426. }
  4427. });
  4428. reservevar("eval");
  4429. reservevar("false");
  4430. reservevar("Infinity");
  4431. reservevar("null");
  4432. reservevar("this", function (x) {
  4433. if (state.directive["use strict"] && !state.option.validthis && ((funct["(statement)"] &&
  4434. funct["(name)"].charAt(0) > "Z") || funct["(global)"])) {
  4435. warning("W040", x);
  4436. }
  4437. });
  4438. reservevar("true");
  4439. reservevar("undefined");
  4440. assignop("=", "assign", 20);
  4441. assignop("+=", "assignadd", 20);
  4442. assignop("-=", "assignsub", 20);
  4443. assignop("*=", "assignmult", 20);
  4444. assignop("/=", "assigndiv", 20).nud = function () {
  4445. error("E014");
  4446. };
  4447. assignop("%=", "assignmod", 20);
  4448. bitwiseassignop("&=", "assignbitand", 20);
  4449. bitwiseassignop("|=", "assignbitor", 20);
  4450. bitwiseassignop("^=", "assignbitxor", 20);
  4451. bitwiseassignop("<<=", "assignshiftleft", 20);
  4452. bitwiseassignop(">>=", "assignshiftright", 20);
  4453. bitwiseassignop(">>>=", "assignshiftrightunsigned", 20);
  4454. infix(",", function (left, that) {
  4455. var expr;
  4456. that.exprs = [left];
  4457. if (!comma({peek: true})) {
  4458. return that;
  4459. }
  4460. while (true) {
  4461. if (!(expr = expression(10))) {
  4462. break;
  4463. }
  4464. that.exprs.push(expr);
  4465. if (state.tokens.next.value !== "," || !comma()) {
  4466. break;
  4467. }
  4468. }
  4469. return that;
  4470. }, 10, true);
  4471. infix("?", function (left, that) {
  4472. increaseComplexityCount();
  4473. that.left = left;
  4474. that.right = expression(10);
  4475. advance(":");
  4476. that["else"] = expression(10);
  4477. return that;
  4478. }, 30);
  4479. var orPrecendence = 40;
  4480. infix("||", function (left, that) {
  4481. increaseComplexityCount();
  4482. that.left = left;
  4483. that.right = expression(orPrecendence);
  4484. return that;
  4485. }, orPrecendence);
  4486. infix("&&", "and", 50);
  4487. bitwise("|", "bitor", 70);
  4488. bitwise("^", "bitxor", 80);
  4489. bitwise("&", "bitand", 90);
  4490. relation("==", function (left, right) {
  4491. var eqnull = state.option.eqnull && (left.value === "null" || right.value === "null");
  4492. if (!eqnull && state.option.eqeqeq)
  4493. warning("W116", this, "===", "==");
  4494. else if (isPoorRelation(left))
  4495. warning("W041", this, "===", left.value);
  4496. else if (isPoorRelation(right))
  4497. warning("W041", this, "===", right.value);
  4498. return this;
  4499. });
  4500. relation("===");
  4501. relation("!=", function (left, right) {
  4502. var eqnull = state.option.eqnull &&
  4503. (left.value === "null" || right.value === "null");
  4504. if (!eqnull && state.option.eqeqeq) {
  4505. warning("W116", this, "!==", "!=");
  4506. } else if (isPoorRelation(left)) {
  4507. warning("W041", this, "!==", left.value);
  4508. } else if (isPoorRelation(right)) {
  4509. warning("W041", this, "!==", right.value);
  4510. }
  4511. return this;
  4512. });
  4513. relation("!==");
  4514. relation("<");
  4515. relation(">");
  4516. relation("<=");
  4517. relation(">=");
  4518. bitwise("<<", "shiftleft", 120);
  4519. bitwise(">>", "shiftright", 120);
  4520. bitwise(">>>", "shiftrightunsigned", 120);
  4521. infix("in", "in", 120);
  4522. infix("instanceof", "instanceof", 120);
  4523. infix("+", function (left, that) {
  4524. var right = expression(130);
  4525. if (left && right && left.id === "(string)" && right.id === "(string)") {
  4526. left.value += right.value;
  4527. left.character = right.character;
  4528. if (!state.option.scripturl && reg.javascriptURL.test(left.value)) {
  4529. warning("W050", left);
  4530. }
  4531. return left;
  4532. }
  4533. that.left = left;
  4534. that.right = right;
  4535. return that;
  4536. }, 130);
  4537. prefix("+", "num");
  4538. prefix("+++", function () {
  4539. warning("W007");
  4540. this.right = expression(150);
  4541. this.arity = "unary";
  4542. return this;
  4543. });
  4544. infix("+++", function (left) {
  4545. warning("W007");
  4546. this.left = left;
  4547. this.right = expression(130);
  4548. return this;
  4549. }, 130);
  4550. infix("-", "sub", 130);
  4551. prefix("-", "neg");
  4552. prefix("---", function () {
  4553. warning("W006");
  4554. this.right = expression(150);
  4555. this.arity = "unary";
  4556. return this;
  4557. });
  4558. infix("---", function (left) {
  4559. warning("W006");
  4560. this.left = left;
  4561. this.right = expression(130);
  4562. return this;
  4563. }, 130);
  4564. infix("*", "mult", 140);
  4565. infix("/", "div", 140);
  4566. infix("%", "mod", 140);
  4567. suffix("++", "postinc");
  4568. prefix("++", "preinc");
  4569. state.syntax["++"].exps = true;
  4570. suffix("--", "postdec");
  4571. prefix("--", "predec");
  4572. state.syntax["--"].exps = true;
  4573. prefix("delete", function () {
  4574. var p = expression(10);
  4575. if (!p || (p.id !== "." && p.id !== "[")) {
  4576. warning("W051");
  4577. }
  4578. this.first = p;
  4579. return this;
  4580. }).exps = true;
  4581. prefix("~", function () {
  4582. if (state.option.bitwise) {
  4583. warning("W052", this, "~");
  4584. }
  4585. expression(150);
  4586. return this;
  4587. });
  4588. prefix("...", function () {
  4589. if (!state.option.inESNext()) {
  4590. warning("W104", this, "spread/rest operator");
  4591. }
  4592. if (!state.tokens.next.identifier) {
  4593. error("E030", state.tokens.next, state.tokens.next.value);
  4594. }
  4595. expression(150);
  4596. return this;
  4597. });
  4598. prefix("!", function () {
  4599. this.right = expression(150);
  4600. this.arity = "unary";
  4601. if (!this.right) { // '!' followed by nothing? Give up.
  4602. quit("E041", this.line || 0);
  4603. }
  4604. if (bang[this.right.id] === true) {
  4605. warning("W018", this, "!");
  4606. }
  4607. return this;
  4608. });
  4609. prefix("typeof", "typeof");
  4610. prefix("new", function () {
  4611. var c = expression(155), i;
  4612. if (c && c.id !== "function") {
  4613. if (c.identifier) {
  4614. c["new"] = true;
  4615. switch (c.value) {
  4616. case "Number":
  4617. case "String":
  4618. case "Boolean":
  4619. case "Math":
  4620. case "JSON":
  4621. warning("W053", state.tokens.prev, c.value);
  4622. break;
  4623. case "Function":
  4624. if (!state.option.evil) {
  4625. warning("W054");
  4626. }
  4627. break;
  4628. case "Date":
  4629. case "RegExp":
  4630. break;
  4631. default:
  4632. if (c.id !== "function") {
  4633. i = c.value.substr(0, 1);
  4634. if (state.option.newcap && (i < "A" || i > "Z") && !_.has(global, c.value)) {
  4635. warning("W055", state.tokens.curr);
  4636. }
  4637. }
  4638. }
  4639. } else {
  4640. if (c.id !== "." && c.id !== "[" && c.id !== "(") {
  4641. warning("W056", state.tokens.curr);
  4642. }
  4643. }
  4644. } else {
  4645. if (!state.option.supernew)
  4646. warning("W057", this);
  4647. }
  4648. adjacent(state.tokens.curr, state.tokens.next);
  4649. if (state.tokens.next.id !== "(" && !state.option.supernew) {
  4650. warning("W058", state.tokens.curr, state.tokens.curr.value);
  4651. }
  4652. this.first = c;
  4653. return this;
  4654. });
  4655. state.syntax["new"].exps = true;
  4656. prefix("void").exps = true;
  4657. infix(".", function (left, that) {
  4658. adjacent(state.tokens.prev, state.tokens.curr);
  4659. nobreak();
  4660. var m = identifier(false, true);
  4661. if (typeof m === "string") {
  4662. countMember(m);
  4663. }
  4664. that.left = left;
  4665. that.right = m;
  4666. if (m && m === "hasOwnProperty" && state.tokens.next.value === "=") {
  4667. warning("W001");
  4668. }
  4669. if (left && left.value === "arguments" && (m === "callee" || m === "caller")) {
  4670. if (state.option.noarg)
  4671. warning("W059", left, m);
  4672. else if (state.directive["use strict"])
  4673. error("E008");
  4674. } else if (!state.option.evil && left && left.value === "document" &&
  4675. (m === "write" || m === "writeln")) {
  4676. warning("W060", left);
  4677. }
  4678. if (!state.option.evil && (m === "eval" || m === "execScript")) {
  4679. warning("W061");
  4680. }
  4681. return that;
  4682. }, 160, true);
  4683. infix("(", function (left, that) {
  4684. if (state.tokens.prev.id !== "}" && state.tokens.prev.id !== ")") {
  4685. nobreak(state.tokens.prev, state.tokens.curr);
  4686. }
  4687. nospace();
  4688. if (state.option.immed && left && !left.immed && left.id === "function") {
  4689. warning("W062");
  4690. }
  4691. var n = 0;
  4692. var p = [];
  4693. if (left) {
  4694. if (left.type === "(identifier)") {
  4695. if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) {
  4696. if ("Number String Boolean Date Object".indexOf(left.value) === -1) {
  4697. if (left.value === "Math") {
  4698. warning("W063", left);
  4699. } else if (state.option.newcap) {
  4700. warning("W064", left);
  4701. }
  4702. }
  4703. }
  4704. }
  4705. }
  4706. if (state.tokens.next.id !== ")") {
  4707. for (;;) {
  4708. p[p.length] = expression(10);
  4709. n += 1;
  4710. if (state.tokens.next.id !== ",") {
  4711. break;
  4712. }
  4713. comma();
  4714. }
  4715. }
  4716. advance(")");
  4717. nospace(state.tokens.prev, state.tokens.curr);
  4718. if (typeof left === "object") {
  4719. if (left.value === "parseInt" && n === 1) {
  4720. warning("W065", state.tokens.curr);
  4721. }
  4722. if (!state.option.evil) {
  4723. if (left.value === "eval" || left.value === "Function" ||
  4724. left.value === "execScript") {
  4725. warning("W061", left);
  4726. if (p[0] && [0].id === "(string)") {
  4727. addInternalSrc(left, p[0].value);
  4728. }
  4729. } else if (p[0] && p[0].id === "(string)" &&
  4730. (left.value === "setTimeout" ||
  4731. left.value === "setInterval")) {
  4732. warning("W066", left);
  4733. addInternalSrc(left, p[0].value);
  4734. // window.setTimeout/setInterval
  4735. } else if (p[0] && p[0].id === "(string)" &&
  4736. left.value === "." &&
  4737. left.left.value === "window" &&
  4738. (left.right === "setTimeout" ||
  4739. left.right === "setInterval")) {
  4740. warning("W066", left);
  4741. addInternalSrc(left, p[0].value);
  4742. }
  4743. }
  4744. if (!left.identifier && left.id !== "." && left.id !== "[" &&
  4745. left.id !== "(" && left.id !== "&&" && left.id !== "||" &&
  4746. left.id !== "?") {
  4747. warning("W067", left);
  4748. }
  4749. }
  4750. that.left = left;
  4751. return that;
  4752. }, 155, true).exps = true;
  4753. prefix("(", function () {
  4754. nospace();
  4755. var bracket, brackets = [];
  4756. var pn, pn1, i = 0;
  4757. var ret;
  4758. do {
  4759. pn = peek(i);
  4760. i += 1;
  4761. pn1 = peek(i);
  4762. i += 1;
  4763. } while (pn.value !== ")" && pn1.value !== "=>" && pn1.value !== ";" && pn1.type !== "(end)");
  4764. if (state.tokens.next.id === "function") {
  4765. state.tokens.next.immed = true;
  4766. }
  4767. var exprs = [];
  4768. if (state.tokens.next.id !== ")") {
  4769. for (;;) {
  4770. if (pn1.value === "=>" && state.tokens.next.value === "{") {
  4771. bracket = state.tokens.next;
  4772. bracket.left = destructuringExpression();
  4773. brackets.push(bracket);
  4774. for (var t in bracket.left) {
  4775. exprs.push(bracket.left[t].token);
  4776. }
  4777. } else {
  4778. exprs.push(expression(10));
  4779. }
  4780. if (state.tokens.next.id !== ",") {
  4781. break;
  4782. }
  4783. comma();
  4784. }
  4785. }
  4786. advance(")", this);
  4787. nospace(state.tokens.prev, state.tokens.curr);
  4788. if (state.option.immed && exprs[0] && exprs[0].id === "function") {
  4789. if (state.tokens.next.id !== "(" &&
  4790. (state.tokens.next.id !== "." || (peek().value !== "call" && peek().value !== "apply"))) {
  4791. warning("W068", this);
  4792. }
  4793. }
  4794. if (state.tokens.next.value === "=>") {
  4795. return exprs;
  4796. }
  4797. if (!exprs.length) {
  4798. return;
  4799. }
  4800. if (exprs.length > 1) {
  4801. ret = Object.create(state.syntax[","]);
  4802. ret.exprs = exprs;
  4803. } else {
  4804. ret = exprs[0];
  4805. }
  4806. if (ret) {
  4807. ret.paren = true;
  4808. }
  4809. return ret;
  4810. });
  4811. application("=>");
  4812. infix("[", function (left, that) {
  4813. nobreak(state.tokens.prev, state.tokens.curr);
  4814. nospace();
  4815. var e = expression(10), s;
  4816. if (e && e.type === "(string)") {
  4817. if (!state.option.evil && (e.value === "eval" || e.value === "execScript")) {
  4818. warning("W061", that);
  4819. }
  4820. countMember(e.value);
  4821. if (!state.option.sub && reg.identifier.test(e.value)) {
  4822. s = state.syntax[e.value];
  4823. if (!s || !isReserved(s)) {
  4824. warning("W069", state.tokens.prev, e.value);
  4825. }
  4826. }
  4827. }
  4828. advance("]", that);
  4829. if (e && e.value === "hasOwnProperty" && state.tokens.next.value === "=") {
  4830. warning("W001");
  4831. }
  4832. nospace(state.tokens.prev, state.tokens.curr);
  4833. that.left = left;
  4834. that.right = e;
  4835. return that;
  4836. }, 160, true);
  4837. function comprehensiveArrayExpression() {
  4838. var res = {};
  4839. res.exps = true;
  4840. funct["(comparray)"].stack();
  4841. // Handle reversed for expressions, used in spidermonkey
  4842. var reversed = false;
  4843. if (state.tokens.next.value !== "for") {
  4844. reversed = true;
  4845. if (!state.option.inMoz(true)) {
  4846. warning("W116", state.tokens.next, "for", state.tokens.next.value);
  4847. }
  4848. funct["(comparray)"].setState("use");
  4849. res.right = expression(10);
  4850. }
  4851. advance("for");
  4852. if (state.tokens.next.value === "each") {
  4853. advance("each");
  4854. if (!state.option.inMoz(true)) {
  4855. warning("W118", state.tokens.curr, "for each");
  4856. }
  4857. }
  4858. advance("(");
  4859. funct["(comparray)"].setState("define");
  4860. res.left = expression(130);
  4861. if (_.contains(["in", "of"], state.tokens.next.value)) {
  4862. advance();
  4863. } else {
  4864. error("E045", state.tokens.curr);
  4865. }
  4866. funct["(comparray)"].setState("generate");
  4867. expression(10);
  4868. advance(")");
  4869. if (state.tokens.next.value === "if") {
  4870. advance("if");
  4871. advance("(");
  4872. funct["(comparray)"].setState("filter");
  4873. res.filter = expression(10);
  4874. advance(")");
  4875. }
  4876. if (!reversed) {
  4877. funct["(comparray)"].setState("use");
  4878. res.right = expression(10);
  4879. }
  4880. advance("]");
  4881. funct["(comparray)"].unstack();
  4882. return res;
  4883. }
  4884. prefix("[", function () {
  4885. var blocktype = lookupBlockType(true);
  4886. if (blocktype.isCompArray) {
  4887. if (!state.option.inESNext()) {
  4888. warning("W119", state.tokens.curr, "array comprehension");
  4889. }
  4890. return comprehensiveArrayExpression();
  4891. } else if (blocktype.isDestAssign && !state.option.inESNext()) {
  4892. warning("W104", state.tokens.curr, "destructuring assignment");
  4893. }
  4894. var b = state.tokens.curr.line !== state.tokens.next.line;
  4895. this.first = [];
  4896. if (b) {
  4897. indent += state.option.indent;
  4898. if (state.tokens.next.from === indent + state.option.indent) {
  4899. indent += state.option.indent;
  4900. }
  4901. }
  4902. while (state.tokens.next.id !== "(end)") {
  4903. while (state.tokens.next.id === ",") {
  4904. if (!state.option.inES5())
  4905. warning("W070");
  4906. advance(",");
  4907. }
  4908. if (state.tokens.next.id === "]") {
  4909. break;
  4910. }
  4911. if (b && state.tokens.curr.line !== state.tokens.next.line) {
  4912. indentation();
  4913. }
  4914. this.first.push(expression(10));
  4915. if (state.tokens.next.id === ",") {
  4916. comma({ allowTrailing: true });
  4917. if (state.tokens.next.id === "]" && !state.option.inES5(true)) {
  4918. warning("W070", state.tokens.curr);
  4919. break;
  4920. }
  4921. } else {
  4922. break;
  4923. }
  4924. }
  4925. if (b) {
  4926. indent -= state.option.indent;
  4927. indentation();
  4928. }
  4929. advance("]", this);
  4930. return this;
  4931. }, 160);
  4932. function property_name() {
  4933. var id = optionalidentifier(false, true);
  4934. if (!id) {
  4935. if (state.tokens.next.id === "(string)") {
  4936. id = state.tokens.next.value;
  4937. advance();
  4938. } else if (state.tokens.next.id === "(number)") {
  4939. id = state.tokens.next.value.toString();
  4940. advance();
  4941. }
  4942. }
  4943. if (id === "hasOwnProperty") {
  4944. warning("W001");
  4945. }
  4946. return id;
  4947. }
  4948. function functionparams(parsed) {
  4949. var curr, next;
  4950. var params = [];
  4951. var ident;
  4952. var tokens = [];
  4953. var t;
  4954. var pastDefault = false;
  4955. if (parsed) {
  4956. if (parsed instanceof Array) {
  4957. for (var i in parsed) {
  4958. curr = parsed[i];
  4959. if (_.contains(["{", "["], curr.id)) {
  4960. for (t in curr.left) {
  4961. t = tokens[t];
  4962. if (t.id) {
  4963. params.push(t.id);
  4964. addlabel(t.id, "unused", t.token);
  4965. }
  4966. }
  4967. } else if (curr.value === "...") {
  4968. if (!state.option.inESNext()) {
  4969. warning("W104", curr, "spread/rest operator");
  4970. }
  4971. continue;
  4972. } else {
  4973. addlabel(curr.value, "unused", curr);
  4974. }
  4975. }
  4976. return params;
  4977. } else {
  4978. if (parsed.identifier === true) {
  4979. addlabel(parsed.value, "unused", parsed);
  4980. return [parsed];
  4981. }
  4982. }
  4983. }
  4984. next = state.tokens.next;
  4985. advance("(");
  4986. nospace();
  4987. if (state.tokens.next.id === ")") {
  4988. advance(")");
  4989. return;
  4990. }
  4991. for (;;) {
  4992. if (_.contains(["{", "["], state.tokens.next.id)) {
  4993. tokens = destructuringExpression();
  4994. for (t in tokens) {
  4995. t = tokens[t];
  4996. if (t.id) {
  4997. params.push(t.id);
  4998. addlabel(t.id, "unused", t.token);
  4999. }
  5000. }
  5001. } else if (state.tokens.next.value === "...") {
  5002. if (!state.option.inESNext()) {
  5003. warning("W104", state.tokens.next, "spread/rest operator");
  5004. }
  5005. advance("...");
  5006. nospace();
  5007. ident = identifier(true);
  5008. params.push(ident);
  5009. addlabel(ident, "unused", state.tokens.curr);
  5010. } else {
  5011. ident = identifier(true);
  5012. params.push(ident);
  5013. addlabel(ident, "unused", state.tokens.curr);
  5014. }
  5015. // it is a syntax error to have a regular argument after a default argument
  5016. if (pastDefault) {
  5017. if (state.tokens.next.id !== "=") {
  5018. error("E051", state.tokens.current);
  5019. }
  5020. }
  5021. if (state.tokens.next.id === "=") {
  5022. if (!state.option.inESNext()) {
  5023. warning("W119", state.tokens.next, "default parameters");
  5024. }
  5025. advance("=");
  5026. pastDefault = true;
  5027. expression(10);
  5028. }
  5029. if (state.tokens.next.id === ",") {
  5030. comma();
  5031. } else {
  5032. advance(")", next);
  5033. nospace(state.tokens.prev, state.tokens.curr);
  5034. return params;
  5035. }
  5036. }
  5037. }
  5038. function doFunction(name, statement, generator, fatarrowparams) {
  5039. var f;
  5040. var oldOption = state.option;
  5041. var oldIgnored = state.ignored;
  5042. var oldScope = scope;
  5043. state.option = Object.create(state.option);
  5044. state.ignored = Object.create(state.ignored);
  5045. scope = Object.create(scope);
  5046. funct = {
  5047. "(name)" : name || "\"" + anonname + "\"",
  5048. "(line)" : state.tokens.next.line,
  5049. "(character)" : state.tokens.next.character,
  5050. "(context)" : funct,
  5051. "(breakage)" : 0,
  5052. "(loopage)" : 0,
  5053. "(metrics)" : createMetrics(state.tokens.next),
  5054. "(scope)" : scope,
  5055. "(statement)" : statement,
  5056. "(tokens)" : {},
  5057. "(blockscope)": funct["(blockscope)"],
  5058. "(comparray)" : funct["(comparray)"]
  5059. };
  5060. if (generator) {
  5061. funct["(generator)"] = true;
  5062. }
  5063. f = funct;
  5064. state.tokens.curr.funct = funct;
  5065. functions.push(funct);
  5066. if (name) {
  5067. addlabel(name, "function");
  5068. }
  5069. funct["(params)"] = functionparams(fatarrowparams);
  5070. funct["(metrics)"].verifyMaxParametersPerFunction(funct["(params)"]);
  5071. block(false, true, true, fatarrowparams ? true:false);
  5072. if (generator && funct["(generator)"] !== "yielded") {
  5073. error("E047", state.tokens.curr);
  5074. }
  5075. funct["(metrics)"].verifyMaxStatementsPerFunction();
  5076. funct["(metrics)"].verifyMaxComplexityPerFunction();
  5077. funct["(unusedOption)"] = state.option.unused;
  5078. scope = oldScope;
  5079. state.option = oldOption;
  5080. state.ignored = oldIgnored;
  5081. funct["(last)"] = state.tokens.curr.line;
  5082. funct["(lastcharacter)"] = state.tokens.curr.character;
  5083. funct = funct["(context)"];
  5084. return f;
  5085. }
  5086. function createMetrics(functionStartToken) {
  5087. return {
  5088. statementCount: 0,
  5089. nestedBlockDepth: -1,
  5090. ComplexityCount: 1,
  5091. verifyMaxStatementsPerFunction: function () {
  5092. if (state.option.maxstatements &&
  5093. this.statementCount > state.option.maxstatements) {
  5094. warning("W071", functionStartToken, this.statementCount);
  5095. }
  5096. },
  5097. verifyMaxParametersPerFunction: function (params) {
  5098. params = params || [];
  5099. if (state.option.maxparams && params.length > state.option.maxparams) {
  5100. warning("W072", functionStartToken, params.length);
  5101. }
  5102. },
  5103. verifyMaxNestedBlockDepthPerFunction: function () {
  5104. if (state.option.maxdepth &&
  5105. this.nestedBlockDepth > 0 &&
  5106. this.nestedBlockDepth === state.option.maxdepth + 1) {
  5107. warning("W073", null, this.nestedBlockDepth);
  5108. }
  5109. },
  5110. verifyMaxComplexityPerFunction: function () {
  5111. var max = state.option.maxcomplexity;
  5112. var cc = this.ComplexityCount;
  5113. if (max && cc > max) {
  5114. warning("W074", functionStartToken, cc);
  5115. }
  5116. }
  5117. };
  5118. }
  5119. function increaseComplexityCount() {
  5120. funct["(metrics)"].ComplexityCount += 1;
  5121. }
  5122. // Parse assignments that were found instead of conditionals.
  5123. // For example: if (a = 1) { ... }
  5124. function checkCondAssignment(expr) {
  5125. var id, paren;
  5126. if (expr) {
  5127. id = expr.id;
  5128. paren = expr.paren;
  5129. if (id === "," && (expr = expr.exprs[expr.exprs.length - 1])) {
  5130. id = expr.id;
  5131. paren = paren || expr.paren;
  5132. }
  5133. }
  5134. switch (id) {
  5135. case "=":
  5136. case "+=":
  5137. case "-=":
  5138. case "*=":
  5139. case "%=":
  5140. case "&=":
  5141. case "|=":
  5142. case "^=":
  5143. case "/=":
  5144. if (!paren && !state.option.boss) {
  5145. warning("W084");
  5146. }
  5147. }
  5148. }
  5149. (function (x) {
  5150. x.nud = function (isclassdef) {
  5151. var b, f, i, p, t, g;
  5152. var props = {}; // All properties, including accessors
  5153. var tag = "";
  5154. function saveProperty(name, tkn) {
  5155. if (props[name] && _.has(props, name))
  5156. warning("W075", state.tokens.next, i);
  5157. else
  5158. props[name] = {};
  5159. props[name].basic = true;
  5160. props[name].basictkn = tkn;
  5161. }
  5162. function saveSetter(name, tkn) {
  5163. if (props[name] && _.has(props, name)) {
  5164. if (props[name].basic || props[name].setter)
  5165. warning("W075", state.tokens.next, i);
  5166. } else {
  5167. props[name] = {};
  5168. }
  5169. props[name].setter = true;
  5170. props[name].setterToken = tkn;
  5171. }
  5172. function saveGetter(name) {
  5173. if (props[name] && _.has(props, name)) {
  5174. if (props[name].basic || props[name].getter)
  5175. warning("W075", state.tokens.next, i);
  5176. } else {
  5177. props[name] = {};
  5178. }
  5179. props[name].getter = true;
  5180. props[name].getterToken = state.tokens.curr;
  5181. }
  5182. b = state.tokens.curr.line !== state.tokens.next.line;
  5183. if (b) {
  5184. indent += state.option.indent;
  5185. if (state.tokens.next.from === indent + state.option.indent) {
  5186. indent += state.option.indent;
  5187. }
  5188. }
  5189. for (;;) {
  5190. if (state.tokens.next.id === "}") {
  5191. break;
  5192. }
  5193. if (b) {
  5194. indentation();
  5195. }
  5196. if (isclassdef && state.tokens.next.value === "static") {
  5197. advance("static");
  5198. tag = "static ";
  5199. }
  5200. if (state.tokens.next.value === "get" && peek().id !== ":") {
  5201. advance("get");
  5202. if (!state.option.inES5(!isclassdef)) {
  5203. error("E034");
  5204. }
  5205. i = property_name();
  5206. if (!i) {
  5207. error("E035");
  5208. }
  5209. // It is a Syntax Error if PropName of MethodDefinition is
  5210. // "constructor" and SpecialMethod of MethodDefinition is true.
  5211. if (isclassdef && i === "constructor") {
  5212. error("E049", state.tokens.next, "class getter method", i);
  5213. }
  5214. saveGetter(tag + i);
  5215. t = state.tokens.next;
  5216. adjacent(state.tokens.curr, state.tokens.next);
  5217. f = doFunction();
  5218. p = f["(params)"];
  5219. if (p) {
  5220. warning("W076", t, p[0], i);
  5221. }
  5222. adjacent(state.tokens.curr, state.tokens.next);
  5223. } else if (state.tokens.next.value === "set" && peek().id !== ":") {
  5224. advance("set");
  5225. if (!state.option.inES5(!isclassdef)) {
  5226. error("E034");
  5227. }
  5228. i = property_name();
  5229. if (!i) {
  5230. error("E035");
  5231. }
  5232. // It is a Syntax Error if PropName of MethodDefinition is
  5233. // "constructor" and SpecialMethod of MethodDefinition is true.
  5234. if (isclassdef && i === "constructor") {
  5235. error("E049", state.tokens.next, "class setter method", i);
  5236. }
  5237. saveSetter(tag + i, state.tokens.next);
  5238. t = state.tokens.next;
  5239. adjacent(state.tokens.curr, state.tokens.next);
  5240. f = doFunction();
  5241. p = f["(params)"];
  5242. if (!p || p.length !== 1) {
  5243. warning("W077", t, i);
  5244. }
  5245. } else {
  5246. g = false;
  5247. if (state.tokens.next.value === "*" && state.tokens.next.type === "(punctuator)") {
  5248. if (!state.option.inESNext()) {
  5249. warning("W104", state.tokens.next, "generator functions");
  5250. }
  5251. advance("*");
  5252. g = true;
  5253. }
  5254. i = property_name();
  5255. saveProperty(tag + i, state.tokens.next);
  5256. if (typeof i !== "string") {
  5257. break;
  5258. }
  5259. if (state.tokens.next.value === "(") {
  5260. if (!state.option.inESNext()) {
  5261. warning("W104", state.tokens.curr, "concise methods");
  5262. }
  5263. doFunction(i, undefined, g);
  5264. } else if (!isclassdef) {
  5265. advance(":");
  5266. nonadjacent(state.tokens.curr, state.tokens.next);
  5267. expression(10);
  5268. }
  5269. }
  5270. // It is a Syntax Error if PropName of MethodDefinition is "prototype".
  5271. if (isclassdef && i === "prototype") {
  5272. error("E049", state.tokens.next, "class method", i);
  5273. }
  5274. countMember(i);
  5275. if (isclassdef) {
  5276. tag = "";
  5277. continue;
  5278. }
  5279. if (state.tokens.next.id === ",") {
  5280. comma({ allowTrailing: true, property: true });
  5281. if (state.tokens.next.id === ",") {
  5282. warning("W070", state.tokens.curr);
  5283. } else if (state.tokens.next.id === "}" && !state.option.inES5(true)) {
  5284. warning("W070", state.tokens.curr);
  5285. }
  5286. } else {
  5287. break;
  5288. }
  5289. }
  5290. if (b) {
  5291. indent -= state.option.indent;
  5292. indentation();
  5293. }
  5294. advance("}", this);
  5295. // Check for lonely setters if in the ES5 mode.
  5296. if (state.option.inES5()) {
  5297. for (var name in props) {
  5298. if (_.has(props, name) && props[name].setter && !props[name].getter) {
  5299. warning("W078", props[name].setterToken);
  5300. }
  5301. }
  5302. }
  5303. return this;
  5304. };
  5305. x.fud = function () {
  5306. error("E036", state.tokens.curr);
  5307. };
  5308. }(delim("{")));
  5309. function destructuringExpression() {
  5310. var id, ids;
  5311. var identifiers = [];
  5312. if (!state.option.inESNext()) {
  5313. warning("W104", state.tokens.curr, "destructuring expression");
  5314. }
  5315. var nextInnerDE = function () {
  5316. var ident;
  5317. if (_.contains(["[", "{"], state.tokens.next.value)) {
  5318. ids = destructuringExpression();
  5319. for (var id in ids) {
  5320. id = ids[id];
  5321. identifiers.push({ id: id.id, token: id.token });
  5322. }
  5323. } else if (state.tokens.next.value === ",") {
  5324. identifiers.push({ id: null, token: state.tokens.curr });
  5325. } else {
  5326. ident = identifier();
  5327. if (ident)
  5328. identifiers.push({ id: ident, token: state.tokens.curr });
  5329. }
  5330. };
  5331. if (state.tokens.next.value === "[") {
  5332. advance("[");
  5333. nextInnerDE();
  5334. while (state.tokens.next.value !== "]") {
  5335. advance(",");
  5336. nextInnerDE();
  5337. }
  5338. advance("]");
  5339. } else if (state.tokens.next.value === "{") {
  5340. advance("{");
  5341. id = identifier();
  5342. if (state.tokens.next.value === ":") {
  5343. advance(":");
  5344. nextInnerDE();
  5345. } else {
  5346. identifiers.push({ id: id, token: state.tokens.curr });
  5347. }
  5348. while (state.tokens.next.value !== "}") {
  5349. advance(",");
  5350. id = identifier();
  5351. if (state.tokens.next.value === ":") {
  5352. advance(":");
  5353. nextInnerDE();
  5354. } else {
  5355. identifiers.push({ id: id, token: state.tokens.curr });
  5356. }
  5357. }
  5358. advance("}");
  5359. }
  5360. return identifiers;
  5361. }
  5362. function destructuringExpressionMatch(tokens, value) {
  5363. if (value.first) {
  5364. _.zip(tokens, value.first).forEach(function (val) {
  5365. var token = val[0];
  5366. var value = val[1];
  5367. if (token && value) {
  5368. token.first = value;
  5369. } else if (token && token.first && !value) {
  5370. warning("W080", token.first, token.first.value);
  5371. } /* else {
  5372. XXX value is discarded: wouldn't it need a warning ?
  5373. } */
  5374. });
  5375. }
  5376. }
  5377. var conststatement = stmt("const", function (prefix) {
  5378. var tokens, value;
  5379. // state variable to know if it is a lone identifier, or a destructuring statement.
  5380. var lone;
  5381. if (!state.option.inESNext()) {
  5382. warning("W104", state.tokens.curr, "const");
  5383. }
  5384. this.first = [];
  5385. for (;;) {
  5386. var names = [];
  5387. nonadjacent(state.tokens.curr, state.tokens.next);
  5388. if (_.contains(["{", "["], state.tokens.next.value)) {
  5389. tokens = destructuringExpression();
  5390. lone = false;
  5391. } else {
  5392. tokens = [ { id: identifier(), token: state.tokens.curr } ];
  5393. lone = true;
  5394. }
  5395. for (var t in tokens) {
  5396. t = tokens[t];
  5397. if (funct[t.id] === "const") {
  5398. warning("E011", null, t.id);
  5399. }
  5400. if (funct["(global)"] && predefined[t.id] === false) {
  5401. warning("W079", t.token, t.id);
  5402. }
  5403. if (t.id) {
  5404. addlabel(t.id, "const");
  5405. names.push(t.token);
  5406. }
  5407. }
  5408. if (prefix) {
  5409. break;
  5410. }
  5411. this.first = this.first.concat(names);
  5412. if (state.tokens.next.id !== "=") {
  5413. warning("E012", state.tokens.curr, state.tokens.curr.value);
  5414. }
  5415. if (state.tokens.next.id === "=") {
  5416. nonadjacent(state.tokens.curr, state.tokens.next);
  5417. advance("=");
  5418. nonadjacent(state.tokens.curr, state.tokens.next);
  5419. if (state.tokens.next.id === "undefined") {
  5420. warning("W080", state.tokens.prev, state.tokens.prev.value);
  5421. }
  5422. if (peek(0).id === "=" && state.tokens.next.identifier) {
  5423. warning("W120", state.tokens.next, state.tokens.next.value);
  5424. }
  5425. value = expression(10);
  5426. if (lone) {
  5427. tokens[0].first = value;
  5428. } else {
  5429. destructuringExpressionMatch(names, value);
  5430. }
  5431. }
  5432. if (state.tokens.next.id !== ",") {
  5433. break;
  5434. }
  5435. comma();
  5436. }
  5437. return this;
  5438. });
  5439. conststatement.exps = true;
  5440. var varstatement = stmt("var", function (prefix) {
  5441. // JavaScript does not have block scope. It only has function scope. So,
  5442. // declaring a variable in a block can have unexpected consequences.
  5443. var tokens, lone, value;
  5444. if (funct["(onevar)"] && state.option.onevar) {
  5445. warning("W081");
  5446. } else if (!funct["(global)"]) {
  5447. funct["(onevar)"] = true;
  5448. }
  5449. this.first = [];
  5450. for (;;) {
  5451. var names = [];
  5452. nonadjacent(state.tokens.curr, state.tokens.next);
  5453. if (_.contains(["{", "["], state.tokens.next.value)) {
  5454. tokens = destructuringExpression();
  5455. lone = false;
  5456. } else {
  5457. tokens = [ { id: identifier(), token: state.tokens.curr } ];
  5458. lone = true;
  5459. }
  5460. for (var t in tokens) {
  5461. t = tokens[t];
  5462. if (state.option.inESNext() && funct[t.id] === "const") {
  5463. warning("E011", null, t.id);
  5464. }
  5465. if (funct["(global)"] && predefined[t.id] === false) {
  5466. warning("W079", t.token, t.id);
  5467. }
  5468. if (t.id) {
  5469. addlabel(t.id, "unused", t.token);
  5470. names.push(t.token);
  5471. }
  5472. }
  5473. if (prefix) {
  5474. break;
  5475. }
  5476. this.first = this.first.concat(names);
  5477. if (state.tokens.next.id === "=") {
  5478. nonadjacent(state.tokens.curr, state.tokens.next);
  5479. advance("=");
  5480. nonadjacent(state.tokens.curr, state.tokens.next);
  5481. if (state.tokens.next.id === "undefined") {
  5482. warning("W080", state.tokens.prev, state.tokens.prev.value);
  5483. }
  5484. if (peek(0).id === "=" && state.tokens.next.identifier) {
  5485. warning("W120", state.tokens.next, state.tokens.next.value);
  5486. }
  5487. value = expression(10);
  5488. if (lone) {
  5489. tokens[0].first = value;
  5490. } else {
  5491. destructuringExpressionMatch(names, value);
  5492. }
  5493. }
  5494. if (state.tokens.next.id !== ",") {
  5495. break;
  5496. }
  5497. comma();
  5498. }
  5499. return this;
  5500. });
  5501. varstatement.exps = true;
  5502. var letstatement = stmt("let", function (prefix) {
  5503. var tokens, lone, value, letblock;
  5504. if (!state.option.inESNext()) {
  5505. warning("W104", state.tokens.curr, "let");
  5506. }
  5507. if (state.tokens.next.value === "(") {
  5508. if (!state.option.inMoz(true)) {
  5509. warning("W118", state.tokens.next, "let block");
  5510. }
  5511. advance("(");
  5512. funct["(blockscope)"].stack();
  5513. letblock = true;
  5514. } else if (funct["(nolet)"]) {
  5515. error("E048", state.tokens.curr);
  5516. }
  5517. if (funct["(onevar)"] && state.option.onevar) {
  5518. warning("W081");
  5519. } else if (!funct["(global)"]) {
  5520. funct["(onevar)"] = true;
  5521. }
  5522. this.first = [];
  5523. for (;;) {
  5524. var names = [];
  5525. nonadjacent(state.tokens.curr, state.tokens.next);
  5526. if (_.contains(["{", "["], state.tokens.next.value)) {
  5527. tokens = destructuringExpression();
  5528. lone = false;
  5529. } else {
  5530. tokens = [ { id: identifier(), token: state.tokens.curr.value } ];
  5531. lone = true;
  5532. }
  5533. for (var t in tokens) {
  5534. t = tokens[t];
  5535. if (state.option.inESNext() && funct[t.id] === "const") {
  5536. warning("E011", null, t.id);
  5537. }
  5538. if (funct["(global)"] && predefined[t.id] === false) {
  5539. warning("W079", t.token, t.id);
  5540. }
  5541. if (t.id && !funct["(nolet)"]) {
  5542. addlabel(t.id, "unused", t.token, true);
  5543. names.push(t.token);
  5544. }
  5545. }
  5546. if (prefix) {
  5547. break;
  5548. }
  5549. this.first = this.first.concat(names);
  5550. if (state.tokens.next.id === "=") {
  5551. nonadjacent(state.tokens.curr, state.tokens.next);
  5552. advance("=");
  5553. nonadjacent(state.tokens.curr, state.tokens.next);
  5554. if (state.tokens.next.id === "undefined") {
  5555. warning("W080", state.tokens.prev, state.tokens.prev.value);
  5556. }
  5557. if (peek(0).id === "=" && state.tokens.next.identifier) {
  5558. warning("W120", state.tokens.next, state.tokens.next.value);
  5559. }
  5560. value = expression(10);
  5561. if (lone) {
  5562. tokens[0].first = value;
  5563. } else {
  5564. destructuringExpressionMatch(names, value);
  5565. }
  5566. }
  5567. if (state.tokens.next.id !== ",") {
  5568. break;
  5569. }
  5570. comma();
  5571. }
  5572. if (letblock) {
  5573. advance(")");
  5574. block(true, true);
  5575. this.block = true;
  5576. funct["(blockscope)"].unstack();
  5577. }
  5578. return this;
  5579. });
  5580. letstatement.exps = true;
  5581. blockstmt("class", function () {
  5582. return classdef.call(this, true);
  5583. });
  5584. function classdef(stmt) {
  5585. /*jshint validthis:true */
  5586. if (!state.option.inESNext()) {
  5587. warning("W104", state.tokens.curr, "class");
  5588. }
  5589. if (stmt) {
  5590. // BindingIdentifier
  5591. this.name = identifier();
  5592. addlabel(this.name, "unused", state.tokens.curr);
  5593. } else if (state.tokens.next.identifier && state.tokens.next.value !== "extends") {
  5594. // BindingIdentifier(opt)
  5595. this.name = identifier();
  5596. }
  5597. classtail(this);
  5598. return this;
  5599. }
  5600. function classtail(c) {
  5601. var strictness = state.directive["use strict"];
  5602. // ClassHeritage(opt)
  5603. if (state.tokens.next.value === "extends") {
  5604. advance("extends");
  5605. c.heritage = expression(10);
  5606. }
  5607. // A ClassBody is always strict code.
  5608. state.directive["use strict"] = true;
  5609. advance("{");
  5610. // ClassBody(opt)
  5611. c.body = state.syntax["{"].nud(true);
  5612. state.directive["use strict"] = strictness;
  5613. }
  5614. blockstmt("function", function () {
  5615. var generator = false;
  5616. if (state.tokens.next.value === "*") {
  5617. advance("*");
  5618. if (state.option.inESNext(true)) {
  5619. generator = true;
  5620. } else {
  5621. warning("W119", state.tokens.curr, "function*");
  5622. }
  5623. }
  5624. if (inblock) {
  5625. warning("W082", state.tokens.curr);
  5626. }
  5627. var i = identifier();
  5628. if (funct[i] === "const") {
  5629. warning("E011", null, i);
  5630. }
  5631. adjacent(state.tokens.curr, state.tokens.next);
  5632. addlabel(i, "unction", state.tokens.curr);
  5633. doFunction(i, { statement: true }, generator);
  5634. if (state.tokens.next.id === "(" && state.tokens.next.line === state.tokens.curr.line) {
  5635. error("E039");
  5636. }
  5637. return this;
  5638. });
  5639. prefix("function", function () {
  5640. var generator = false;
  5641. if (state.tokens.next.value === "*") {
  5642. if (!state.option.inESNext()) {
  5643. warning("W119", state.tokens.curr, "function*");
  5644. }
  5645. advance("*");
  5646. generator = true;
  5647. }
  5648. var i = optionalidentifier();
  5649. if (i || state.option.gcl) {
  5650. adjacent(state.tokens.curr, state.tokens.next);
  5651. } else {
  5652. nonadjacent(state.tokens.curr, state.tokens.next);
  5653. }
  5654. doFunction(i, undefined, generator);
  5655. if (!state.option.loopfunc && funct["(loopage)"]) {
  5656. warning("W083");
  5657. }
  5658. return this;
  5659. });
  5660. blockstmt("if", function () {
  5661. var t = state.tokens.next;
  5662. increaseComplexityCount();
  5663. state.condition = true;
  5664. advance("(");
  5665. nonadjacent(this, t);
  5666. nospace();
  5667. checkCondAssignment(expression(0));
  5668. advance(")", t);
  5669. state.condition = false;
  5670. nospace(state.tokens.prev, state.tokens.curr);
  5671. block(true, true);
  5672. if (state.tokens.next.id === "else") {
  5673. nonadjacent(state.tokens.curr, state.tokens.next);
  5674. advance("else");
  5675. if (state.tokens.next.id === "if" || state.tokens.next.id === "switch") {
  5676. statement(true);
  5677. } else {
  5678. block(true, true);
  5679. }
  5680. }
  5681. return this;
  5682. });
  5683. blockstmt("try", function () {
  5684. var b;
  5685. function doCatch() {
  5686. var oldScope = scope;
  5687. var e;
  5688. advance("catch");
  5689. nonadjacent(state.tokens.curr, state.tokens.next);
  5690. advance("(");
  5691. scope = Object.create(oldScope);
  5692. e = state.tokens.next.value;
  5693. if (state.tokens.next.type !== "(identifier)") {
  5694. e = null;
  5695. warning("E030", state.tokens.next, e);
  5696. }
  5697. advance();
  5698. funct = {
  5699. "(name)" : "(catch)",
  5700. "(line)" : state.tokens.next.line,
  5701. "(character)": state.tokens.next.character,
  5702. "(context)" : funct,
  5703. "(breakage)" : funct["(breakage)"],
  5704. "(loopage)" : funct["(loopage)"],
  5705. "(scope)" : scope,
  5706. "(statement)": false,
  5707. "(metrics)" : createMetrics(state.tokens.next),
  5708. "(catch)" : true,
  5709. "(tokens)" : {},
  5710. "(blockscope)": funct["(blockscope)"],
  5711. "(comparray)": funct["(comparray)"]
  5712. };
  5713. if (e) {
  5714. addlabel(e, "exception");
  5715. }
  5716. if (state.tokens.next.value === "if") {
  5717. if (!state.option.inMoz(true)) {
  5718. warning("W118", state.tokens.curr, "catch filter");
  5719. }
  5720. advance("if");
  5721. expression(0);
  5722. }
  5723. advance(")");
  5724. state.tokens.curr.funct = funct;
  5725. functions.push(funct);
  5726. block(false);
  5727. scope = oldScope;
  5728. funct["(last)"] = state.tokens.curr.line;
  5729. funct["(lastcharacter)"] = state.tokens.curr.character;
  5730. funct = funct["(context)"];
  5731. }
  5732. block(false);
  5733. while (state.tokens.next.id === "catch") {
  5734. increaseComplexityCount();
  5735. if (b && (!state.option.inMoz(true))) {
  5736. warning("W118", state.tokens.next, "multiple catch blocks");
  5737. }
  5738. doCatch();
  5739. b = true;
  5740. }
  5741. if (state.tokens.next.id === "finally") {
  5742. advance("finally");
  5743. block(false);
  5744. return;
  5745. }
  5746. if (!b) {
  5747. error("E021", state.tokens.next, "catch", state.tokens.next.value);
  5748. }
  5749. return this;
  5750. });
  5751. blockstmt("while", function () {
  5752. var t = state.tokens.next;
  5753. funct["(breakage)"] += 1;
  5754. funct["(loopage)"] += 1;
  5755. increaseComplexityCount();
  5756. advance("(");
  5757. nonadjacent(this, t);
  5758. nospace();
  5759. checkCondAssignment(expression(0));
  5760. advance(")", t);
  5761. nospace(state.tokens.prev, state.tokens.curr);
  5762. block(true, true);
  5763. funct["(breakage)"] -= 1;
  5764. funct["(loopage)"] -= 1;
  5765. return this;
  5766. }).labelled = true;
  5767. blockstmt("with", function () {
  5768. var t = state.tokens.next;
  5769. if (state.directive["use strict"]) {
  5770. error("E010", state.tokens.curr);
  5771. } else if (!state.option.withstmt) {
  5772. warning("W085", state.tokens.curr);
  5773. }
  5774. advance("(");
  5775. nonadjacent(this, t);
  5776. nospace();
  5777. expression(0);
  5778. advance(")", t);
  5779. nospace(state.tokens.prev, state.tokens.curr);
  5780. block(true, true);
  5781. return this;
  5782. });
  5783. blockstmt("switch", function () {
  5784. var t = state.tokens.next,
  5785. g = false;
  5786. funct["(breakage)"] += 1;
  5787. advance("(");
  5788. nonadjacent(this, t);
  5789. nospace();
  5790. checkCondAssignment(expression(0));
  5791. advance(")", t);
  5792. nospace(state.tokens.prev, state.tokens.curr);
  5793. nonadjacent(state.tokens.curr, state.tokens.next);
  5794. t = state.tokens.next;
  5795. advance("{");
  5796. nonadjacent(state.tokens.curr, state.tokens.next);
  5797. indent += state.option.indent;
  5798. this.cases = [];
  5799. for (;;) {
  5800. switch (state.tokens.next.id) {
  5801. case "case":
  5802. switch (funct["(verb)"]) {
  5803. case "yield":
  5804. case "break":
  5805. case "case":
  5806. case "continue":
  5807. case "return":
  5808. case "switch":
  5809. case "throw":
  5810. break;
  5811. default:
  5812. // You can tell JSHint that you don't use break intentionally by
  5813. // adding a comment /* falls through */ on a line just before
  5814. // the next `case`.
  5815. if (!reg.fallsThrough.test(state.lines[state.tokens.next.line - 2])) {
  5816. warning("W086", state.tokens.curr, "case");
  5817. }
  5818. }
  5819. indentation(-state.option.indent);
  5820. advance("case");
  5821. this.cases.push(expression(20));
  5822. increaseComplexityCount();
  5823. g = true;
  5824. advance(":");
  5825. funct["(verb)"] = "case";
  5826. break;
  5827. case "default":
  5828. switch (funct["(verb)"]) {
  5829. case "yield":
  5830. case "break":
  5831. case "continue":
  5832. case "return":
  5833. case "throw":
  5834. break;
  5835. default:
  5836. // Do not display a warning if 'default' is the first statement or if
  5837. // there is a special /* falls through */ comment.
  5838. if (this.cases.length) {
  5839. if (!reg.fallsThrough.test(state.lines[state.tokens.next.line - 2])) {
  5840. warning("W086", state.tokens.curr, "default");
  5841. }
  5842. }
  5843. }
  5844. indentation(-state.option.indent);
  5845. advance("default");
  5846. g = true;
  5847. advance(":");
  5848. break;
  5849. case "}":
  5850. indent -= state.option.indent;
  5851. indentation();
  5852. advance("}", t);
  5853. funct["(breakage)"] -= 1;
  5854. funct["(verb)"] = undefined;
  5855. return;
  5856. case "(end)":
  5857. error("E023", state.tokens.next, "}");
  5858. return;
  5859. default:
  5860. if (g) {
  5861. switch (state.tokens.curr.id) {
  5862. case ",":
  5863. error("E040");
  5864. return;
  5865. case ":":
  5866. g = false;
  5867. statements();
  5868. break;
  5869. default:
  5870. error("E025", state.tokens.curr);
  5871. return;
  5872. }
  5873. } else {
  5874. if (state.tokens.curr.id === ":") {
  5875. advance(":");
  5876. error("E024", state.tokens.curr, ":");
  5877. statements();
  5878. } else {
  5879. error("E021", state.tokens.next, "case", state.tokens.next.value);
  5880. return;
  5881. }
  5882. }
  5883. }
  5884. }
  5885. }).labelled = true;
  5886. stmt("debugger", function () {
  5887. if (!state.option.debug) {
  5888. warning("W087", this);
  5889. }
  5890. return this;
  5891. }).exps = true;
  5892. (function () {
  5893. var x = stmt("do", function () {
  5894. funct["(breakage)"] += 1;
  5895. funct["(loopage)"] += 1;
  5896. increaseComplexityCount();
  5897. this.first = block(true, true);
  5898. advance("while");
  5899. var t = state.tokens.next;
  5900. nonadjacent(state.tokens.curr, t);
  5901. advance("(");
  5902. nospace();
  5903. checkCondAssignment(expression(0));
  5904. advance(")", t);
  5905. nospace(state.tokens.prev, state.tokens.curr);
  5906. funct["(breakage)"] -= 1;
  5907. funct["(loopage)"] -= 1;
  5908. return this;
  5909. });
  5910. x.labelled = true;
  5911. x.exps = true;
  5912. }());
  5913. blockstmt("for", function () {
  5914. var s, t = state.tokens.next;
  5915. var letscope = false;
  5916. var foreachtok = null;
  5917. if (t.value === "each") {
  5918. foreachtok = t;
  5919. advance("each");
  5920. if (!state.option.inMoz(true)) {
  5921. warning("W118", state.tokens.curr, "for each");
  5922. }
  5923. }
  5924. funct["(breakage)"] += 1;
  5925. funct["(loopage)"] += 1;
  5926. increaseComplexityCount();
  5927. advance("(");
  5928. nonadjacent(this, t);
  5929. nospace();
  5930. // what kind of for(…) statement it is? for(…of…)? for(…in…)? for(…;…;…)?
  5931. var nextop; // contains the token of the "in" or "of" operator
  5932. var i = 0;
  5933. var inof = ["in", "of"];
  5934. do {
  5935. nextop = peek(i);
  5936. ++i;
  5937. } while (!_.contains(inof, nextop.value) && nextop.value !== ";" &&
  5938. nextop.type !== "(end)");
  5939. // if we're in a for (… in|of …) statement
  5940. if (_.contains(inof, nextop.value)) {
  5941. if (!state.option.inESNext() && nextop.value === "of") {
  5942. error("W104", nextop, "for of");
  5943. }
  5944. if (state.tokens.next.id === "var") {
  5945. advance("var");
  5946. state.syntax["var"].fud.call(state.syntax["var"].fud, true);
  5947. } else if (state.tokens.next.id === "let") {
  5948. advance("let");
  5949. // create a new block scope
  5950. letscope = true;
  5951. funct["(blockscope)"].stack();
  5952. state.syntax["let"].fud.call(state.syntax["let"].fud, true);
  5953. } else {
  5954. switch (funct[state.tokens.next.value]) {
  5955. case "unused":
  5956. funct[state.tokens.next.value] = "var";
  5957. break;
  5958. case "var":
  5959. break;
  5960. default:
  5961. if (!funct["(blockscope)"].getlabel(state.tokens.next.value))
  5962. warning("W088", state.tokens.next, state.tokens.next.value);
  5963. }
  5964. advance();
  5965. }
  5966. advance(nextop.value);
  5967. expression(20);
  5968. advance(")", t);
  5969. s = block(true, true);
  5970. if (state.option.forin && s && (s.length > 1 || typeof s[0] !== "object" ||
  5971. s[0].value !== "if")) {
  5972. warning("W089", this);
  5973. }
  5974. funct["(breakage)"] -= 1;
  5975. funct["(loopage)"] -= 1;
  5976. } else {
  5977. if (foreachtok) {
  5978. error("E045", foreachtok);
  5979. }
  5980. if (state.tokens.next.id !== ";") {
  5981. if (state.tokens.next.id === "var") {
  5982. advance("var");
  5983. state.syntax["var"].fud.call(state.syntax["var"].fud);
  5984. } else if (state.tokens.next.id === "let") {
  5985. advance("let");
  5986. // create a new block scope
  5987. letscope = true;
  5988. funct["(blockscope)"].stack();
  5989. state.syntax["let"].fud.call(state.syntax["let"].fud);
  5990. } else {
  5991. for (;;) {
  5992. expression(0, "for");
  5993. if (state.tokens.next.id !== ",") {
  5994. break;
  5995. }
  5996. comma();
  5997. }
  5998. }
  5999. }
  6000. nolinebreak(state.tokens.curr);
  6001. advance(";");
  6002. if (state.tokens.next.id !== ";") {
  6003. checkCondAssignment(expression(0));
  6004. }
  6005. nolinebreak(state.tokens.curr);
  6006. advance(";");
  6007. if (state.tokens.next.id === ";") {
  6008. error("E021", state.tokens.next, ")", ";");
  6009. }
  6010. if (state.tokens.next.id !== ")") {
  6011. for (;;) {
  6012. expression(0, "for");
  6013. if (state.tokens.next.id !== ",") {
  6014. break;
  6015. }
  6016. comma();
  6017. }
  6018. }
  6019. advance(")", t);
  6020. nospace(state.tokens.prev, state.tokens.curr);
  6021. block(true, true);
  6022. funct["(breakage)"] -= 1;
  6023. funct["(loopage)"] -= 1;
  6024. }
  6025. // unstack loop blockscope
  6026. if (letscope) {
  6027. funct["(blockscope)"].unstack();
  6028. }
  6029. return this;
  6030. }).labelled = true;
  6031. stmt("break", function () {
  6032. var v = state.tokens.next.value;
  6033. if (funct["(breakage)"] === 0)
  6034. warning("W052", state.tokens.next, this.value);
  6035. if (!state.option.asi)
  6036. nolinebreak(this);
  6037. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  6038. if (state.tokens.curr.line === state.tokens.next.line) {
  6039. if (funct[v] !== "label") {
  6040. warning("W090", state.tokens.next, v);
  6041. } else if (scope[v] !== funct) {
  6042. warning("W091", state.tokens.next, v);
  6043. }
  6044. this.first = state.tokens.next;
  6045. advance();
  6046. }
  6047. }
  6048. reachable("break");
  6049. return this;
  6050. }).exps = true;
  6051. stmt("continue", function () {
  6052. var v = state.tokens.next.value;
  6053. if (funct["(breakage)"] === 0)
  6054. warning("W052", state.tokens.next, this.value);
  6055. if (!state.option.asi)
  6056. nolinebreak(this);
  6057. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  6058. if (state.tokens.curr.line === state.tokens.next.line) {
  6059. if (funct[v] !== "label") {
  6060. warning("W090", state.tokens.next, v);
  6061. } else if (scope[v] !== funct) {
  6062. warning("W091", state.tokens.next, v);
  6063. }
  6064. this.first = state.tokens.next;
  6065. advance();
  6066. }
  6067. } else if (!funct["(loopage)"]) {
  6068. warning("W052", state.tokens.next, this.value);
  6069. }
  6070. reachable("continue");
  6071. return this;
  6072. }).exps = true;
  6073. stmt("return", function () {
  6074. if (this.line === state.tokens.next.line) {
  6075. if (state.tokens.next.id === "(regexp)")
  6076. warning("W092");
  6077. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  6078. nonadjacent(state.tokens.curr, state.tokens.next);
  6079. this.first = expression(0);
  6080. if (this.first &&
  6081. this.first.type === "(punctuator)" && this.first.value === "=" && !state.option.boss) {
  6082. warningAt("W093", this.first.line, this.first.character);
  6083. }
  6084. }
  6085. } else {
  6086. if (state.tokens.next.type === "(punctuator)" &&
  6087. ["[", "{", "+", "-"].indexOf(state.tokens.next.value) > -1) {
  6088. nolinebreak(this); // always warn (Line breaking error)
  6089. }
  6090. }
  6091. reachable("return");
  6092. return this;
  6093. }).exps = true;
  6094. (function (x) {
  6095. x.exps = true;
  6096. x.lbp = 25;
  6097. }(prefix("yield", function () {
  6098. var prev = state.tokens.prev;
  6099. if (state.option.inESNext(true) && !funct["(generator)"]) {
  6100. error("E046", state.tokens.curr, "yield");
  6101. } else if (!state.option.inESNext()) {
  6102. warning("W104", state.tokens.curr, "yield");
  6103. }
  6104. funct["(generator)"] = "yielded";
  6105. if (this.line === state.tokens.next.line || !state.option.inMoz(true)) {
  6106. if (state.tokens.next.id === "(regexp)")
  6107. warning("W092");
  6108. if (state.tokens.next.id !== ";" && !state.tokens.next.reach && state.tokens.next.nud) {
  6109. nobreaknonadjacent(state.tokens.curr, state.tokens.next);
  6110. this.first = expression(10);
  6111. if (this.first.type === "(punctuator)" && this.first.value === "=" && !state.option.boss) {
  6112. warningAt("W093", this.first.line, this.first.character);
  6113. }
  6114. }
  6115. if (state.option.inMoz(true) && state.tokens.next.id !== ")" &&
  6116. (prev.lbp > 30 || (!prev.assign && !isEndOfExpr()) || prev.id === "yield")) {
  6117. error("E050", this);
  6118. }
  6119. } else if (!state.option.asi) {
  6120. nolinebreak(this); // always warn (Line breaking error)
  6121. }
  6122. return this;
  6123. })));
  6124. stmt("throw", function () {
  6125. nolinebreak(this);
  6126. nonadjacent(state.tokens.curr, state.tokens.next);
  6127. this.first = expression(20);
  6128. reachable("throw");
  6129. return this;
  6130. }).exps = true;
  6131. stmt("import", function () {
  6132. if (!state.option.inESNext()) {
  6133. warning("W119", state.tokens.curr, "import");
  6134. }
  6135. if (state.tokens.next.identifier) {
  6136. this.name = identifier();
  6137. addlabel(this.name, "unused", state.tokens.curr);
  6138. } else {
  6139. advance("{");
  6140. for (;;) {
  6141. var importName;
  6142. if (state.tokens.next.type === "default") {
  6143. importName = "default";
  6144. advance("default");
  6145. } else {
  6146. importName = identifier();
  6147. }
  6148. if (state.tokens.next.value === "as") {
  6149. advance("as");
  6150. importName = identifier();
  6151. }
  6152. addlabel(importName, "unused", state.tokens.curr);
  6153. if (state.tokens.next.value === ",") {
  6154. advance(",");
  6155. } else if (state.tokens.next.value === "}") {
  6156. advance("}");
  6157. break;
  6158. } else {
  6159. error("E024", state.tokens.next, state.tokens.next.value);
  6160. break;
  6161. }
  6162. }
  6163. }
  6164. advance("from");
  6165. advance("(string)");
  6166. return this;
  6167. }).exps = true;
  6168. stmt("export", function () {
  6169. if (!state.option.inESNext()) {
  6170. warning("W119", state.tokens.curr, "export");
  6171. }
  6172. if (state.tokens.next.type === "default") {
  6173. advance("default");
  6174. if (state.tokens.next.id === "function" || state.tokens.next.id === "class") {
  6175. this.block = true;
  6176. }
  6177. this.exportee = expression(10);
  6178. return this;
  6179. }
  6180. if (state.tokens.next.value === "{") {
  6181. advance("{");
  6182. for (;;) {
  6183. identifier();
  6184. if (state.tokens.next.value === ",") {
  6185. advance(",");
  6186. } else if (state.tokens.next.value === "}") {
  6187. advance("}");
  6188. break;
  6189. } else {
  6190. error("E024", state.tokens.next, state.tokens.next.value);
  6191. break;
  6192. }
  6193. }
  6194. return this;
  6195. }
  6196. if (state.tokens.next.id === "var") {
  6197. advance("var");
  6198. state.syntax["var"].fud.call(state.syntax["var"].fud);
  6199. } else if (state.tokens.next.id === "let") {
  6200. advance("let");
  6201. state.syntax["let"].fud.call(state.syntax["let"].fud);
  6202. } else if (state.tokens.next.id === "const") {
  6203. advance("const");
  6204. state.syntax["const"].fud.call(state.syntax["const"].fud);
  6205. } else if (state.tokens.next.id === "function") {
  6206. this.block = true;
  6207. advance("function");
  6208. state.syntax["function"].fud();
  6209. } else if (state.tokens.next.id === "class") {
  6210. this.block = true;
  6211. advance("class");
  6212. state.syntax["class"].fud();
  6213. } else {
  6214. error("E024", state.tokens.next, state.tokens.next.value);
  6215. }
  6216. return this;
  6217. }).exps = true;
  6218. // Future Reserved Words
  6219. FutureReservedWord("abstract");
  6220. FutureReservedWord("boolean");
  6221. FutureReservedWord("byte");
  6222. FutureReservedWord("char");
  6223. FutureReservedWord("class", { es5: true, nud: classdef });
  6224. FutureReservedWord("double");
  6225. FutureReservedWord("enum", { es5: true });
  6226. FutureReservedWord("export", { es5: true });
  6227. FutureReservedWord("extends", { es5: true });
  6228. FutureReservedWord("final");
  6229. FutureReservedWord("float");
  6230. FutureReservedWord("goto");
  6231. FutureReservedWord("implements", { es5: true, strictOnly: true });
  6232. FutureReservedWord("import", { es5: true });
  6233. FutureReservedWord("int");
  6234. FutureReservedWord("interface", { es5: true, strictOnly: true });
  6235. FutureReservedWord("long");
  6236. FutureReservedWord("native");
  6237. FutureReservedWord("package", { es5: true, strictOnly: true });
  6238. FutureReservedWord("private", { es5: true, strictOnly: true });
  6239. FutureReservedWord("protected", { es5: true, strictOnly: true });
  6240. FutureReservedWord("public", { es5: true, strictOnly: true });
  6241. FutureReservedWord("short");
  6242. FutureReservedWord("static", { es5: true, strictOnly: true });
  6243. FutureReservedWord("super", { es5: true });
  6244. FutureReservedWord("synchronized");
  6245. FutureReservedWord("throws");
  6246. FutureReservedWord("transient");
  6247. FutureReservedWord("volatile");
  6248. // this function is used to determine wether a squarebracket or a curlybracket
  6249. // expression is a comprehension array, destructuring assignment or a json value.
  6250. var lookupBlockType = function () {
  6251. var pn, pn1;
  6252. var i = -1;
  6253. var bracketStack = 0;
  6254. var ret = {};
  6255. if (_.contains(["[", "{"], state.tokens.curr.value))
  6256. bracketStack += 1;
  6257. do {
  6258. pn = (i === -1) ? state.tokens.next : peek(i);
  6259. pn1 = peek(i + 1);
  6260. i = i + 1;
  6261. if (_.contains(["[", "{"], pn.value)) {
  6262. bracketStack += 1;
  6263. } else if (_.contains(["]", "}"], pn.value)) {
  6264. bracketStack -= 1;
  6265. }
  6266. if (pn.identifier && pn.value === "for" && bracketStack === 1) {
  6267. ret.isCompArray = true;
  6268. ret.notJson = true;
  6269. break;
  6270. }
  6271. if (_.contains(["}", "]"], pn.value) && pn1.value === "=" && bracketStack === 0) {
  6272. ret.isDestAssign = true;
  6273. ret.notJson = true;
  6274. break;
  6275. }
  6276. if (pn.value === ";") {
  6277. ret.isBlock = true;
  6278. ret.notJson = true;
  6279. }
  6280. } while (bracketStack > 0 && pn.id !== "(end)" && i < 15);
  6281. return ret;
  6282. };
  6283. // Check whether this function has been reached for a destructuring assign with undeclared values
  6284. function destructuringAssignOrJsonValue() {
  6285. // lookup for the assignment (esnext only)
  6286. // if it has semicolons, it is a block, so go parse it as a block
  6287. // or it's not a block, but there are assignments, check for undeclared variables
  6288. var block = lookupBlockType();
  6289. if (block.notJson) {
  6290. if (!state.option.inESNext() && block.isDestAssign) {
  6291. warning("W104", state.tokens.curr, "destructuring assignment");
  6292. }
  6293. statements();
  6294. // otherwise parse json value
  6295. } else {
  6296. state.option.laxbreak = true;
  6297. state.jsonMode = true;
  6298. jsonValue();
  6299. }
  6300. }
  6301. // array comprehension parsing function
  6302. // parses and defines the three states of the list comprehension in order
  6303. // to avoid defining global variables, but keeping them to the list comprehension scope
  6304. // only. The order of the states are as follows:
  6305. // * "use" which will be the returned iterative part of the list comprehension
  6306. // * "define" which will define the variables local to the list comprehension
  6307. // * "filter" which will help filter out values
  6308. var arrayComprehension = function () {
  6309. var CompArray = function () {
  6310. this.mode = "use";
  6311. this.variables = [];
  6312. };
  6313. var _carrays = [];
  6314. var _current;
  6315. function declare(v) {
  6316. var l = _current.variables.filter(function (elt) {
  6317. // if it has, change its undef state
  6318. if (elt.value === v) {
  6319. elt.undef = false;
  6320. return v;
  6321. }
  6322. }).length;
  6323. return l !== 0;
  6324. }
  6325. function use(v) {
  6326. var l = _current.variables.filter(function (elt) {
  6327. // and if it has been defined
  6328. if (elt.value === v && !elt.undef) {
  6329. if (elt.unused === true) {
  6330. elt.unused = false;
  6331. }
  6332. return v;
  6333. }
  6334. }).length;
  6335. // otherwise we warn about it
  6336. return (l === 0);
  6337. }
  6338. return {stack: function () {
  6339. _current = new CompArray();
  6340. _carrays.push(_current);
  6341. },
  6342. unstack: function () {
  6343. _current.variables.filter(function (v) {
  6344. if (v.unused)
  6345. warning("W098", v.token, v.value);
  6346. if (v.undef)
  6347. isundef(v.funct, "W117", v.token, v.value);
  6348. });
  6349. _carrays.splice(-1, 1);
  6350. _current = _carrays[_carrays.length - 1];
  6351. },
  6352. setState: function (s) {
  6353. if (_.contains(["use", "define", "generate", "filter"], s))
  6354. _current.mode = s;
  6355. },
  6356. check: function (v) {
  6357. if (!_current) {
  6358. return;
  6359. }
  6360. // When we are in "use" state of the list comp, we enqueue that var
  6361. if (_current && _current.mode === "use") {
  6362. if (use(v)) {
  6363. _current.variables.push({
  6364. funct: funct,
  6365. token: state.tokens.curr,
  6366. value: v,
  6367. undef: true,
  6368. unused: false
  6369. });
  6370. }
  6371. return true;
  6372. // When we are in "define" state of the list comp,
  6373. } else if (_current && _current.mode === "define") {
  6374. // check if the variable has been used previously
  6375. if (!declare(v)) {
  6376. _current.variables.push({
  6377. funct: funct,
  6378. token: state.tokens.curr,
  6379. value: v,
  6380. undef: false,
  6381. unused: true
  6382. });
  6383. }
  6384. return true;
  6385. // When we are in the "generate" state of the list comp,
  6386. } else if (_current && _current.mode === "generate") {
  6387. isundef(funct, "W117", state.tokens.curr, v);
  6388. return true;
  6389. // When we are in "filter" state,
  6390. } else if (_current && _current.mode === "filter") {
  6391. // we check whether current variable has been declared
  6392. if (use(v)) {
  6393. // if not we warn about it
  6394. isundef(funct, "W117", state.tokens.curr, v);
  6395. }
  6396. return true;
  6397. }
  6398. return false;
  6399. }
  6400. };
  6401. };
  6402. // Parse JSON
  6403. function jsonValue() {
  6404. function jsonObject() {
  6405. var o = {}, t = state.tokens.next;
  6406. advance("{");
  6407. if (state.tokens.next.id !== "}") {
  6408. for (;;) {
  6409. if (state.tokens.next.id === "(end)") {
  6410. error("E026", state.tokens.next, t.line);
  6411. } else if (state.tokens.next.id === "}") {
  6412. warning("W094", state.tokens.curr);
  6413. break;
  6414. } else if (state.tokens.next.id === ",") {
  6415. error("E028", state.tokens.next);
  6416. } else if (state.tokens.next.id !== "(string)") {
  6417. warning("W095", state.tokens.next, state.tokens.next.value);
  6418. }
  6419. if (o[state.tokens.next.value] === true) {
  6420. warning("W075", state.tokens.next, state.tokens.next.value);
  6421. } else if ((state.tokens.next.value === "__proto__" &&
  6422. !state.option.proto) || (state.tokens.next.value === "__iterator__" &&
  6423. !state.option.iterator)) {
  6424. warning("W096", state.tokens.next, state.tokens.next.value);
  6425. } else {
  6426. o[state.tokens.next.value] = true;
  6427. }
  6428. advance();
  6429. advance(":");
  6430. jsonValue();
  6431. if (state.tokens.next.id !== ",") {
  6432. break;
  6433. }
  6434. advance(",");
  6435. }
  6436. }
  6437. advance("}");
  6438. }
  6439. function jsonArray() {
  6440. var t = state.tokens.next;
  6441. advance("[");
  6442. if (state.tokens.next.id !== "]") {
  6443. for (;;) {
  6444. if (state.tokens.next.id === "(end)") {
  6445. error("E027", state.tokens.next, t.line);
  6446. } else if (state.tokens.next.id === "]") {
  6447. warning("W094", state.tokens.curr);
  6448. break;
  6449. } else if (state.tokens.next.id === ",") {
  6450. error("E028", state.tokens.next);
  6451. }
  6452. jsonValue();
  6453. if (state.tokens.next.id !== ",") {
  6454. break;
  6455. }
  6456. advance(",");
  6457. }
  6458. }
  6459. advance("]");
  6460. }
  6461. switch (state.tokens.next.id) {
  6462. case "{":
  6463. jsonObject();
  6464. break;
  6465. case "[":
  6466. jsonArray();
  6467. break;
  6468. case "true":
  6469. case "false":
  6470. case "null":
  6471. case "(number)":
  6472. case "(string)":
  6473. advance();
  6474. break;
  6475. case "-":
  6476. advance("-");
  6477. if (state.tokens.curr.character !== state.tokens.next.from) {
  6478. warning("W011", state.tokens.curr);
  6479. }
  6480. adjacent(state.tokens.curr, state.tokens.next);
  6481. advance("(number)");
  6482. break;
  6483. default:
  6484. error("E003", state.tokens.next);
  6485. }
  6486. }
  6487. var blockScope = function () {
  6488. var _current = {};
  6489. var _variables = [_current];
  6490. function _checkBlockLabels() {
  6491. for (var t in _current) {
  6492. if (_current[t]["(type)"] === "unused") {
  6493. if (state.option.unused) {
  6494. var tkn = _current[t]["(token)"];
  6495. var line = tkn.line;
  6496. var chr = tkn.character;
  6497. warningAt("W098", line, chr, t);
  6498. }
  6499. }
  6500. }
  6501. }
  6502. return {
  6503. stack: function () {
  6504. _current = {};
  6505. _variables.push(_current);
  6506. },
  6507. unstack: function () {
  6508. _checkBlockLabels();
  6509. _variables.splice(_variables.length - 1, 1);
  6510. _current = _.last(_variables);
  6511. },
  6512. getlabel: function (l) {
  6513. for (var i = _variables.length - 1 ; i >= 0; --i) {
  6514. if (_.has(_variables[i], l)) {
  6515. return _variables[i];
  6516. }
  6517. }
  6518. },
  6519. current: {
  6520. has: function (t) {
  6521. return _.has(_current, t);
  6522. },
  6523. add: function (t, type, tok) {
  6524. _current[t] = { "(type)" : type,
  6525. "(token)": tok };
  6526. }
  6527. }
  6528. };
  6529. };
  6530. // The actual JSHINT function itself.
  6531. var itself = function (s, o, g) {
  6532. var i, k, x;
  6533. var optionKeys;
  6534. var newOptionObj = {};
  6535. var newIgnoredObj = {};
  6536. state.reset();
  6537. if (o && o.scope) {
  6538. JSHINT.scope = o.scope;
  6539. } else {
  6540. JSHINT.errors = [];
  6541. JSHINT.undefs = [];
  6542. JSHINT.internals = [];
  6543. JSHINT.blacklist = {};
  6544. JSHINT.scope = "(main)";
  6545. }
  6546. predefined = Object.create(null);
  6547. combine(predefined, vars.ecmaIdentifiers);
  6548. combine(predefined, vars.reservedVars);
  6549. combine(predefined, g || {});
  6550. declared = Object.create(null);
  6551. exported = Object.create(null);
  6552. function each(obj, cb) {
  6553. if (!obj)
  6554. return;
  6555. if (!Array.isArray(obj) && typeof obj === "object")
  6556. obj = Object.keys(obj);
  6557. obj.forEach(cb);
  6558. }
  6559. if (o) {
  6560. each(o.predef || null, function (item) {
  6561. var slice, prop;
  6562. if (item[0] === "-") {
  6563. slice = item.slice(1);
  6564. JSHINT.blacklist[slice] = slice;
  6565. } else {
  6566. prop = Object.getOwnPropertyDescriptor(o.predef, item);
  6567. predefined[item] = prop ? prop.value : false;
  6568. }
  6569. });
  6570. each(o.exported || null, function (item) {
  6571. exported[item] = true;
  6572. });
  6573. delete o.predef;
  6574. delete o.exported;
  6575. optionKeys = Object.keys(o);
  6576. for (x = 0; x < optionKeys.length; x++) {
  6577. if (/^-W\d{3}$/g.test(optionKeys[x])) {
  6578. newIgnoredObj[optionKeys[x].slice(1)] = true;
  6579. } else {
  6580. newOptionObj[optionKeys[x]] = o[optionKeys[x]];
  6581. if (optionKeys[x] === "newcap" && o[optionKeys[x]] === false)
  6582. newOptionObj["(explicitNewcap)"] = true;
  6583. if (optionKeys[x] === "indent")
  6584. newOptionObj["(explicitIndent)"] = o[optionKeys[x]] === false ? false : true;
  6585. }
  6586. }
  6587. }
  6588. state.option = newOptionObj;
  6589. state.ignored = newIgnoredObj;
  6590. state.option.indent = state.option.indent || 4;
  6591. state.option.maxerr = state.option.maxerr || 50;
  6592. indent = 1;
  6593. global = Object.create(predefined);
  6594. scope = global;
  6595. funct = {
  6596. "(global)": true,
  6597. "(name)": "(global)",
  6598. "(scope)": scope,
  6599. "(breakage)": 0,
  6600. "(loopage)": 0,
  6601. "(tokens)": {},
  6602. "(metrics)": createMetrics(state.tokens.next),
  6603. "(blockscope)": blockScope(),
  6604. "(comparray)": arrayComprehension()
  6605. };
  6606. functions = [funct];
  6607. urls = [];
  6608. stack = null;
  6609. member = {};
  6610. membersOnly = null;
  6611. implied = {};
  6612. inblock = false;
  6613. lookahead = [];
  6614. warnings = 0;
  6615. unuseds = [];
  6616. if (!isString(s) && !Array.isArray(s)) {
  6617. errorAt("E004", 0);
  6618. return false;
  6619. }
  6620. api = {
  6621. get isJSON() {
  6622. return state.jsonMode;
  6623. },
  6624. getOption: function (name) {
  6625. return state.option[name] || null;
  6626. },
  6627. getCache: function (name) {
  6628. return state.cache[name];
  6629. },
  6630. setCache: function (name, value) {
  6631. state.cache[name] = value;
  6632. },
  6633. warn: function (code, data) {
  6634. warningAt.apply(null, [ code, data.line, data.char ].concat(data.data));
  6635. },
  6636. on: function (names, listener) {
  6637. names.split(" ").forEach(function (name) {
  6638. emitter.on(name, listener);
  6639. }.bind(this));
  6640. }
  6641. };
  6642. emitter.removeAllListeners();
  6643. (extraModules || []).forEach(function (func) {
  6644. func(api);
  6645. });
  6646. state.tokens.prev = state.tokens.curr = state.tokens.next = state.syntax["(begin)"];
  6647. lex = new Lexer(s);
  6648. lex.on("warning", function (ev) {
  6649. warningAt.apply(null, [ ev.code, ev.line, ev.character].concat(ev.data));
  6650. });
  6651. lex.on("error", function (ev) {
  6652. errorAt.apply(null, [ ev.code, ev.line, ev.character ].concat(ev.data));
  6653. });
  6654. lex.on("fatal", function (ev) {
  6655. quit("E041", ev.line, ev.from);
  6656. });
  6657. lex.on("Identifier", function (ev) {
  6658. emitter.emit("Identifier", ev);
  6659. });
  6660. lex.on("String", function (ev) {
  6661. emitter.emit("String", ev);
  6662. });
  6663. lex.on("Number", function (ev) {
  6664. emitter.emit("Number", ev);
  6665. });
  6666. lex.start();
  6667. // Check options
  6668. for (var name in o) {
  6669. if (_.has(o, name)) {
  6670. checkOption(name, state.tokens.curr);
  6671. }
  6672. }
  6673. assume();
  6674. // combine the passed globals after we've assumed all our options
  6675. combine(predefined, g || {});
  6676. //reset values
  6677. comma.first = true;
  6678. try {
  6679. advance();
  6680. switch (state.tokens.next.id) {
  6681. case "{":
  6682. case "[":
  6683. destructuringAssignOrJsonValue();
  6684. break;
  6685. default:
  6686. directives();
  6687. if (state.directive["use strict"]) {
  6688. if (!state.option.globalstrict && !(state.option.node || state.option.phantom)) {
  6689. warning("W097", state.tokens.prev);
  6690. }
  6691. }
  6692. statements();
  6693. }
  6694. advance((state.tokens.next && state.tokens.next.value !== ".") ? "(end)" : undefined);
  6695. funct["(blockscope)"].unstack();
  6696. var markDefined = function (name, context) {
  6697. do {
  6698. if (typeof context[name] === "string") {
  6699. // JSHINT marks unused variables as 'unused' and
  6700. // unused function declaration as 'unction'. This
  6701. // code changes such instances back 'var' and
  6702. // 'closure' so that the code in JSHINT.data()
  6703. // doesn't think they're unused.
  6704. if (context[name] === "unused")
  6705. context[name] = "var";
  6706. else if (context[name] === "unction")
  6707. context[name] = "closure";
  6708. return true;
  6709. }
  6710. context = context["(context)"];
  6711. } while (context);
  6712. return false;
  6713. };
  6714. var clearImplied = function (name, line) {
  6715. if (!implied[name])
  6716. return;
  6717. var newImplied = [];
  6718. for (var i = 0; i < implied[name].length; i += 1) {
  6719. if (implied[name][i] !== line)
  6720. newImplied.push(implied[name][i]);
  6721. }
  6722. if (newImplied.length === 0)
  6723. delete implied[name];
  6724. else
  6725. implied[name] = newImplied;
  6726. };
  6727. var warnUnused = function (name, tkn, type, unused_opt) {
  6728. var line = tkn.line;
  6729. var chr = tkn.character;
  6730. if (unused_opt === undefined) {
  6731. unused_opt = state.option.unused;
  6732. }
  6733. if (unused_opt === true) {
  6734. unused_opt = "last-param";
  6735. }
  6736. var warnable_types = {
  6737. "vars": ["var"],
  6738. "last-param": ["var", "param"],
  6739. "strict": ["var", "param", "last-param"]
  6740. };
  6741. if (unused_opt) {
  6742. if (warnable_types[unused_opt] && warnable_types[unused_opt].indexOf(type) !== -1) {
  6743. warningAt("W098", line, chr, name);
  6744. }
  6745. }
  6746. unuseds.push({
  6747. name: name,
  6748. line: line,
  6749. character: chr
  6750. });
  6751. };
  6752. var checkUnused = function (func, key) {
  6753. var type = func[key];
  6754. var tkn = func["(tokens)"][key];
  6755. if (key.charAt(0) === "(")
  6756. return;
  6757. if (type !== "unused" && type !== "unction")
  6758. return;
  6759. // Params are checked separately from other variables.
  6760. if (func["(params)"] && func["(params)"].indexOf(key) !== -1)
  6761. return;
  6762. // Variable is in global scope and defined as exported.
  6763. if (func["(global)"] && _.has(exported, key)) {
  6764. return;
  6765. }
  6766. warnUnused(key, tkn, "var");
  6767. };
  6768. // Check queued 'x is not defined' instances to see if they're still undefined.
  6769. for (i = 0; i < JSHINT.undefs.length; i += 1) {
  6770. k = JSHINT.undefs[i].slice(0);
  6771. if (markDefined(k[2].value, k[0])) {
  6772. clearImplied(k[2].value, k[2].line);
  6773. } else if (state.option.undef) {
  6774. warning.apply(warning, k.slice(1));
  6775. }
  6776. }
  6777. functions.forEach(function (func) {
  6778. if (func["(unusedOption)"] === false) {
  6779. return;
  6780. }
  6781. for (var key in func) {
  6782. if (_.has(func, key)) {
  6783. checkUnused(func, key);
  6784. }
  6785. }
  6786. if (!func["(params)"])
  6787. return;
  6788. var params = func["(params)"].slice();
  6789. var param = params.pop();
  6790. var type, unused_opt;
  6791. while (param) {
  6792. type = func[param];
  6793. unused_opt = func["(unusedOption)"] || state.option.unused;
  6794. unused_opt = unused_opt === true ? "last-param" : unused_opt;
  6795. // 'undefined' is a special case for (function (window, undefined) { ... })();
  6796. // patterns.
  6797. if (param === "undefined")
  6798. return;
  6799. if (type === "unused" || type === "unction") {
  6800. warnUnused(param, func["(tokens)"][param], "param", func["(unusedOption)"]);
  6801. } else if (unused_opt === "last-param") {
  6802. return;
  6803. }
  6804. param = params.pop();
  6805. }
  6806. });
  6807. for (var key in declared) {
  6808. if (_.has(declared, key) && !_.has(global, key)) {
  6809. warnUnused(key, declared[key], "var");
  6810. }
  6811. }
  6812. } catch (err) {
  6813. if (err && err.name === "JSHintError") {
  6814. var nt = state.tokens.next || {};
  6815. JSHINT.errors.push({
  6816. scope : "(main)",
  6817. raw : err.raw,
  6818. code : err.code,
  6819. reason : err.message,
  6820. line : err.line || nt.line,
  6821. character : err.character || nt.from
  6822. }, null);
  6823. } else {
  6824. throw err;
  6825. }
  6826. }
  6827. // Loop over the listed "internals", and check them as well.
  6828. if (JSHINT.scope === "(main)") {
  6829. o = o || {};
  6830. for (i = 0; i < JSHINT.internals.length; i += 1) {
  6831. k = JSHINT.internals[i];
  6832. o.scope = k.elem;
  6833. itself(k.value, o, g);
  6834. }
  6835. }
  6836. return JSHINT.errors.length === 0;
  6837. };
  6838. // Modules.
  6839. itself.addModule = function (func) {
  6840. extraModules.push(func);
  6841. };
  6842. itself.addModule(style.register);
  6843. // Data summary.
  6844. itself.data = function () {
  6845. var data = {
  6846. functions: [],
  6847. options: state.option
  6848. };
  6849. var implieds = [];
  6850. var members = [];
  6851. var fu, f, i, j, n, globals;
  6852. if (itself.errors.length) {
  6853. data.errors = itself.errors;
  6854. }
  6855. if (state.jsonMode) {
  6856. data.json = true;
  6857. }
  6858. for (n in implied) {
  6859. if (_.has(implied, n)) {
  6860. implieds.push({
  6861. name: n,
  6862. line: implied[n]
  6863. });
  6864. }
  6865. }
  6866. if (implieds.length > 0) {
  6867. data.implieds = implieds;
  6868. }
  6869. if (urls.length > 0) {
  6870. data.urls = urls;
  6871. }
  6872. globals = Object.keys(scope);
  6873. if (globals.length > 0) {
  6874. data.globals = globals;
  6875. }
  6876. for (i = 1; i < functions.length; i += 1) {
  6877. f = functions[i];
  6878. fu = {};
  6879. for (j = 0; j < functionicity.length; j += 1) {
  6880. fu[functionicity[j]] = [];
  6881. }
  6882. for (j = 0; j < functionicity.length; j += 1) {
  6883. if (fu[functionicity[j]].length === 0) {
  6884. delete fu[functionicity[j]];
  6885. }
  6886. }
  6887. fu.name = f["(name)"];
  6888. fu.param = f["(params)"];
  6889. fu.line = f["(line)"];
  6890. fu.character = f["(character)"];
  6891. fu.last = f["(last)"];
  6892. fu.lastcharacter = f["(lastcharacter)"];
  6893. data.functions.push(fu);
  6894. }
  6895. if (unuseds.length > 0) {
  6896. data.unused = unuseds;
  6897. }
  6898. members = [];
  6899. for (n in member) {
  6900. if (typeof member[n] === "number") {
  6901. data.member = member;
  6902. break;
  6903. }
  6904. }
  6905. return data;
  6906. };
  6907. itself.jshint = itself;
  6908. return itself;
  6909. }());
  6910. // Make JSHINT a Node module, if possible.
  6911. if (typeof exports === "object" && exports) {
  6912. exports.JSHINT = JSHINT;
  6913. }
  6914. })()
  6915. },{"events":2,"./vars.js":3,"./messages.js":7,"./lex.js":9,"./reg.js":4,"./state.js":5,"./style.js":6,"console-browserify":10,"underscore":8}],8:[function(require,module,exports){
  6916. (function(){// Underscore.js 1.4.4
  6917. // http://underscorejs.org
  6918. // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
  6919. // Underscore may be freely distributed under the MIT license.
  6920. (function() {
  6921. // Baseline setup
  6922. // --------------
  6923. // Establish the root object, `window` in the browser, or `global` on the server.
  6924. var root = this;
  6925. // Save the previous value of the `_` variable.
  6926. var previousUnderscore = root._;
  6927. // Establish the object that gets returned to break out of a loop iteration.
  6928. var breaker = {};
  6929. // Save bytes in the minified (but not gzipped) version:
  6930. var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
  6931. // Create quick reference variables for speed access to core prototypes.
  6932. var push = ArrayProto.push,
  6933. slice = ArrayProto.slice,
  6934. concat = ArrayProto.concat,
  6935. toString = ObjProto.toString,
  6936. hasOwnProperty = ObjProto.hasOwnProperty;
  6937. // All **ECMAScript 5** native function implementations that we hope to use
  6938. // are declared here.
  6939. var
  6940. nativeForEach = ArrayProto.forEach,
  6941. nativeMap = ArrayProto.map,
  6942. nativeReduce = ArrayProto.reduce,
  6943. nativeReduceRight = ArrayProto.reduceRight,
  6944. nativeFilter = ArrayProto.filter,
  6945. nativeEvery = ArrayProto.every,
  6946. nativeSome = ArrayProto.some,
  6947. nativeIndexOf = ArrayProto.indexOf,
  6948. nativeLastIndexOf = ArrayProto.lastIndexOf,
  6949. nativeIsArray = Array.isArray,
  6950. nativeKeys = Object.keys,
  6951. nativeBind = FuncProto.bind;
  6952. // Create a safe reference to the Underscore object for use below.
  6953. var _ = function(obj) {
  6954. if (obj instanceof _) return obj;
  6955. if (!(this instanceof _)) return new _(obj);
  6956. this._wrapped = obj;
  6957. };
  6958. // Export the Underscore object for **Node.js**, with
  6959. // backwards-compatibility for the old `require()` API. If we're in
  6960. // the browser, add `_` as a global object via a string identifier,
  6961. // for Closure Compiler "advanced" mode.
  6962. if (typeof exports !== 'undefined') {
  6963. if (typeof module !== 'undefined' && module.exports) {
  6964. exports = module.exports = _;
  6965. }
  6966. exports._ = _;
  6967. } else {
  6968. root._ = _;
  6969. }
  6970. // Current version.
  6971. _.VERSION = '1.4.4';
  6972. // Collection Functions
  6973. // --------------------
  6974. // The cornerstone, an `each` implementation, aka `forEach`.
  6975. // Handles objects with the built-in `forEach`, arrays, and raw objects.
  6976. // Delegates to **ECMAScript 5**'s native `forEach` if available.
  6977. var each = _.each = _.forEach = function(obj, iterator, context) {
  6978. if (obj == null) return;
  6979. if (nativeForEach && obj.forEach === nativeForEach) {
  6980. obj.forEach(iterator, context);
  6981. } else if (obj.length === +obj.length) {
  6982. for (var i = 0, l = obj.length; i < l; i++) {
  6983. if (iterator.call(context, obj[i], i, obj) === breaker) return;
  6984. }
  6985. } else {
  6986. for (var key in obj) {
  6987. if (_.has(obj, key)) {
  6988. if (iterator.call(context, obj[key], key, obj) === breaker) return;
  6989. }
  6990. }
  6991. }
  6992. };
  6993. // Return the results of applying the iterator to each element.
  6994. // Delegates to **ECMAScript 5**'s native `map` if available.
  6995. _.map = _.collect = function(obj, iterator, context) {
  6996. var results = [];
  6997. if (obj == null) return results;
  6998. if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
  6999. each(obj, function(value, index, list) {
  7000. results[results.length] = iterator.call(context, value, index, list);
  7001. });
  7002. return results;
  7003. };
  7004. var reduceError = 'Reduce of empty array with no initial value';
  7005. // **Reduce** builds up a single result from a list of values, aka `inject`,
  7006. // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
  7007. _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
  7008. var initial = arguments.length > 2;
  7009. if (obj == null) obj = [];
  7010. if (nativeReduce && obj.reduce === nativeReduce) {
  7011. if (context) iterator = _.bind(iterator, context);
  7012. return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
  7013. }
  7014. each(obj, function(value, index, list) {
  7015. if (!initial) {
  7016. memo = value;
  7017. initial = true;
  7018. } else {
  7019. memo = iterator.call(context, memo, value, index, list);
  7020. }
  7021. });
  7022. if (!initial) throw new TypeError(reduceError);
  7023. return memo;
  7024. };
  7025. // The right-associative version of reduce, also known as `foldr`.
  7026. // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
  7027. _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
  7028. var initial = arguments.length > 2;
  7029. if (obj == null) obj = [];
  7030. if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
  7031. if (context) iterator = _.bind(iterator, context);
  7032. return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
  7033. }
  7034. var length = obj.length;
  7035. if (length !== +length) {
  7036. var keys = _.keys(obj);
  7037. length = keys.length;
  7038. }
  7039. each(obj, function(value, index, list) {
  7040. index = keys ? keys[--length] : --length;
  7041. if (!initial) {
  7042. memo = obj[index];
  7043. initial = true;
  7044. } else {
  7045. memo = iterator.call(context, memo, obj[index], index, list);
  7046. }
  7047. });
  7048. if (!initial) throw new TypeError(reduceError);
  7049. return memo;
  7050. };
  7051. // Return the first value which passes a truth test. Aliased as `detect`.
  7052. _.find = _.detect = function(obj, iterator, context) {
  7053. var result;
  7054. any(obj, function(value, index, list) {
  7055. if (iterator.call(context, value, index, list)) {
  7056. result = value;
  7057. return true;
  7058. }
  7059. });
  7060. return result;
  7061. };
  7062. // Return all the elements that pass a truth test.
  7063. // Delegates to **ECMAScript 5**'s native `filter` if available.
  7064. // Aliased as `select`.
  7065. _.filter = _.select = function(obj, iterator, context) {
  7066. var results = [];
  7067. if (obj == null) return results;
  7068. if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
  7069. each(obj, function(value, index, list) {
  7070. if (iterator.call(context, value, index, list)) results[results.length] = value;
  7071. });
  7072. return results;
  7073. };
  7074. // Return all the elements for which a truth test fails.
  7075. _.reject = function(obj, iterator, context) {
  7076. return _.filter(obj, function(value, index, list) {
  7077. return !iterator.call(context, value, index, list);
  7078. }, context);
  7079. };
  7080. // Determine whether all of the elements match a truth test.
  7081. // Delegates to **ECMAScript 5**'s native `every` if available.
  7082. // Aliased as `all`.
  7083. _.every = _.all = function(obj, iterator, context) {
  7084. iterator || (iterator = _.identity);
  7085. var result = true;
  7086. if (obj == null) return result;
  7087. if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
  7088. each(obj, function(value, index, list) {
  7089. if (!(result = result && iterator.call(context, value, index, list))) return breaker;
  7090. });
  7091. return !!result;
  7092. };
  7093. // Determine if at least one element in the object matches a truth test.
  7094. // Delegates to **ECMAScript 5**'s native `some` if available.
  7095. // Aliased as `any`.
  7096. var any = _.some = _.any = function(obj, iterator, context) {
  7097. iterator || (iterator = _.identity);
  7098. var result = false;
  7099. if (obj == null) return result;
  7100. if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
  7101. each(obj, function(value, index, list) {
  7102. if (result || (result = iterator.call(context, value, index, list))) return breaker;
  7103. });
  7104. return !!result;
  7105. };
  7106. // Determine if the array or object contains a given value (using `===`).
  7107. // Aliased as `include`.
  7108. _.contains = _.include = function(obj, target) {
  7109. if (obj == null) return false;
  7110. if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
  7111. return any(obj, function(value) {
  7112. return value === target;
  7113. });
  7114. };
  7115. // Invoke a method (with arguments) on every item in a collection.
  7116. _.invoke = function(obj, method) {
  7117. var args = slice.call(arguments, 2);
  7118. var isFunc = _.isFunction(method);
  7119. return _.map(obj, function(value) {
  7120. return (isFunc ? method : value[method]).apply(value, args);
  7121. });
  7122. };
  7123. // Convenience version of a common use case of `map`: fetching a property.
  7124. _.pluck = function(obj, key) {
  7125. return _.map(obj, function(value){ return value[key]; });
  7126. };
  7127. // Convenience version of a common use case of `filter`: selecting only objects
  7128. // containing specific `key:value` pairs.
  7129. _.where = function(obj, attrs, first) {
  7130. if (_.isEmpty(attrs)) return first ? null : [];
  7131. return _[first ? 'find' : 'filter'](obj, function(value) {
  7132. for (var key in attrs) {
  7133. if (attrs[key] !== value[key]) return false;
  7134. }
  7135. return true;
  7136. });
  7137. };
  7138. // Convenience version of a common use case of `find`: getting the first object
  7139. // containing specific `key:value` pairs.
  7140. _.findWhere = function(obj, attrs) {
  7141. return _.where(obj, attrs, true);
  7142. };
  7143. // Return the maximum element or (element-based computation).
  7144. // Can't optimize arrays of integers longer than 65,535 elements.
  7145. // See: https://bugs.webkit.org/show_bug.cgi?id=80797
  7146. _.max = function(obj, iterator, context) {
  7147. if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
  7148. return Math.max.apply(Math, obj);
  7149. }
  7150. if (!iterator && _.isEmpty(obj)) return -Infinity;
  7151. var result = {computed : -Infinity, value: -Infinity};
  7152. each(obj, function(value, index, list) {
  7153. var computed = iterator ? iterator.call(context, value, index, list) : value;
  7154. computed >= result.computed && (result = {value : value, computed : computed});
  7155. });
  7156. return result.value;
  7157. };
  7158. // Return the minimum element (or element-based computation).
  7159. _.min = function(obj, iterator, context) {
  7160. if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
  7161. return Math.min.apply(Math, obj);
  7162. }
  7163. if (!iterator && _.isEmpty(obj)) return Infinity;
  7164. var result = {computed : Infinity, value: Infinity};
  7165. each(obj, function(value, index, list) {
  7166. var computed = iterator ? iterator.call(context, value, index, list) : value;
  7167. computed < result.computed && (result = {value : value, computed : computed});
  7168. });
  7169. return result.value;
  7170. };
  7171. // Shuffle an array.
  7172. _.shuffle = function(obj) {
  7173. var rand;
  7174. var index = 0;
  7175. var shuffled = [];
  7176. each(obj, function(value) {
  7177. rand = _.random(index++);
  7178. shuffled[index - 1] = shuffled[rand];
  7179. shuffled[rand] = value;
  7180. });
  7181. return shuffled;
  7182. };
  7183. // An internal function to generate lookup iterators.
  7184. var lookupIterator = function(value) {
  7185. return _.isFunction(value) ? value : function(obj){ return obj[value]; };
  7186. };
  7187. // Sort the object's values by a criterion produced by an iterator.
  7188. _.sortBy = function(obj, value, context) {
  7189. var iterator = lookupIterator(value);
  7190. return _.pluck(_.map(obj, function(value, index, list) {
  7191. return {
  7192. value : value,
  7193. index : index,
  7194. criteria : iterator.call(context, value, index, list)
  7195. };
  7196. }).sort(function(left, right) {
  7197. var a = left.criteria;
  7198. var b = right.criteria;
  7199. if (a !== b) {
  7200. if (a > b || a === void 0) return 1;
  7201. if (a < b || b === void 0) return -1;
  7202. }
  7203. return left.index < right.index ? -1 : 1;
  7204. }), 'value');
  7205. };
  7206. // An internal function used for aggregate "group by" operations.
  7207. var group = function(obj, value, context, behavior) {
  7208. var result = {};
  7209. var iterator = lookupIterator(value || _.identity);
  7210. each(obj, function(value, index) {
  7211. var key = iterator.call(context, value, index, obj);
  7212. behavior(result, key, value);
  7213. });
  7214. return result;
  7215. };
  7216. // Groups the object's values by a criterion. Pass either a string attribute
  7217. // to group by, or a function that returns the criterion.
  7218. _.groupBy = function(obj, value, context) {
  7219. return group(obj, value, context, function(result, key, value) {
  7220. (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
  7221. });
  7222. };
  7223. // Counts instances of an object that group by a certain criterion. Pass
  7224. // either a string attribute to count by, or a function that returns the
  7225. // criterion.
  7226. _.countBy = function(obj, value, context) {
  7227. return group(obj, value, context, function(result, key) {
  7228. if (!_.has(result, key)) result[key] = 0;
  7229. result[key]++;
  7230. });
  7231. };
  7232. // Use a comparator function to figure out the smallest index at which
  7233. // an object should be inserted so as to maintain order. Uses binary search.
  7234. _.sortedIndex = function(array, obj, iterator, context) {
  7235. iterator = iterator == null ? _.identity : lookupIterator(iterator);
  7236. var value = iterator.call(context, obj);
  7237. var low = 0, high = array.length;
  7238. while (low < high) {
  7239. var mid = (low + high) >>> 1;
  7240. iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
  7241. }
  7242. return low;
  7243. };
  7244. // Safely convert anything iterable into a real, live array.
  7245. _.toArray = function(obj) {
  7246. if (!obj) return [];
  7247. if (_.isArray(obj)) return slice.call(obj);
  7248. if (obj.length === +obj.length) return _.map(obj, _.identity);
  7249. return _.values(obj);
  7250. };
  7251. // Return the number of elements in an object.
  7252. _.size = function(obj) {
  7253. if (obj == null) return 0;
  7254. return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
  7255. };
  7256. // Array Functions
  7257. // ---------------
  7258. // Get the first element of an array. Passing **n** will return the first N
  7259. // values in the array. Aliased as `head` and `take`. The **guard** check
  7260. // allows it to work with `_.map`.
  7261. _.first = _.head = _.take = function(array, n, guard) {
  7262. if (array == null) return void 0;
  7263. return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
  7264. };
  7265. // Returns everything but the last entry of the array. Especially useful on
  7266. // the arguments object. Passing **n** will return all the values in
  7267. // the array, excluding the last N. The **guard** check allows it to work with
  7268. // `_.map`.
  7269. _.initial = function(array, n, guard) {
  7270. return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
  7271. };
  7272. // Get the last element of an array. Passing **n** will return the last N
  7273. // values in the array. The **guard** check allows it to work with `_.map`.
  7274. _.last = function(array, n, guard) {
  7275. if (array == null) return void 0;
  7276. if ((n != null) && !guard) {
  7277. return slice.call(array, Math.max(array.length - n, 0));
  7278. } else {
  7279. return array[array.length - 1];
  7280. }
  7281. };
  7282. // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
  7283. // Especially useful on the arguments object. Passing an **n** will return
  7284. // the rest N values in the array. The **guard**
  7285. // check allows it to work with `_.map`.
  7286. _.rest = _.tail = _.drop = function(array, n, guard) {
  7287. return slice.call(array, (n == null) || guard ? 1 : n);
  7288. };
  7289. // Trim out all falsy values from an array.
  7290. _.compact = function(array) {
  7291. return _.filter(array, _.identity);
  7292. };
  7293. // Internal implementation of a recursive `flatten` function.
  7294. var flatten = function(input, shallow, output) {
  7295. each(input, function(value) {
  7296. if (_.isArray(value)) {
  7297. shallow ? push.apply(output, value) : flatten(value, shallow, output);
  7298. } else {
  7299. output.push(value);
  7300. }
  7301. });
  7302. return output;
  7303. };
  7304. // Return a completely flattened version of an array.
  7305. _.flatten = function(array, shallow) {
  7306. return flatten(array, shallow, []);
  7307. };
  7308. // Return a version of the array that does not contain the specified value(s).
  7309. _.without = function(array) {
  7310. return _.difference(array, slice.call(arguments, 1));
  7311. };
  7312. // Produce a duplicate-free version of the array. If the array has already
  7313. // been sorted, you have the option of using a faster algorithm.
  7314. // Aliased as `unique`.
  7315. _.uniq = _.unique = function(array, isSorted, iterator, context) {
  7316. if (_.isFunction(isSorted)) {
  7317. context = iterator;
  7318. iterator = isSorted;
  7319. isSorted = false;
  7320. }
  7321. var initial = iterator ? _.map(array, iterator, context) : array;
  7322. var results = [];
  7323. var seen = [];
  7324. each(initial, function(value, index) {
  7325. if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
  7326. seen.push(value);
  7327. results.push(array[index]);
  7328. }
  7329. });
  7330. return results;
  7331. };
  7332. // Produce an array that contains the union: each distinct element from all of
  7333. // the passed-in arrays.
  7334. _.union = function() {
  7335. return _.uniq(concat.apply(ArrayProto, arguments));
  7336. };
  7337. // Produce an array that contains every item shared between all the
  7338. // passed-in arrays.
  7339. _.intersection = function(array) {
  7340. var rest = slice.call(arguments, 1);
  7341. return _.filter(_.uniq(array), function(item) {
  7342. return _.every(rest, function(other) {
  7343. return _.indexOf(other, item) >= 0;
  7344. });
  7345. });
  7346. };
  7347. // Take the difference between one array and a number of other arrays.
  7348. // Only the elements present in just the first array will remain.
  7349. _.difference = function(array) {
  7350. var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
  7351. return _.filter(array, function(value){ return !_.contains(rest, value); });
  7352. };
  7353. // Zip together multiple lists into a single array -- elements that share
  7354. // an index go together.
  7355. _.zip = function() {
  7356. var args = slice.call(arguments);
  7357. var length = _.max(_.pluck(args, 'length'));
  7358. var results = new Array(length);
  7359. for (var i = 0; i < length; i++) {
  7360. results[i] = _.pluck(args, "" + i);
  7361. }
  7362. return results;
  7363. };
  7364. // Converts lists into objects. Pass either a single array of `[key, value]`
  7365. // pairs, or two parallel arrays of the same length -- one of keys, and one of
  7366. // the corresponding values.
  7367. _.object = function(list, values) {
  7368. if (list == null) return {};
  7369. var result = {};
  7370. for (var i = 0, l = list.length; i < l; i++) {
  7371. if (values) {
  7372. result[list[i]] = values[i];
  7373. } else {
  7374. result[list[i][0]] = list[i][1];
  7375. }
  7376. }
  7377. return result;
  7378. };
  7379. // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
  7380. // we need this function. Return the position of the first occurrence of an
  7381. // item in an array, or -1 if the item is not included in the array.
  7382. // Delegates to **ECMAScript 5**'s native `indexOf` if available.
  7383. // If the array is large and already in sort order, pass `true`
  7384. // for **isSorted** to use binary search.
  7385. _.indexOf = function(array, item, isSorted) {
  7386. if (array == null) return -1;
  7387. var i = 0, l = array.length;
  7388. if (isSorted) {
  7389. if (typeof isSorted == 'number') {
  7390. i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted);
  7391. } else {
  7392. i = _.sortedIndex(array, item);
  7393. return array[i] === item ? i : -1;
  7394. }
  7395. }
  7396. if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
  7397. for (; i < l; i++) if (array[i] === item) return i;
  7398. return -1;
  7399. };
  7400. // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
  7401. _.lastIndexOf = function(array, item, from) {
  7402. if (array == null) return -1;
  7403. var hasIndex = from != null;
  7404. if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
  7405. return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
  7406. }
  7407. var i = (hasIndex ? from : array.length);
  7408. while (i--) if (array[i] === item) return i;
  7409. return -1;
  7410. };
  7411. // Generate an integer Array containing an arithmetic progression. A port of
  7412. // the native Python `range()` function. See
  7413. // [the Python documentation](http://docs.python.org/library/functions.html#range).
  7414. _.range = function(start, stop, step) {
  7415. if (arguments.length <= 1) {
  7416. stop = start || 0;
  7417. start = 0;
  7418. }
  7419. step = arguments[2] || 1;
  7420. var len = Math.max(Math.ceil((stop - start) / step), 0);
  7421. var idx = 0;
  7422. var range = new Array(len);
  7423. while(idx < len) {
  7424. range[idx++] = start;
  7425. start += step;
  7426. }
  7427. return range;
  7428. };
  7429. // Function (ahem) Functions
  7430. // ------------------
  7431. // Create a function bound to a given object (assigning `this`, and arguments,
  7432. // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
  7433. // available.
  7434. _.bind = function(func, context) {
  7435. if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
  7436. var args = slice.call(arguments, 2);
  7437. return function() {
  7438. return func.apply(context, args.concat(slice.call(arguments)));
  7439. };
  7440. };
  7441. // Partially apply a function by creating a version that has had some of its
  7442. // arguments pre-filled, without changing its dynamic `this` context.
  7443. _.partial = function(func) {
  7444. var args = slice.call(arguments, 1);
  7445. return function() {
  7446. return func.apply(this, args.concat(slice.call(arguments)));
  7447. };
  7448. };
  7449. // Bind all of an object's methods to that object. Useful for ensuring that
  7450. // all callbacks defined on an object belong to it.
  7451. _.bindAll = function(obj) {
  7452. var funcs = slice.call(arguments, 1);
  7453. if (funcs.length === 0) funcs = _.functions(obj);
  7454. each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
  7455. return obj;
  7456. };
  7457. // Memoize an expensive function by storing its results.
  7458. _.memoize = function(func, hasher) {
  7459. var memo = {};
  7460. hasher || (hasher = _.identity);
  7461. return function() {
  7462. var key = hasher.apply(this, arguments);
  7463. return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
  7464. };
  7465. };
  7466. // Delays a function for the given number of milliseconds, and then calls
  7467. // it with the arguments supplied.
  7468. _.delay = function(func, wait) {
  7469. var args = slice.call(arguments, 2);
  7470. return setTimeout(function(){ return func.apply(null, args); }, wait);
  7471. };
  7472. // Defers a function, scheduling it to run after the current call stack has
  7473. // cleared.
  7474. _.defer = function(func) {
  7475. return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
  7476. };
  7477. // Returns a function, that, when invoked, will only be triggered at most once
  7478. // during a given window of time.
  7479. _.throttle = function(func, wait) {
  7480. var context, args, timeout, result;
  7481. var previous = 0;
  7482. var later = function() {
  7483. previous = new Date;
  7484. timeout = null;
  7485. result = func.apply(context, args);
  7486. };
  7487. return function() {
  7488. var now = new Date;
  7489. var remaining = wait - (now - previous);
  7490. context = this;
  7491. args = arguments;
  7492. if (remaining <= 0) {
  7493. clearTimeout(timeout);
  7494. timeout = null;
  7495. previous = now;
  7496. result = func.apply(context, args);
  7497. } else if (!timeout) {
  7498. timeout = setTimeout(later, remaining);
  7499. }
  7500. return result;
  7501. };
  7502. };
  7503. // Returns a function, that, as long as it continues to be invoked, will not
  7504. // be triggered. The function will be called after it stops being called for
  7505. // N milliseconds. If `immediate` is passed, trigger the function on the
  7506. // leading edge, instead of the trailing.
  7507. _.debounce = function(func, wait, immediate) {
  7508. var timeout, result;
  7509. return function() {
  7510. var context = this, args = arguments;
  7511. var later = function() {
  7512. timeout = null;
  7513. if (!immediate) result = func.apply(context, args);
  7514. };
  7515. var callNow = immediate && !timeout;
  7516. clearTimeout(timeout);
  7517. timeout = setTimeout(later, wait);
  7518. if (callNow) result = func.apply(context, args);
  7519. return result;
  7520. };
  7521. };
  7522. // Returns a function that will be executed at most one time, no matter how
  7523. // often you call it. Useful for lazy initialization.
  7524. _.once = function(func) {
  7525. var ran = false, memo;
  7526. return function() {
  7527. if (ran) return memo;
  7528. ran = true;
  7529. memo = func.apply(this, arguments);
  7530. func = null;
  7531. return memo;
  7532. };
  7533. };
  7534. // Returns the first function passed as an argument to the second,
  7535. // allowing you to adjust arguments, run code before and after, and
  7536. // conditionally execute the original function.
  7537. _.wrap = function(func, wrapper) {
  7538. return function() {
  7539. var args = [func];
  7540. push.apply(args, arguments);
  7541. return wrapper.apply(this, args);
  7542. };
  7543. };
  7544. // Returns a function that is the composition of a list of functions, each
  7545. // consuming the return value of the function that follows.
  7546. _.compose = function() {
  7547. var funcs = arguments;
  7548. return function() {
  7549. var args = arguments;
  7550. for (var i = funcs.length - 1; i >= 0; i--) {
  7551. args = [funcs[i].apply(this, args)];
  7552. }
  7553. return args[0];
  7554. };
  7555. };
  7556. // Returns a function that will only be executed after being called N times.
  7557. _.after = function(times, func) {
  7558. if (times <= 0) return func();
  7559. return function() {
  7560. if (--times < 1) {
  7561. return func.apply(this, arguments);
  7562. }
  7563. };
  7564. };
  7565. // Object Functions
  7566. // ----------------
  7567. // Retrieve the names of an object's properties.
  7568. // Delegates to **ECMAScript 5**'s native `Object.keys`
  7569. _.keys = nativeKeys || function(obj) {
  7570. if (obj !== Object(obj)) throw new TypeError('Invalid object');
  7571. var keys = [];
  7572. for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
  7573. return keys;
  7574. };
  7575. // Retrieve the values of an object's properties.
  7576. _.values = function(obj) {
  7577. var values = [];
  7578. for (var key in obj) if (_.has(obj, key)) values.push(obj[key]);
  7579. return values;
  7580. };
  7581. // Convert an object into a list of `[key, value]` pairs.
  7582. _.pairs = function(obj) {
  7583. var pairs = [];
  7584. for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]);
  7585. return pairs;
  7586. };
  7587. // Invert the keys and values of an object. The values must be serializable.
  7588. _.invert = function(obj) {
  7589. var result = {};
  7590. for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key;
  7591. return result;
  7592. };
  7593. // Return a sorted list of the function names available on the object.
  7594. // Aliased as `methods`
  7595. _.functions = _.methods = function(obj) {
  7596. var names = [];
  7597. for (var key in obj) {
  7598. if (_.isFunction(obj[key])) names.push(key);
  7599. }
  7600. return names.sort();
  7601. };
  7602. // Extend a given object with all the properties in passed-in object(s).
  7603. _.extend = function(obj) {
  7604. each(slice.call(arguments, 1), function(source) {
  7605. if (source) {
  7606. for (var prop in source) {
  7607. obj[prop] = source[prop];
  7608. }
  7609. }
  7610. });
  7611. return obj;
  7612. };
  7613. // Return a copy of the object only containing the whitelisted properties.
  7614. _.pick = function(obj) {
  7615. var copy = {};
  7616. var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
  7617. each(keys, function(key) {
  7618. if (key in obj) copy[key] = obj[key];
  7619. });
  7620. return copy;
  7621. };
  7622. // Return a copy of the object without the blacklisted properties.
  7623. _.omit = function(obj) {
  7624. var copy = {};
  7625. var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
  7626. for (var key in obj) {
  7627. if (!_.contains(keys, key)) copy[key] = obj[key];
  7628. }
  7629. return copy;
  7630. };
  7631. // Fill in a given object with default properties.
  7632. _.defaults = function(obj) {
  7633. each(slice.call(arguments, 1), function(source) {
  7634. if (source) {
  7635. for (var prop in source) {
  7636. if (obj[prop] == null) obj[prop] = source[prop];
  7637. }
  7638. }
  7639. });
  7640. return obj;
  7641. };
  7642. // Create a (shallow-cloned) duplicate of an object.
  7643. _.clone = function(obj) {
  7644. if (!_.isObject(obj)) return obj;
  7645. return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
  7646. };
  7647. // Invokes interceptor with the obj, and then returns obj.
  7648. // The primary purpose of this method is to "tap into" a method chain, in
  7649. // order to perform operations on intermediate results within the chain.
  7650. _.tap = function(obj, interceptor) {
  7651. interceptor(obj);
  7652. return obj;
  7653. };
  7654. // Internal recursive comparison function for `isEqual`.
  7655. var eq = function(a, b, aStack, bStack) {
  7656. // Identical objects are equal. `0 === -0`, but they aren't identical.
  7657. // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
  7658. if (a === b) return a !== 0 || 1 / a == 1 / b;
  7659. // A strict comparison is necessary because `null == undefined`.
  7660. if (a == null || b == null) return a === b;
  7661. // Unwrap any wrapped objects.
  7662. if (a instanceof _) a = a._wrapped;
  7663. if (b instanceof _) b = b._wrapped;
  7664. // Compare `[[Class]]` names.
  7665. var className = toString.call(a);
  7666. if (className != toString.call(b)) return false;
  7667. switch (className) {
  7668. // Strings, numbers, dates, and booleans are compared by value.
  7669. case '[object String]':
  7670. // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  7671. // equivalent to `new String("5")`.
  7672. return a == String(b);
  7673. case '[object Number]':
  7674. // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
  7675. // other numeric values.
  7676. return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
  7677. case '[object Date]':
  7678. case '[object Boolean]':
  7679. // Coerce dates and booleans to numeric primitive values. Dates are compared by their
  7680. // millisecond representations. Note that invalid dates with millisecond representations
  7681. // of `NaN` are not equivalent.
  7682. return +a == +b;
  7683. // RegExps are compared by their source patterns and flags.
  7684. case '[object RegExp]':
  7685. return a.source == b.source &&
  7686. a.global == b.global &&
  7687. a.multiline == b.multiline &&
  7688. a.ignoreCase == b.ignoreCase;
  7689. }
  7690. if (typeof a != 'object' || typeof b != 'object') return false;
  7691. // Assume equality for cyclic structures. The algorithm for detecting cyclic
  7692. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  7693. var length = aStack.length;
  7694. while (length--) {
  7695. // Linear search. Performance is inversely proportional to the number of
  7696. // unique nested structures.
  7697. if (aStack[length] == a) return bStack[length] == b;
  7698. }
  7699. // Add the first object to the stack of traversed objects.
  7700. aStack.push(a);
  7701. bStack.push(b);
  7702. var size = 0, result = true;
  7703. // Recursively compare objects and arrays.
  7704. if (className == '[object Array]') {
  7705. // Compare array lengths to determine if a deep comparison is necessary.
  7706. size = a.length;
  7707. result = size == b.length;
  7708. if (result) {
  7709. // Deep compare the contents, ignoring non-numeric properties.
  7710. while (size--) {
  7711. if (!(result = eq(a[size], b[size], aStack, bStack))) break;
  7712. }
  7713. }
  7714. } else {
  7715. // Objects with different constructors are not equivalent, but `Object`s
  7716. // from different frames are.
  7717. var aCtor = a.constructor, bCtor = b.constructor;
  7718. if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
  7719. _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
  7720. return false;
  7721. }
  7722. // Deep compare objects.
  7723. for (var key in a) {
  7724. if (_.has(a, key)) {
  7725. // Count the expected number of properties.
  7726. size++;
  7727. // Deep compare each member.
  7728. if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
  7729. }
  7730. }
  7731. // Ensure that both objects contain the same number of properties.
  7732. if (result) {
  7733. for (key in b) {
  7734. if (_.has(b, key) && !(size--)) break;
  7735. }
  7736. result = !size;
  7737. }
  7738. }
  7739. // Remove the first object from the stack of traversed objects.
  7740. aStack.pop();
  7741. bStack.pop();
  7742. return result;
  7743. };
  7744. // Perform a deep comparison to check if two objects are equal.
  7745. _.isEqual = function(a, b) {
  7746. return eq(a, b, [], []);
  7747. };
  7748. // Is a given array, string, or object empty?
  7749. // An "empty" object has no enumerable own-properties.
  7750. _.isEmpty = function(obj) {
  7751. if (obj == null) return true;
  7752. if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
  7753. for (var key in obj) if (_.has(obj, key)) return false;
  7754. return true;
  7755. };
  7756. // Is a given value a DOM element?
  7757. _.isElement = function(obj) {
  7758. return !!(obj && obj.nodeType === 1);
  7759. };
  7760. // Is a given value an array?
  7761. // Delegates to ECMA5's native Array.isArray
  7762. _.isArray = nativeIsArray || function(obj) {
  7763. return toString.call(obj) == '[object Array]';
  7764. };
  7765. // Is a given variable an object?
  7766. _.isObject = function(obj) {
  7767. return obj === Object(obj);
  7768. };
  7769. // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
  7770. each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
  7771. _['is' + name] = function(obj) {
  7772. return toString.call(obj) == '[object ' + name + ']';
  7773. };
  7774. });
  7775. // Define a fallback version of the method in browsers (ahem, IE), where
  7776. // there isn't any inspectable "Arguments" type.
  7777. if (!_.isArguments(arguments)) {
  7778. _.isArguments = function(obj) {
  7779. return !!(obj && _.has(obj, 'callee'));
  7780. };
  7781. }
  7782. // Optimize `isFunction` if appropriate.
  7783. if (typeof (/./) !== 'function') {
  7784. _.isFunction = function(obj) {
  7785. return typeof obj === 'function';
  7786. };
  7787. }
  7788. // Is a given object a finite number?
  7789. _.isFinite = function(obj) {
  7790. return isFinite(obj) && !isNaN(parseFloat(obj));
  7791. };
  7792. // Is the given value `NaN`? (NaN is the only number which does not equal itself).
  7793. _.isNaN = function(obj) {
  7794. return _.isNumber(obj) && obj != +obj;
  7795. };
  7796. // Is a given value a boolean?
  7797. _.isBoolean = function(obj) {
  7798. return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
  7799. };
  7800. // Is a given value equal to null?
  7801. _.isNull = function(obj) {
  7802. return obj === null;
  7803. };
  7804. // Is a given variable undefined?
  7805. _.isUndefined = function(obj) {
  7806. return obj === void 0;
  7807. };
  7808. // Shortcut function for checking if an object has a given property directly
  7809. // on itself (in other words, not on a prototype).
  7810. _.has = function(obj, key) {
  7811. return hasOwnProperty.call(obj, key);
  7812. };
  7813. // Utility Functions
  7814. // -----------------
  7815. // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  7816. // previous owner. Returns a reference to the Underscore object.
  7817. _.noConflict = function() {
  7818. root._ = previousUnderscore;
  7819. return this;
  7820. };
  7821. // Keep the identity function around for default iterators.
  7822. _.identity = function(value) {
  7823. return value;
  7824. };
  7825. // Run a function **n** times.
  7826. _.times = function(n, iterator, context) {
  7827. var accum = Array(n);
  7828. for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
  7829. return accum;
  7830. };
  7831. // Return a random integer between min and max (inclusive).
  7832. _.random = function(min, max) {
  7833. if (max == null) {
  7834. max = min;
  7835. min = 0;
  7836. }
  7837. return min + Math.floor(Math.random() * (max - min + 1));
  7838. };
  7839. // List of HTML entities for escaping.
  7840. var entityMap = {
  7841. escape: {
  7842. '&': '&amp;',
  7843. '<': '&lt;',
  7844. '>': '&gt;',
  7845. '"': '&quot;',
  7846. "'": '&#x27;',
  7847. '/': '&#x2F;'
  7848. }
  7849. };
  7850. entityMap.unescape = _.invert(entityMap.escape);
  7851. // Regexes containing the keys and values listed immediately above.
  7852. var entityRegexes = {
  7853. escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
  7854. unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
  7855. };
  7856. // Functions for escaping and unescaping strings to/from HTML interpolation.
  7857. _.each(['escape', 'unescape'], function(method) {
  7858. _[method] = function(string) {
  7859. if (string == null) return '';
  7860. return ('' + string).replace(entityRegexes[method], function(match) {
  7861. return entityMap[method][match];
  7862. });
  7863. };
  7864. });
  7865. // If the value of the named property is a function then invoke it;
  7866. // otherwise, return it.
  7867. _.result = function(object, property) {
  7868. if (object == null) return null;
  7869. var value = object[property];
  7870. return _.isFunction(value) ? value.call(object) : value;
  7871. };
  7872. // Add your own custom functions to the Underscore object.
  7873. _.mixin = function(obj) {
  7874. each(_.functions(obj), function(name){
  7875. var func = _[name] = obj[name];
  7876. _.prototype[name] = function() {
  7877. var args = [this._wrapped];
  7878. push.apply(args, arguments);
  7879. return result.call(this, func.apply(_, args));
  7880. };
  7881. });
  7882. };
  7883. // Generate a unique integer id (unique within the entire client session).
  7884. // Useful for temporary DOM ids.
  7885. var idCounter = 0;
  7886. _.uniqueId = function(prefix) {
  7887. var id = ++idCounter + '';
  7888. return prefix ? prefix + id : id;
  7889. };
  7890. // By default, Underscore uses ERB-style template delimiters, change the
  7891. // following template settings to use alternative delimiters.
  7892. _.templateSettings = {
  7893. evaluate : /<%([\s\S]+?)%>/g,
  7894. interpolate : /<%=([\s\S]+?)%>/g,
  7895. escape : /<%-([\s\S]+?)%>/g
  7896. };
  7897. // When customizing `templateSettings`, if you don't want to define an
  7898. // interpolation, evaluation or escaping regex, we need one that is
  7899. // guaranteed not to match.
  7900. var noMatch = /(.)^/;
  7901. // Certain characters need to be escaped so that they can be put into a
  7902. // string literal.
  7903. var escapes = {
  7904. "'": "'",
  7905. '\\': '\\',
  7906. '\r': 'r',
  7907. '\n': 'n',
  7908. '\t': 't',
  7909. '\u2028': 'u2028',
  7910. '\u2029': 'u2029'
  7911. };
  7912. var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
  7913. // JavaScript micro-templating, similar to John Resig's implementation.
  7914. // Underscore templating handles arbitrary delimiters, preserves whitespace,
  7915. // and correctly escapes quotes within interpolated code.
  7916. _.template = function(text, data, settings) {
  7917. var render;
  7918. settings = _.defaults({}, settings, _.templateSettings);
  7919. // Combine delimiters into one regular expression via alternation.
  7920. var matcher = new RegExp([
  7921. (settings.escape || noMatch).source,
  7922. (settings.interpolate || noMatch).source,
  7923. (settings.evaluate || noMatch).source
  7924. ].join('|') + '|$', 'g');
  7925. // Compile the template source, escaping string literals appropriately.
  7926. var index = 0;
  7927. var source = "__p+='";
  7928. text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  7929. source += text.slice(index, offset)
  7930. .replace(escaper, function(match) { return '\\' + escapes[match]; });
  7931. if (escape) {
  7932. source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  7933. }
  7934. if (interpolate) {
  7935. source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
  7936. }
  7937. if (evaluate) {
  7938. source += "';\n" + evaluate + "\n__p+='";
  7939. }
  7940. index = offset + match.length;
  7941. return match;
  7942. });
  7943. source += "';\n";
  7944. // If a variable is not specified, place data values in local scope.
  7945. if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  7946. source = "var __t,__p='',__j=Array.prototype.join," +
  7947. "print=function(){__p+=__j.call(arguments,'');};\n" +
  7948. source + "return __p;\n";
  7949. try {
  7950. render = new Function(settings.variable || 'obj', '_', source);
  7951. } catch (e) {
  7952. e.source = source;
  7953. throw e;
  7954. }
  7955. if (data) return render(data, _);
  7956. var template = function(data) {
  7957. return render.call(this, data, _);
  7958. };
  7959. // Provide the compiled function source as a convenience for precompilation.
  7960. template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
  7961. return template;
  7962. };
  7963. // Add a "chain" function, which will delegate to the wrapper.
  7964. _.chain = function(obj) {
  7965. return _(obj).chain();
  7966. };
  7967. // OOP
  7968. // ---------------
  7969. // If Underscore is called as a function, it returns a wrapped object that
  7970. // can be used OO-style. This wrapper holds altered versions of all the
  7971. // underscore functions. Wrapped objects may be chained.
  7972. // Helper function to continue chaining intermediate results.
  7973. var result = function(obj) {
  7974. return this._chain ? _(obj).chain() : obj;
  7975. };
  7976. // Add all of the Underscore functions to the wrapper object.
  7977. _.mixin(_);
  7978. // Add all mutator Array functions to the wrapper.
  7979. each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  7980. var method = ArrayProto[name];
  7981. _.prototype[name] = function() {
  7982. var obj = this._wrapped;
  7983. method.apply(obj, arguments);
  7984. if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
  7985. return result.call(this, obj);
  7986. };
  7987. });
  7988. // Add all accessor Array functions to the wrapper.
  7989. each(['concat', 'join', 'slice'], function(name) {
  7990. var method = ArrayProto[name];
  7991. _.prototype[name] = function() {
  7992. return result.call(this, method.apply(this._wrapped, arguments));
  7993. };
  7994. });
  7995. _.extend(_.prototype, {
  7996. // Start chaining a wrapped Underscore object.
  7997. chain: function() {
  7998. this._chain = true;
  7999. return this;
  8000. },
  8001. // Extracts the result from a wrapped and chained object.
  8002. value: function() {
  8003. return this._wrapped;
  8004. }
  8005. });
  8006. }).call(this);
  8007. })()
  8008. },{}],11:[function(require,module,exports){
  8009. var events = require('events');
  8010. exports.isArray = isArray;
  8011. exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};
  8012. exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};
  8013. exports.print = function () {};
  8014. exports.puts = function () {};
  8015. exports.debug = function() {};
  8016. exports.inspect = function(obj, showHidden, depth, colors) {
  8017. var seen = [];
  8018. var stylize = function(str, styleType) {
  8019. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  8020. var styles =
  8021. { 'bold' : [1, 22],
  8022. 'italic' : [3, 23],
  8023. 'underline' : [4, 24],
  8024. 'inverse' : [7, 27],
  8025. 'white' : [37, 39],
  8026. 'grey' : [90, 39],
  8027. 'black' : [30, 39],
  8028. 'blue' : [34, 39],
  8029. 'cyan' : [36, 39],
  8030. 'green' : [32, 39],
  8031. 'magenta' : [35, 39],
  8032. 'red' : [31, 39],
  8033. 'yellow' : [33, 39] };
  8034. var style =
  8035. { 'special': 'cyan',
  8036. 'number': 'blue',
  8037. 'boolean': 'yellow',
  8038. 'undefined': 'grey',
  8039. 'null': 'bold',
  8040. 'string': 'green',
  8041. 'date': 'magenta',
  8042. // "name": intentionally not styling
  8043. 'regexp': 'red' }[styleType];
  8044. if (style) {
  8045. return '\033[' + styles[style][0] + 'm' + str +
  8046. '\033[' + styles[style][1] + 'm';
  8047. } else {
  8048. return str;
  8049. }
  8050. };
  8051. if (! colors) {
  8052. stylize = function(str, styleType) { return str; };
  8053. }
  8054. function format(value, recurseTimes) {
  8055. // Provide a hook for user-specified inspect functions.
  8056. // Check that value is an object with an inspect function on it
  8057. if (value && typeof value.inspect === 'function' &&
  8058. // Filter out the util module, it's inspect function is special
  8059. value !== exports &&
  8060. // Also filter out any prototype objects using the circular check.
  8061. !(value.constructor && value.constructor.prototype === value)) {
  8062. return value.inspect(recurseTimes);
  8063. }
  8064. // Primitive types cannot have properties
  8065. switch (typeof value) {
  8066. case 'undefined':
  8067. return stylize('undefined', 'undefined');
  8068. case 'string':
  8069. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  8070. .replace(/'/g, "\\'")
  8071. .replace(/\\"/g, '"') + '\'';
  8072. return stylize(simple, 'string');
  8073. case 'number':
  8074. return stylize('' + value, 'number');
  8075. case 'boolean':
  8076. return stylize('' + value, 'boolean');
  8077. }
  8078. // For some reason typeof null is "object", so special case here.
  8079. if (value === null) {
  8080. return stylize('null', 'null');
  8081. }
  8082. // Look up the keys of the object.
  8083. var visible_keys = Object_keys(value);
  8084. var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;
  8085. // Functions without properties can be shortcutted.
  8086. if (typeof value === 'function' && keys.length === 0) {
  8087. if (isRegExp(value)) {
  8088. return stylize('' + value, 'regexp');
  8089. } else {
  8090. var name = value.name ? ': ' + value.name : '';
  8091. return stylize('[Function' + name + ']', 'special');
  8092. }
  8093. }
  8094. // Dates without properties can be shortcutted
  8095. if (isDate(value) && keys.length === 0) {
  8096. return stylize(value.toUTCString(), 'date');
  8097. }
  8098. var base, type, braces;
  8099. // Determine the object type
  8100. if (isArray(value)) {
  8101. type = 'Array';
  8102. braces = ['[', ']'];
  8103. } else {
  8104. type = 'Object';
  8105. braces = ['{', '}'];
  8106. }
  8107. // Make functions say that they are functions
  8108. if (typeof value === 'function') {
  8109. var n = value.name ? ': ' + value.name : '';
  8110. base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
  8111. } else {
  8112. base = '';
  8113. }
  8114. // Make dates with properties first say the date
  8115. if (isDate(value)) {
  8116. base = ' ' + value.toUTCString();
  8117. }
  8118. if (keys.length === 0) {
  8119. return braces[0] + base + braces[1];
  8120. }
  8121. if (recurseTimes < 0) {
  8122. if (isRegExp(value)) {
  8123. return stylize('' + value, 'regexp');
  8124. } else {
  8125. return stylize('[Object]', 'special');
  8126. }
  8127. }
  8128. seen.push(value);
  8129. var output = keys.map(function(key) {
  8130. var name, str;
  8131. if (value.__lookupGetter__) {
  8132. if (value.__lookupGetter__(key)) {
  8133. if (value.__lookupSetter__(key)) {
  8134. str = stylize('[Getter/Setter]', 'special');
  8135. } else {
  8136. str = stylize('[Getter]', 'special');
  8137. }
  8138. } else {
  8139. if (value.__lookupSetter__(key)) {
  8140. str = stylize('[Setter]', 'special');
  8141. }
  8142. }
  8143. }
  8144. if (visible_keys.indexOf(key) < 0) {
  8145. name = '[' + key + ']';
  8146. }
  8147. if (!str) {
  8148. if (seen.indexOf(value[key]) < 0) {
  8149. if (recurseTimes === null) {
  8150. str = format(value[key]);
  8151. } else {
  8152. str = format(value[key], recurseTimes - 1);
  8153. }
  8154. if (str.indexOf('\n') > -1) {
  8155. if (isArray(value)) {
  8156. str = str.split('\n').map(function(line) {
  8157. return ' ' + line;
  8158. }).join('\n').substr(2);
  8159. } else {
  8160. str = '\n' + str.split('\n').map(function(line) {
  8161. return ' ' + line;
  8162. }).join('\n');
  8163. }
  8164. }
  8165. } else {
  8166. str = stylize('[Circular]', 'special');
  8167. }
  8168. }
  8169. if (typeof name === 'undefined') {
  8170. if (type === 'Array' && key.match(/^\d+$/)) {
  8171. return str;
  8172. }
  8173. name = JSON.stringify('' + key);
  8174. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  8175. name = name.substr(1, name.length - 2);
  8176. name = stylize(name, 'name');
  8177. } else {
  8178. name = name.replace(/'/g, "\\'")
  8179. .replace(/\\"/g, '"')
  8180. .replace(/(^"|"$)/g, "'");
  8181. name = stylize(name, 'string');
  8182. }
  8183. }
  8184. return name + ': ' + str;
  8185. });
  8186. seen.pop();
  8187. var numLinesEst = 0;
  8188. var length = output.reduce(function(prev, cur) {
  8189. numLinesEst++;
  8190. if (cur.indexOf('\n') >= 0) numLinesEst++;
  8191. return prev + cur.length + 1;
  8192. }, 0);
  8193. if (length > 50) {
  8194. output = braces[0] +
  8195. (base === '' ? '' : base + '\n ') +
  8196. ' ' +
  8197. output.join(',\n ') +
  8198. ' ' +
  8199. braces[1];
  8200. } else {
  8201. output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  8202. }
  8203. return output;
  8204. }
  8205. return format(obj, (typeof depth === 'undefined' ? 2 : depth));
  8206. };
  8207. function isArray(ar) {
  8208. return ar instanceof Array ||
  8209. Array.isArray(ar) ||
  8210. (ar && ar !== Object.prototype && isArray(ar.__proto__));
  8211. }
  8212. function isRegExp(re) {
  8213. return re instanceof RegExp ||
  8214. (typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]');
  8215. }
  8216. function isDate(d) {
  8217. if (d instanceof Date) return true;
  8218. if (typeof d !== 'object') return false;
  8219. var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype);
  8220. var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__);
  8221. return JSON.stringify(proto) === JSON.stringify(properties);
  8222. }
  8223. function pad(n) {
  8224. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  8225. }
  8226. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  8227. 'Oct', 'Nov', 'Dec'];
  8228. // 26 Feb 16:19:34
  8229. function timestamp() {
  8230. var d = new Date();
  8231. var time = [pad(d.getHours()),
  8232. pad(d.getMinutes()),
  8233. pad(d.getSeconds())].join(':');
  8234. return [d.getDate(), months[d.getMonth()], time].join(' ');
  8235. }
  8236. exports.log = function (msg) {};
  8237. exports.pump = null;
  8238. var Object_keys = Object.keys || function (obj) {
  8239. var res = [];
  8240. for (var key in obj) res.push(key);
  8241. return res;
  8242. };
  8243. var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {
  8244. var res = [];
  8245. for (var key in obj) {
  8246. if (Object.hasOwnProperty.call(obj, key)) res.push(key);
  8247. }
  8248. return res;
  8249. };
  8250. var Object_create = Object.create || function (prototype, properties) {
  8251. // from es5-shim
  8252. var object;
  8253. if (prototype === null) {
  8254. object = { '__proto__' : null };
  8255. }
  8256. else {
  8257. if (typeof prototype !== 'object') {
  8258. throw new TypeError(
  8259. 'typeof prototype[' + (typeof prototype) + '] != \'object\''
  8260. );
  8261. }
  8262. var Type = function () {};
  8263. Type.prototype = prototype;
  8264. object = new Type();
  8265. object.__proto__ = prototype;
  8266. }
  8267. if (typeof properties !== 'undefined' && Object.defineProperties) {
  8268. Object.defineProperties(object, properties);
  8269. }
  8270. return object;
  8271. };
  8272. exports.inherits = function(ctor, superCtor) {
  8273. ctor.super_ = superCtor;
  8274. ctor.prototype = Object_create(superCtor.prototype, {
  8275. constructor: {
  8276. value: ctor,
  8277. enumerable: false,
  8278. writable: true,
  8279. configurable: true
  8280. }
  8281. });
  8282. };
  8283. var formatRegExp = /%[sdj%]/g;
  8284. exports.format = function(f) {
  8285. if (typeof f !== 'string') {
  8286. var objects = [];
  8287. for (var i = 0; i < arguments.length; i++) {
  8288. objects.push(exports.inspect(arguments[i]));
  8289. }
  8290. return objects.join(' ');
  8291. }
  8292. var i = 1;
  8293. var args = arguments;
  8294. var len = args.length;
  8295. var str = String(f).replace(formatRegExp, function(x) {
  8296. if (x === '%%') return '%';
  8297. if (i >= len) return x;
  8298. switch (x) {
  8299. case '%s': return String(args[i++]);
  8300. case '%d': return Number(args[i++]);
  8301. case '%j': return JSON.stringify(args[i++]);
  8302. default:
  8303. return x;
  8304. }
  8305. });
  8306. for(var x = args[i]; i < len; x = args[++i]){
  8307. if (x === null || typeof x !== 'object') {
  8308. str += ' ' + x;
  8309. } else {
  8310. str += ' ' + exports.inspect(x);
  8311. }
  8312. }
  8313. return str;
  8314. };
  8315. },{"events":2}],12:[function(require,module,exports){
  8316. (function(){// UTILITY
  8317. var util = require('util');
  8318. var Buffer = require("buffer").Buffer;
  8319. var pSlice = Array.prototype.slice;
  8320. function objectKeys(object) {
  8321. if (Object.keys) return Object.keys(object);
  8322. var result = [];
  8323. for (var name in object) {
  8324. if (Object.prototype.hasOwnProperty.call(object, name)) {
  8325. result.push(name);
  8326. }
  8327. }
  8328. return result;
  8329. }
  8330. // 1. The assert module provides functions that throw
  8331. // AssertionError's when particular conditions are not met. The
  8332. // assert module must conform to the following interface.
  8333. var assert = module.exports = ok;
  8334. // 2. The AssertionError is defined in assert.
  8335. // new assert.AssertionError({ message: message,
  8336. // actual: actual,
  8337. // expected: expected })
  8338. assert.AssertionError = function AssertionError(options) {
  8339. this.name = 'AssertionError';
  8340. this.message = options.message;
  8341. this.actual = options.actual;
  8342. this.expected = options.expected;
  8343. this.operator = options.operator;
  8344. var stackStartFunction = options.stackStartFunction || fail;
  8345. if (Error.captureStackTrace) {
  8346. Error.captureStackTrace(this, stackStartFunction);
  8347. }
  8348. };
  8349. util.inherits(assert.AssertionError, Error);
  8350. function replacer(key, value) {
  8351. if (value === undefined) {
  8352. return '' + value;
  8353. }
  8354. if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
  8355. return value.toString();
  8356. }
  8357. if (typeof value === 'function' || value instanceof RegExp) {
  8358. return value.toString();
  8359. }
  8360. return value;
  8361. }
  8362. function truncate(s, n) {
  8363. if (typeof s == 'string') {
  8364. return s.length < n ? s : s.slice(0, n);
  8365. } else {
  8366. return s;
  8367. }
  8368. }
  8369. assert.AssertionError.prototype.toString = function() {
  8370. if (this.message) {
  8371. return [this.name + ':', this.message].join(' ');
  8372. } else {
  8373. return [
  8374. this.name + ':',
  8375. truncate(JSON.stringify(this.actual, replacer), 128),
  8376. this.operator,
  8377. truncate(JSON.stringify(this.expected, replacer), 128)
  8378. ].join(' ');
  8379. }
  8380. };
  8381. // assert.AssertionError instanceof Error
  8382. assert.AssertionError.__proto__ = Error.prototype;
  8383. // At present only the three keys mentioned above are used and
  8384. // understood by the spec. Implementations or sub modules can pass
  8385. // other keys to the AssertionError's constructor - they will be
  8386. // ignored.
  8387. // 3. All of the following functions must throw an AssertionError
  8388. // when a corresponding condition is not met, with a message that
  8389. // may be undefined if not provided. All assertion methods provide
  8390. // both the actual and expected values to the assertion error for
  8391. // display purposes.
  8392. function fail(actual, expected, message, operator, stackStartFunction) {
  8393. throw new assert.AssertionError({
  8394. message: message,
  8395. actual: actual,
  8396. expected: expected,
  8397. operator: operator,
  8398. stackStartFunction: stackStartFunction
  8399. });
  8400. }
  8401. // EXTENSION! allows for well behaved errors defined elsewhere.
  8402. assert.fail = fail;
  8403. // 4. Pure assertion tests whether a value is truthy, as determined
  8404. // by !!guard.
  8405. // assert.ok(guard, message_opt);
  8406. // This statement is equivalent to assert.equal(true, guard,
  8407. // message_opt);. To test strictly for the value true, use
  8408. // assert.strictEqual(true, guard, message_opt);.
  8409. function ok(value, message) {
  8410. if (!!!value) fail(value, true, message, '==', assert.ok);
  8411. }
  8412. assert.ok = ok;
  8413. // 5. The equality assertion tests shallow, coercive equality with
  8414. // ==.
  8415. // assert.equal(actual, expected, message_opt);
  8416. assert.equal = function equal(actual, expected, message) {
  8417. if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  8418. };
  8419. // 6. The non-equality assertion tests for whether two objects are not equal
  8420. // with != assert.notEqual(actual, expected, message_opt);
  8421. assert.notEqual = function notEqual(actual, expected, message) {
  8422. if (actual == expected) {
  8423. fail(actual, expected, message, '!=', assert.notEqual);
  8424. }
  8425. };
  8426. // 7. The equivalence assertion tests a deep equality relation.
  8427. // assert.deepEqual(actual, expected, message_opt);
  8428. assert.deepEqual = function deepEqual(actual, expected, message) {
  8429. if (!_deepEqual(actual, expected)) {
  8430. fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  8431. }
  8432. };
  8433. function _deepEqual(actual, expected) {
  8434. // 7.1. All identical values are equivalent, as determined by ===.
  8435. if (actual === expected) {
  8436. return true;
  8437. } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
  8438. if (actual.length != expected.length) return false;
  8439. for (var i = 0; i < actual.length; i++) {
  8440. if (actual[i] !== expected[i]) return false;
  8441. }
  8442. return true;
  8443. // 7.2. If the expected value is a Date object, the actual value is
  8444. // equivalent if it is also a Date object that refers to the same time.
  8445. } else if (actual instanceof Date && expected instanceof Date) {
  8446. return actual.getTime() === expected.getTime();
  8447. // 7.3. Other pairs that do not both pass typeof value == 'object',
  8448. // equivalence is determined by ==.
  8449. } else if (typeof actual != 'object' && typeof expected != 'object') {
  8450. return actual == expected;
  8451. // 7.4. For all other Object pairs, including Array objects, equivalence is
  8452. // determined by having the same number of owned properties (as verified
  8453. // with Object.prototype.hasOwnProperty.call), the same set of keys
  8454. // (although not necessarily the same order), equivalent values for every
  8455. // corresponding key, and an identical 'prototype' property. Note: this
  8456. // accounts for both named and indexed properties on Arrays.
  8457. } else {
  8458. return objEquiv(actual, expected);
  8459. }
  8460. }
  8461. function isUndefinedOrNull(value) {
  8462. return value === null || value === undefined;
  8463. }
  8464. function isArguments(object) {
  8465. return Object.prototype.toString.call(object) == '[object Arguments]';
  8466. }
  8467. function objEquiv(a, b) {
  8468. if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
  8469. return false;
  8470. // an identical 'prototype' property.
  8471. if (a.prototype !== b.prototype) return false;
  8472. //~~~I've managed to break Object.keys through screwy arguments passing.
  8473. // Converting to array solves the problem.
  8474. if (isArguments(a)) {
  8475. if (!isArguments(b)) {
  8476. return false;
  8477. }
  8478. a = pSlice.call(a);
  8479. b = pSlice.call(b);
  8480. return _deepEqual(a, b);
  8481. }
  8482. try {
  8483. var ka = objectKeys(a),
  8484. kb = objectKeys(b),
  8485. key, i;
  8486. } catch (e) {//happens when one is a string literal and the other isn't
  8487. return false;
  8488. }
  8489. // having the same number of owned properties (keys incorporates
  8490. // hasOwnProperty)
  8491. if (ka.length != kb.length)
  8492. return false;
  8493. //the same set of keys (although not necessarily the same order),
  8494. ka.sort();
  8495. kb.sort();
  8496. //~~~cheap key test
  8497. for (i = ka.length - 1; i >= 0; i--) {
  8498. if (ka[i] != kb[i])
  8499. return false;
  8500. }
  8501. //equivalent values for every corresponding key, and
  8502. //~~~possibly expensive deep test
  8503. for (i = ka.length - 1; i >= 0; i--) {
  8504. key = ka[i];
  8505. if (!_deepEqual(a[key], b[key])) return false;
  8506. }
  8507. return true;
  8508. }
  8509. // 8. The non-equivalence assertion tests for any deep inequality.
  8510. // assert.notDeepEqual(actual, expected, message_opt);
  8511. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  8512. if (_deepEqual(actual, expected)) {
  8513. fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  8514. }
  8515. };
  8516. // 9. The strict equality assertion tests strict equality, as determined by ===.
  8517. // assert.strictEqual(actual, expected, message_opt);
  8518. assert.strictEqual = function strictEqual(actual, expected, message) {
  8519. if (actual !== expected) {
  8520. fail(actual, expected, message, '===', assert.strictEqual);
  8521. }
  8522. };
  8523. // 10. The strict non-equality assertion tests for strict inequality, as
  8524. // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
  8525. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  8526. if (actual === expected) {
  8527. fail(actual, expected, message, '!==', assert.notStrictEqual);
  8528. }
  8529. };
  8530. function expectedException(actual, expected) {
  8531. if (!actual || !expected) {
  8532. return false;
  8533. }
  8534. if (expected instanceof RegExp) {
  8535. return expected.test(actual);
  8536. } else if (actual instanceof expected) {
  8537. return true;
  8538. } else if (expected.call({}, actual) === true) {
  8539. return true;
  8540. }
  8541. return false;
  8542. }
  8543. function _throws(shouldThrow, block, expected, message) {
  8544. var actual;
  8545. if (typeof expected === 'string') {
  8546. message = expected;
  8547. expected = null;
  8548. }
  8549. try {
  8550. block();
  8551. } catch (e) {
  8552. actual = e;
  8553. }
  8554. message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  8555. (message ? ' ' + message : '.');
  8556. if (shouldThrow && !actual) {
  8557. fail('Missing expected exception' + message);
  8558. }
  8559. if (!shouldThrow && expectedException(actual, expected)) {
  8560. fail('Got unwanted exception' + message);
  8561. }
  8562. if ((shouldThrow && actual && expected &&
  8563. !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  8564. throw actual;
  8565. }
  8566. }
  8567. // 11. Expected to throw an error:
  8568. // assert.throws(block, Error_opt, message_opt);
  8569. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  8570. _throws.apply(this, [true].concat(pSlice.call(arguments)));
  8571. };
  8572. // EXTENSION! This is annoying to write outside this module.
  8573. assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
  8574. _throws.apply(this, [false].concat(pSlice.call(arguments)));
  8575. };
  8576. assert.ifError = function(err) { if (err) {throw err;}};
  8577. })()
  8578. },{"util":11,"buffer":13}],14:[function(require,module,exports){
  8579. exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
  8580. var e, m,
  8581. eLen = nBytes * 8 - mLen - 1,
  8582. eMax = (1 << eLen) - 1,
  8583. eBias = eMax >> 1,
  8584. nBits = -7,
  8585. i = isBE ? 0 : (nBytes - 1),
  8586. d = isBE ? 1 : -1,
  8587. s = buffer[offset + i];
  8588. i += d;
  8589. e = s & ((1 << (-nBits)) - 1);
  8590. s >>= (-nBits);
  8591. nBits += eLen;
  8592. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
  8593. m = e & ((1 << (-nBits)) - 1);
  8594. e >>= (-nBits);
  8595. nBits += mLen;
  8596. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
  8597. if (e === 0) {
  8598. e = 1 - eBias;
  8599. } else if (e === eMax) {
  8600. return m ? NaN : ((s ? -1 : 1) * Infinity);
  8601. } else {
  8602. m = m + Math.pow(2, mLen);
  8603. e = e - eBias;
  8604. }
  8605. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  8606. };
  8607. exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
  8608. var e, m, c,
  8609. eLen = nBytes * 8 - mLen - 1,
  8610. eMax = (1 << eLen) - 1,
  8611. eBias = eMax >> 1,
  8612. rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
  8613. i = isBE ? (nBytes - 1) : 0,
  8614. d = isBE ? -1 : 1,
  8615. s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  8616. value = Math.abs(value);
  8617. if (isNaN(value) || value === Infinity) {
  8618. m = isNaN(value) ? 1 : 0;
  8619. e = eMax;
  8620. } else {
  8621. e = Math.floor(Math.log(value) / Math.LN2);
  8622. if (value * (c = Math.pow(2, -e)) < 1) {
  8623. e--;
  8624. c *= 2;
  8625. }
  8626. if (e + eBias >= 1) {
  8627. value += rt / c;
  8628. } else {
  8629. value += rt * Math.pow(2, 1 - eBias);
  8630. }
  8631. if (value * c >= 2) {
  8632. e++;
  8633. c /= 2;
  8634. }
  8635. if (e + eBias >= eMax) {
  8636. m = 0;
  8637. e = eMax;
  8638. } else if (e + eBias >= 1) {
  8639. m = (value * c - 1) * Math.pow(2, mLen);
  8640. e = e + eBias;
  8641. } else {
  8642. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  8643. e = 0;
  8644. }
  8645. }
  8646. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
  8647. e = (e << mLen) | m;
  8648. eLen += mLen;
  8649. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
  8650. buffer[offset + i - d] |= s * 128;
  8651. };
  8652. },{}],13:[function(require,module,exports){
  8653. (function(){function SlowBuffer (size) {
  8654. this.length = size;
  8655. };
  8656. var assert = require('assert');
  8657. exports.INSPECT_MAX_BYTES = 50;
  8658. function toHex(n) {
  8659. if (n < 16) return '0' + n.toString(16);
  8660. return n.toString(16);
  8661. }
  8662. function utf8ToBytes(str) {
  8663. var byteArray = [];
  8664. for (var i = 0; i < str.length; i++)
  8665. if (str.charCodeAt(i) <= 0x7F)
  8666. byteArray.push(str.charCodeAt(i));
  8667. else {
  8668. var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
  8669. for (var j = 0; j < h.length; j++)
  8670. byteArray.push(parseInt(h[j], 16));
  8671. }
  8672. return byteArray;
  8673. }
  8674. function asciiToBytes(str) {
  8675. var byteArray = []
  8676. for (var i = 0; i < str.length; i++ )
  8677. // Node's code seems to be doing this and not & 0x7F..
  8678. byteArray.push( str.charCodeAt(i) & 0xFF );
  8679. return byteArray;
  8680. }
  8681. function base64ToBytes(str) {
  8682. return require("base64-js").toByteArray(str);
  8683. }
  8684. SlowBuffer.byteLength = function (str, encoding) {
  8685. switch (encoding || "utf8") {
  8686. case 'hex':
  8687. return str.length / 2;
  8688. case 'utf8':
  8689. case 'utf-8':
  8690. return utf8ToBytes(str).length;
  8691. case 'ascii':
  8692. case 'binary':
  8693. return str.length;
  8694. case 'base64':
  8695. return base64ToBytes(str).length;
  8696. default:
  8697. throw new Error('Unknown encoding');
  8698. }
  8699. };
  8700. function blitBuffer(src, dst, offset, length) {
  8701. var pos, i = 0;
  8702. while (i < length) {
  8703. if ((i+offset >= dst.length) || (i >= src.length))
  8704. break;
  8705. dst[i + offset] = src[i];
  8706. i++;
  8707. }
  8708. return i;
  8709. }
  8710. SlowBuffer.prototype.utf8Write = function (string, offset, length) {
  8711. var bytes, pos;
  8712. return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
  8713. };
  8714. SlowBuffer.prototype.asciiWrite = function (string, offset, length) {
  8715. var bytes, pos;
  8716. return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
  8717. };
  8718. SlowBuffer.prototype.binaryWrite = SlowBuffer.prototype.asciiWrite;
  8719. SlowBuffer.prototype.base64Write = function (string, offset, length) {
  8720. var bytes, pos;
  8721. return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
  8722. };
  8723. SlowBuffer.prototype.base64Slice = function (start, end) {
  8724. var bytes = Array.prototype.slice.apply(this, arguments)
  8725. return require("base64-js").fromByteArray(bytes);
  8726. }
  8727. function decodeUtf8Char(str) {
  8728. try {
  8729. return decodeURIComponent(str);
  8730. } catch (err) {
  8731. return String.fromCharCode(0xFFFD); // UTF 8 invalid char
  8732. }
  8733. }
  8734. SlowBuffer.prototype.utf8Slice = function () {
  8735. var bytes = Array.prototype.slice.apply(this, arguments);
  8736. var res = "";
  8737. var tmp = "";
  8738. var i = 0;
  8739. while (i < bytes.length) {
  8740. if (bytes[i] <= 0x7F) {
  8741. res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
  8742. tmp = "";
  8743. } else
  8744. tmp += "%" + bytes[i].toString(16);
  8745. i++;
  8746. }
  8747. return res + decodeUtf8Char(tmp);
  8748. }
  8749. SlowBuffer.prototype.asciiSlice = function () {
  8750. var bytes = Array.prototype.slice.apply(this, arguments);
  8751. var ret = "";
  8752. for (var i = 0; i < bytes.length; i++)
  8753. ret += String.fromCharCode(bytes[i]);
  8754. return ret;
  8755. }
  8756. SlowBuffer.prototype.binarySlice = SlowBuffer.prototype.asciiSlice;
  8757. SlowBuffer.prototype.inspect = function() {
  8758. var out = [],
  8759. len = this.length;
  8760. for (var i = 0; i < len; i++) {
  8761. out[i] = toHex(this[i]);
  8762. if (i == exports.INSPECT_MAX_BYTES) {
  8763. out[i + 1] = '...';
  8764. break;
  8765. }
  8766. }
  8767. return '<SlowBuffer ' + out.join(' ') + '>';
  8768. };
  8769. SlowBuffer.prototype.hexSlice = function(start, end) {
  8770. var len = this.length;
  8771. if (!start || start < 0) start = 0;
  8772. if (!end || end < 0 || end > len) end = len;
  8773. var out = '';
  8774. for (var i = start; i < end; i++) {
  8775. out += toHex(this[i]);
  8776. }
  8777. return out;
  8778. };
  8779. SlowBuffer.prototype.toString = function(encoding, start, end) {
  8780. encoding = String(encoding || 'utf8').toLowerCase();
  8781. start = +start || 0;
  8782. if (typeof end == 'undefined') end = this.length;
  8783. // Fastpath empty strings
  8784. if (+end == start) {
  8785. return '';
  8786. }
  8787. switch (encoding) {
  8788. case 'hex':
  8789. return this.hexSlice(start, end);
  8790. case 'utf8':
  8791. case 'utf-8':
  8792. return this.utf8Slice(start, end);
  8793. case 'ascii':
  8794. return this.asciiSlice(start, end);
  8795. case 'binary':
  8796. return this.binarySlice(start, end);
  8797. case 'base64':
  8798. return this.base64Slice(start, end);
  8799. case 'ucs2':
  8800. case 'ucs-2':
  8801. return this.ucs2Slice(start, end);
  8802. default:
  8803. throw new Error('Unknown encoding');
  8804. }
  8805. };
  8806. SlowBuffer.prototype.hexWrite = function(string, offset, length) {
  8807. offset = +offset || 0;
  8808. var remaining = this.length - offset;
  8809. if (!length) {
  8810. length = remaining;
  8811. } else {
  8812. length = +length;
  8813. if (length > remaining) {
  8814. length = remaining;
  8815. }
  8816. }
  8817. // must be an even number of digits
  8818. var strLen = string.length;
  8819. if (strLen % 2) {
  8820. throw new Error('Invalid hex string');
  8821. }
  8822. if (length > strLen / 2) {
  8823. length = strLen / 2;
  8824. }
  8825. for (var i = 0; i < length; i++) {
  8826. var byte = parseInt(string.substr(i * 2, 2), 16);
  8827. if (isNaN(byte)) throw new Error('Invalid hex string');
  8828. this[offset + i] = byte;
  8829. }
  8830. SlowBuffer._charsWritten = i * 2;
  8831. return i;
  8832. };
  8833. SlowBuffer.prototype.write = function(string, offset, length, encoding) {
  8834. // Support both (string, offset, length, encoding)
  8835. // and the legacy (string, encoding, offset, length)
  8836. if (isFinite(offset)) {
  8837. if (!isFinite(length)) {
  8838. encoding = length;
  8839. length = undefined;
  8840. }
  8841. } else { // legacy
  8842. var swap = encoding;
  8843. encoding = offset;
  8844. offset = length;
  8845. length = swap;
  8846. }
  8847. offset = +offset || 0;
  8848. var remaining = this.length - offset;
  8849. if (!length) {
  8850. length = remaining;
  8851. } else {
  8852. length = +length;
  8853. if (length > remaining) {
  8854. length = remaining;
  8855. }
  8856. }
  8857. encoding = String(encoding || 'utf8').toLowerCase();
  8858. switch (encoding) {
  8859. case 'hex':
  8860. return this.hexWrite(string, offset, length);
  8861. case 'utf8':
  8862. case 'utf-8':
  8863. return this.utf8Write(string, offset, length);
  8864. case 'ascii':
  8865. return this.asciiWrite(string, offset, length);
  8866. case 'binary':
  8867. return this.binaryWrite(string, offset, length);
  8868. case 'base64':
  8869. return this.base64Write(string, offset, length);
  8870. case 'ucs2':
  8871. case 'ucs-2':
  8872. return this.ucs2Write(string, offset, length);
  8873. default:
  8874. throw new Error('Unknown encoding');
  8875. }
  8876. };
  8877. // slice(start, end)
  8878. SlowBuffer.prototype.slice = function(start, end) {
  8879. if (end === undefined) end = this.length;
  8880. if (end > this.length) {
  8881. throw new Error('oob');
  8882. }
  8883. if (start > end) {
  8884. throw new Error('oob');
  8885. }
  8886. return new Buffer(this, end - start, +start);
  8887. };
  8888. SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) {
  8889. var temp = [];
  8890. for (var i=sourcestart; i<sourceend; i++) {
  8891. assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
  8892. temp.push(this[i]);
  8893. }
  8894. for (var i=targetstart; i<targetstart+temp.length; i++) {
  8895. target[i] = temp[i-targetstart];
  8896. }
  8897. };
  8898. SlowBuffer.prototype.fill = function(value, start, end) {
  8899. if (end > this.length) {
  8900. throw new Error('oob');
  8901. }
  8902. if (start > end) {
  8903. throw new Error('oob');
  8904. }
  8905. for (var i = start; i < end; i++) {
  8906. this[i] = value;
  8907. }
  8908. }
  8909. function coerce(length) {
  8910. // Coerce length to a number (possibly NaN), round up
  8911. // in case it's fractional (e.g. 123.456) then do a
  8912. // double negate to coerce a NaN to 0. Easy, right?
  8913. length = ~~Math.ceil(+length);
  8914. return length < 0 ? 0 : length;
  8915. }
  8916. // Buffer
  8917. function Buffer(subject, encoding, offset) {
  8918. if (!(this instanceof Buffer)) {
  8919. return new Buffer(subject, encoding, offset);
  8920. }
  8921. var type;
  8922. // Are we slicing?
  8923. if (typeof offset === 'number') {
  8924. this.length = coerce(encoding);
  8925. this.parent = subject;
  8926. this.offset = offset;
  8927. } else {
  8928. // Find the length
  8929. switch (type = typeof subject) {
  8930. case 'number':
  8931. this.length = coerce(subject);
  8932. break;
  8933. case 'string':
  8934. this.length = Buffer.byteLength(subject, encoding);
  8935. break;
  8936. case 'object': // Assume object is an array
  8937. this.length = coerce(subject.length);
  8938. break;
  8939. default:
  8940. throw new Error('First argument needs to be a number, ' +
  8941. 'array or string.');
  8942. }
  8943. if (this.length > Buffer.poolSize) {
  8944. // Big buffer, just alloc one.
  8945. this.parent = new SlowBuffer(this.length);
  8946. this.offset = 0;
  8947. } else {
  8948. // Small buffer.
  8949. if (!pool || pool.length - pool.used < this.length) allocPool();
  8950. this.parent = pool;
  8951. this.offset = pool.used;
  8952. pool.used += this.length;
  8953. }
  8954. // Treat array-ish objects as a byte array.
  8955. if (isArrayIsh(subject)) {
  8956. for (var i = 0; i < this.length; i++) {
  8957. if (subject instanceof Buffer) {
  8958. this.parent[i + this.offset] = subject.readUInt8(i);
  8959. }
  8960. else {
  8961. this.parent[i + this.offset] = subject[i];
  8962. }
  8963. }
  8964. } else if (type == 'string') {
  8965. // We are a string
  8966. this.length = this.write(subject, 0, encoding);
  8967. }
  8968. }
  8969. }
  8970. function isArrayIsh(subject) {
  8971. return Array.isArray(subject) || Buffer.isBuffer(subject) ||
  8972. subject && typeof subject === 'object' &&
  8973. typeof subject.length === 'number';
  8974. }
  8975. exports.SlowBuffer = SlowBuffer;
  8976. exports.Buffer = Buffer;
  8977. Buffer.poolSize = 8 * 1024;
  8978. var pool;
  8979. function allocPool() {
  8980. pool = new SlowBuffer(Buffer.poolSize);
  8981. pool.used = 0;
  8982. }
  8983. // Static methods
  8984. Buffer.isBuffer = function isBuffer(b) {
  8985. return b instanceof Buffer || b instanceof SlowBuffer;
  8986. };
  8987. Buffer.concat = function (list, totalLength) {
  8988. if (!Array.isArray(list)) {
  8989. throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
  8990. list should be an Array.");
  8991. }
  8992. if (list.length === 0) {
  8993. return new Buffer(0);
  8994. } else if (list.length === 1) {
  8995. return list[0];
  8996. }
  8997. if (typeof totalLength !== 'number') {
  8998. totalLength = 0;
  8999. for (var i = 0; i < list.length; i++) {
  9000. var buf = list[i];
  9001. totalLength += buf.length;
  9002. }
  9003. }
  9004. var buffer = new Buffer(totalLength);
  9005. var pos = 0;
  9006. for (var i = 0; i < list.length; i++) {
  9007. var buf = list[i];
  9008. buf.copy(buffer, pos);
  9009. pos += buf.length;
  9010. }
  9011. return buffer;
  9012. };
  9013. // Inspect
  9014. Buffer.prototype.inspect = function inspect() {
  9015. var out = [],
  9016. len = this.length;
  9017. for (var i = 0; i < len; i++) {
  9018. out[i] = toHex(this.parent[i + this.offset]);
  9019. if (i == exports.INSPECT_MAX_BYTES) {
  9020. out[i + 1] = '...';
  9021. break;
  9022. }
  9023. }
  9024. return '<Buffer ' + out.join(' ') + '>';
  9025. };
  9026. Buffer.prototype.get = function get(i) {
  9027. if (i < 0 || i >= this.length) throw new Error('oob');
  9028. return this.parent[this.offset + i];
  9029. };
  9030. Buffer.prototype.set = function set(i, v) {
  9031. if (i < 0 || i >= this.length) throw new Error('oob');
  9032. return this.parent[this.offset + i] = v;
  9033. };
  9034. // write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8')
  9035. Buffer.prototype.write = function(string, offset, length, encoding) {
  9036. // Support both (string, offset, length, encoding)
  9037. // and the legacy (string, encoding, offset, length)
  9038. if (isFinite(offset)) {
  9039. if (!isFinite(length)) {
  9040. encoding = length;
  9041. length = undefined;
  9042. }
  9043. } else { // legacy
  9044. var swap = encoding;
  9045. encoding = offset;
  9046. offset = length;
  9047. length = swap;
  9048. }
  9049. offset = +offset || 0;
  9050. var remaining = this.length - offset;
  9051. if (!length) {
  9052. length = remaining;
  9053. } else {
  9054. length = +length;
  9055. if (length > remaining) {
  9056. length = remaining;
  9057. }
  9058. }
  9059. encoding = String(encoding || 'utf8').toLowerCase();
  9060. var ret;
  9061. switch (encoding) {
  9062. case 'hex':
  9063. ret = this.parent.hexWrite(string, this.offset + offset, length);
  9064. break;
  9065. case 'utf8':
  9066. case 'utf-8':
  9067. ret = this.parent.utf8Write(string, this.offset + offset, length);
  9068. break;
  9069. case 'ascii':
  9070. ret = this.parent.asciiWrite(string, this.offset + offset, length);
  9071. break;
  9072. case 'binary':
  9073. ret = this.parent.binaryWrite(string, this.offset + offset, length);
  9074. break;
  9075. case 'base64':
  9076. // Warning: maxLength not taken into account in base64Write
  9077. ret = this.parent.base64Write(string, this.offset + offset, length);
  9078. break;
  9079. case 'ucs2':
  9080. case 'ucs-2':
  9081. ret = this.parent.ucs2Write(string, this.offset + offset, length);
  9082. break;
  9083. default:
  9084. throw new Error('Unknown encoding');
  9085. }
  9086. Buffer._charsWritten = SlowBuffer._charsWritten;
  9087. return ret;
  9088. };
  9089. // toString(encoding, start=0, end=buffer.length)
  9090. Buffer.prototype.toString = function(encoding, start, end) {
  9091. encoding = String(encoding || 'utf8').toLowerCase();
  9092. if (typeof start == 'undefined' || start < 0) {
  9093. start = 0;
  9094. } else if (start > this.length) {
  9095. start = this.length;
  9096. }
  9097. if (typeof end == 'undefined' || end > this.length) {
  9098. end = this.length;
  9099. } else if (end < 0) {
  9100. end = 0;
  9101. }
  9102. start = start + this.offset;
  9103. end = end + this.offset;
  9104. switch (encoding) {
  9105. case 'hex':
  9106. return this.parent.hexSlice(start, end);
  9107. case 'utf8':
  9108. case 'utf-8':
  9109. return this.parent.utf8Slice(start, end);
  9110. case 'ascii':
  9111. return this.parent.asciiSlice(start, end);
  9112. case 'binary':
  9113. return this.parent.binarySlice(start, end);
  9114. case 'base64':
  9115. return this.parent.base64Slice(start, end);
  9116. case 'ucs2':
  9117. case 'ucs-2':
  9118. return this.parent.ucs2Slice(start, end);
  9119. default:
  9120. throw new Error('Unknown encoding');
  9121. }
  9122. };
  9123. // byteLength
  9124. Buffer.byteLength = SlowBuffer.byteLength;
  9125. // fill(value, start=0, end=buffer.length)
  9126. Buffer.prototype.fill = function fill(value, start, end) {
  9127. value || (value = 0);
  9128. start || (start = 0);
  9129. end || (end = this.length);
  9130. if (typeof value === 'string') {
  9131. value = value.charCodeAt(0);
  9132. }
  9133. if (!(typeof value === 'number') || isNaN(value)) {
  9134. throw new Error('value is not a number');
  9135. }
  9136. if (end < start) throw new Error('end < start');
  9137. // Fill 0 bytes; we're done
  9138. if (end === start) return 0;
  9139. if (this.length == 0) return 0;
  9140. if (start < 0 || start >= this.length) {
  9141. throw new Error('start out of bounds');
  9142. }
  9143. if (end < 0 || end > this.length) {
  9144. throw new Error('end out of bounds');
  9145. }
  9146. return this.parent.fill(value,
  9147. start + this.offset,
  9148. end + this.offset);
  9149. };
  9150. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  9151. Buffer.prototype.copy = function(target, target_start, start, end) {
  9152. var source = this;
  9153. start || (start = 0);
  9154. end || (end = this.length);
  9155. target_start || (target_start = 0);
  9156. if (end < start) throw new Error('sourceEnd < sourceStart');
  9157. // Copy 0 bytes; we're done
  9158. if (end === start) return 0;
  9159. if (target.length == 0 || source.length == 0) return 0;
  9160. if (target_start < 0 || target_start >= target.length) {
  9161. throw new Error('targetStart out of bounds');
  9162. }
  9163. if (start < 0 || start >= source.length) {
  9164. throw new Error('sourceStart out of bounds');
  9165. }
  9166. if (end < 0 || end > source.length) {
  9167. throw new Error('sourceEnd out of bounds');
  9168. }
  9169. // Are we oob?
  9170. if (end > this.length) {
  9171. end = this.length;
  9172. }
  9173. if (target.length - target_start < end - start) {
  9174. end = target.length - target_start + start;
  9175. }
  9176. return this.parent.copy(target.parent,
  9177. target_start + target.offset,
  9178. start + this.offset,
  9179. end + this.offset);
  9180. };
  9181. // slice(start, end)
  9182. Buffer.prototype.slice = function(start, end) {
  9183. if (end === undefined) end = this.length;
  9184. if (end > this.length) throw new Error('oob');
  9185. if (start > end) throw new Error('oob');
  9186. return new Buffer(this.parent, end - start, +start + this.offset);
  9187. };
  9188. // Legacy methods for backwards compatibility.
  9189. Buffer.prototype.utf8Slice = function(start, end) {
  9190. return this.toString('utf8', start, end);
  9191. };
  9192. Buffer.prototype.binarySlice = function(start, end) {
  9193. return this.toString('binary', start, end);
  9194. };
  9195. Buffer.prototype.asciiSlice = function(start, end) {
  9196. return this.toString('ascii', start, end);
  9197. };
  9198. Buffer.prototype.utf8Write = function(string, offset) {
  9199. return this.write(string, offset, 'utf8');
  9200. };
  9201. Buffer.prototype.binaryWrite = function(string, offset) {
  9202. return this.write(string, offset, 'binary');
  9203. };
  9204. Buffer.prototype.asciiWrite = function(string, offset) {
  9205. return this.write(string, offset, 'ascii');
  9206. };
  9207. Buffer.prototype.readUInt8 = function(offset, noAssert) {
  9208. var buffer = this;
  9209. if (!noAssert) {
  9210. assert.ok(offset !== undefined && offset !== null,
  9211. 'missing offset');
  9212. assert.ok(offset < buffer.length,
  9213. 'Trying to read beyond buffer length');
  9214. }
  9215. if (offset >= buffer.length) return;
  9216. return buffer.parent[buffer.offset + offset];
  9217. };
  9218. function readUInt16(buffer, offset, isBigEndian, noAssert) {
  9219. var val = 0;
  9220. if (!noAssert) {
  9221. assert.ok(typeof (isBigEndian) === 'boolean',
  9222. 'missing or invalid endian');
  9223. assert.ok(offset !== undefined && offset !== null,
  9224. 'missing offset');
  9225. assert.ok(offset + 1 < buffer.length,
  9226. 'Trying to read beyond buffer length');
  9227. }
  9228. if (offset >= buffer.length) return 0;
  9229. if (isBigEndian) {
  9230. val = buffer.parent[buffer.offset + offset] << 8;
  9231. if (offset + 1 < buffer.length) {
  9232. val |= buffer.parent[buffer.offset + offset + 1];
  9233. }
  9234. } else {
  9235. val = buffer.parent[buffer.offset + offset];
  9236. if (offset + 1 < buffer.length) {
  9237. val |= buffer.parent[buffer.offset + offset + 1] << 8;
  9238. }
  9239. }
  9240. return val;
  9241. }
  9242. Buffer.prototype.readUInt16LE = function(offset, noAssert) {
  9243. return readUInt16(this, offset, false, noAssert);
  9244. };
  9245. Buffer.prototype.readUInt16BE = function(offset, noAssert) {
  9246. return readUInt16(this, offset, true, noAssert);
  9247. };
  9248. function readUInt32(buffer, offset, isBigEndian, noAssert) {
  9249. var val = 0;
  9250. if (!noAssert) {
  9251. assert.ok(typeof (isBigEndian) === 'boolean',
  9252. 'missing or invalid endian');
  9253. assert.ok(offset !== undefined && offset !== null,
  9254. 'missing offset');
  9255. assert.ok(offset + 3 < buffer.length,
  9256. 'Trying to read beyond buffer length');
  9257. }
  9258. if (offset >= buffer.length) return 0;
  9259. if (isBigEndian) {
  9260. if (offset + 1 < buffer.length)
  9261. val = buffer.parent[buffer.offset + offset + 1] << 16;
  9262. if (offset + 2 < buffer.length)
  9263. val |= buffer.parent[buffer.offset + offset + 2] << 8;
  9264. if (offset + 3 < buffer.length)
  9265. val |= buffer.parent[buffer.offset + offset + 3];
  9266. val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0);
  9267. } else {
  9268. if (offset + 2 < buffer.length)
  9269. val = buffer.parent[buffer.offset + offset + 2] << 16;
  9270. if (offset + 1 < buffer.length)
  9271. val |= buffer.parent[buffer.offset + offset + 1] << 8;
  9272. val |= buffer.parent[buffer.offset + offset];
  9273. if (offset + 3 < buffer.length)
  9274. val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0);
  9275. }
  9276. return val;
  9277. }
  9278. Buffer.prototype.readUInt32LE = function(offset, noAssert) {
  9279. return readUInt32(this, offset, false, noAssert);
  9280. };
  9281. Buffer.prototype.readUInt32BE = function(offset, noAssert) {
  9282. return readUInt32(this, offset, true, noAssert);
  9283. };
  9284. /*
  9285. * Signed integer types, yay team! A reminder on how two's complement actually
  9286. * works. The first bit is the signed bit, i.e. tells us whether or not the
  9287. * number should be positive or negative. If the two's complement value is
  9288. * positive, then we're done, as it's equivalent to the unsigned representation.
  9289. *
  9290. * Now if the number is positive, you're pretty much done, you can just leverage
  9291. * the unsigned translations and return those. Unfortunately, negative numbers
  9292. * aren't quite that straightforward.
  9293. *
  9294. * At first glance, one might be inclined to use the traditional formula to
  9295. * translate binary numbers between the positive and negative values in two's
  9296. * complement. (Though it doesn't quite work for the most negative value)
  9297. * Mainly:
  9298. * - invert all the bits
  9299. * - add one to the result
  9300. *
  9301. * Of course, this doesn't quite work in Javascript. Take for example the value
  9302. * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
  9303. * course, Javascript will do the following:
  9304. *
  9305. * > ~0xff80
  9306. * -65409
  9307. *
  9308. * Whoh there, Javascript, that's not quite right. But wait, according to
  9309. * Javascript that's perfectly correct. When Javascript ends up seeing the
  9310. * constant 0xff80, it has no notion that it is actually a signed number. It
  9311. * assumes that we've input the unsigned value 0xff80. Thus, when it does the
  9312. * binary negation, it casts it into a signed value, (positive 0xff80). Then
  9313. * when you perform binary negation on that, it turns it into a negative number.
  9314. *
  9315. * Instead, we're going to have to use the following general formula, that works
  9316. * in a rather Javascript friendly way. I'm glad we don't support this kind of
  9317. * weird numbering scheme in the kernel.
  9318. *
  9319. * (BIT-MAX - (unsigned)val + 1) * -1
  9320. *
  9321. * The astute observer, may think that this doesn't make sense for 8-bit numbers
  9322. * (really it isn't necessary for them). However, when you get 16-bit numbers,
  9323. * you do. Let's go back to our prior example and see how this will look:
  9324. *
  9325. * (0xffff - 0xff80 + 1) * -1
  9326. * (0x007f + 1) * -1
  9327. * (0x0080) * -1
  9328. */
  9329. Buffer.prototype.readInt8 = function(offset, noAssert) {
  9330. var buffer = this;
  9331. var neg;
  9332. if (!noAssert) {
  9333. assert.ok(offset !== undefined && offset !== null,
  9334. 'missing offset');
  9335. assert.ok(offset < buffer.length,
  9336. 'Trying to read beyond buffer length');
  9337. }
  9338. if (offset >= buffer.length) return;
  9339. neg = buffer.parent[buffer.offset + offset] & 0x80;
  9340. if (!neg) {
  9341. return (buffer.parent[buffer.offset + offset]);
  9342. }
  9343. return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1);
  9344. };
  9345. function readInt16(buffer, offset, isBigEndian, noAssert) {
  9346. var neg, val;
  9347. if (!noAssert) {
  9348. assert.ok(typeof (isBigEndian) === 'boolean',
  9349. 'missing or invalid endian');
  9350. assert.ok(offset !== undefined && offset !== null,
  9351. 'missing offset');
  9352. assert.ok(offset + 1 < buffer.length,
  9353. 'Trying to read beyond buffer length');
  9354. }
  9355. val = readUInt16(buffer, offset, isBigEndian, noAssert);
  9356. neg = val & 0x8000;
  9357. if (!neg) {
  9358. return val;
  9359. }
  9360. return (0xffff - val + 1) * -1;
  9361. }
  9362. Buffer.prototype.readInt16LE = function(offset, noAssert) {
  9363. return readInt16(this, offset, false, noAssert);
  9364. };
  9365. Buffer.prototype.readInt16BE = function(offset, noAssert) {
  9366. return readInt16(this, offset, true, noAssert);
  9367. };
  9368. function readInt32(buffer, offset, isBigEndian, noAssert) {
  9369. var neg, val;
  9370. if (!noAssert) {
  9371. assert.ok(typeof (isBigEndian) === 'boolean',
  9372. 'missing or invalid endian');
  9373. assert.ok(offset !== undefined && offset !== null,
  9374. 'missing offset');
  9375. assert.ok(offset + 3 < buffer.length,
  9376. 'Trying to read beyond buffer length');
  9377. }
  9378. val = readUInt32(buffer, offset, isBigEndian, noAssert);
  9379. neg = val & 0x80000000;
  9380. if (!neg) {
  9381. return (val);
  9382. }
  9383. return (0xffffffff - val + 1) * -1;
  9384. }
  9385. Buffer.prototype.readInt32LE = function(offset, noAssert) {
  9386. return readInt32(this, offset, false, noAssert);
  9387. };
  9388. Buffer.prototype.readInt32BE = function(offset, noAssert) {
  9389. return readInt32(this, offset, true, noAssert);
  9390. };
  9391. function readFloat(buffer, offset, isBigEndian, noAssert) {
  9392. if (!noAssert) {
  9393. assert.ok(typeof (isBigEndian) === 'boolean',
  9394. 'missing or invalid endian');
  9395. assert.ok(offset + 3 < buffer.length,
  9396. 'Trying to read beyond buffer length');
  9397. }
  9398. return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
  9399. 23, 4);
  9400. }
  9401. Buffer.prototype.readFloatLE = function(offset, noAssert) {
  9402. return readFloat(this, offset, false, noAssert);
  9403. };
  9404. Buffer.prototype.readFloatBE = function(offset, noAssert) {
  9405. return readFloat(this, offset, true, noAssert);
  9406. };
  9407. function readDouble(buffer, offset, isBigEndian, noAssert) {
  9408. if (!noAssert) {
  9409. assert.ok(typeof (isBigEndian) === 'boolean',
  9410. 'missing or invalid endian');
  9411. assert.ok(offset + 7 < buffer.length,
  9412. 'Trying to read beyond buffer length');
  9413. }
  9414. return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
  9415. 52, 8);
  9416. }
  9417. Buffer.prototype.readDoubleLE = function(offset, noAssert) {
  9418. return readDouble(this, offset, false, noAssert);
  9419. };
  9420. Buffer.prototype.readDoubleBE = function(offset, noAssert) {
  9421. return readDouble(this, offset, true, noAssert);
  9422. };
  9423. /*
  9424. * We have to make sure that the value is a valid integer. This means that it is
  9425. * non-negative. It has no fractional component and that it does not exceed the
  9426. * maximum allowed value.
  9427. *
  9428. * value The number to check for validity
  9429. *
  9430. * max The maximum value
  9431. */
  9432. function verifuint(value, max) {
  9433. assert.ok(typeof (value) == 'number',
  9434. 'cannot write a non-number as a number');
  9435. assert.ok(value >= 0,
  9436. 'specified a negative value for writing an unsigned value');
  9437. assert.ok(value <= max, 'value is larger than maximum value for type');
  9438. assert.ok(Math.floor(value) === value, 'value has a fractional component');
  9439. }
  9440. Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
  9441. var buffer = this;
  9442. if (!noAssert) {
  9443. assert.ok(value !== undefined && value !== null,
  9444. 'missing value');
  9445. assert.ok(offset !== undefined && offset !== null,
  9446. 'missing offset');
  9447. assert.ok(offset < buffer.length,
  9448. 'trying to write beyond buffer length');
  9449. verifuint(value, 0xff);
  9450. }
  9451. if (offset < buffer.length) {
  9452. buffer.parent[buffer.offset + offset] = value;
  9453. }
  9454. };
  9455. function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
  9456. if (!noAssert) {
  9457. assert.ok(value !== undefined && value !== null,
  9458. 'missing value');
  9459. assert.ok(typeof (isBigEndian) === 'boolean',
  9460. 'missing or invalid endian');
  9461. assert.ok(offset !== undefined && offset !== null,
  9462. 'missing offset');
  9463. assert.ok(offset + 1 < buffer.length,
  9464. 'trying to write beyond buffer length');
  9465. verifuint(value, 0xffff);
  9466. }
  9467. for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) {
  9468. buffer.parent[buffer.offset + offset + i] =
  9469. (value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>>
  9470. (isBigEndian ? 1 - i : i) * 8;
  9471. }
  9472. }
  9473. Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
  9474. writeUInt16(this, value, offset, false, noAssert);
  9475. };
  9476. Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
  9477. writeUInt16(this, value, offset, true, noAssert);
  9478. };
  9479. function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
  9480. if (!noAssert) {
  9481. assert.ok(value !== undefined && value !== null,
  9482. 'missing value');
  9483. assert.ok(typeof (isBigEndian) === 'boolean',
  9484. 'missing or invalid endian');
  9485. assert.ok(offset !== undefined && offset !== null,
  9486. 'missing offset');
  9487. assert.ok(offset + 3 < buffer.length,
  9488. 'trying to write beyond buffer length');
  9489. verifuint(value, 0xffffffff);
  9490. }
  9491. for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) {
  9492. buffer.parent[buffer.offset + offset + i] =
  9493. (value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff;
  9494. }
  9495. }
  9496. Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
  9497. writeUInt32(this, value, offset, false, noAssert);
  9498. };
  9499. Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
  9500. writeUInt32(this, value, offset, true, noAssert);
  9501. };
  9502. /*
  9503. * We now move onto our friends in the signed number category. Unlike unsigned
  9504. * numbers, we're going to have to worry a bit more about how we put values into
  9505. * arrays. Since we are only worrying about signed 32-bit values, we're in
  9506. * slightly better shape. Unfortunately, we really can't do our favorite binary
  9507. * & in this system. It really seems to do the wrong thing. For example:
  9508. *
  9509. * > -32 & 0xff
  9510. * 224
  9511. *
  9512. * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
  9513. * this aren't treated as a signed number. Ultimately a bad thing.
  9514. *
  9515. * What we're going to want to do is basically create the unsigned equivalent of
  9516. * our representation and pass that off to the wuint* functions. To do that
  9517. * we're going to do the following:
  9518. *
  9519. * - if the value is positive
  9520. * we can pass it directly off to the equivalent wuint
  9521. * - if the value is negative
  9522. * we do the following computation:
  9523. * mb + val + 1, where
  9524. * mb is the maximum unsigned value in that byte size
  9525. * val is the Javascript negative integer
  9526. *
  9527. *
  9528. * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
  9529. * you do out the computations:
  9530. *
  9531. * 0xffff - 128 + 1
  9532. * 0xffff - 127
  9533. * 0xff80
  9534. *
  9535. * You can then encode this value as the signed version. This is really rather
  9536. * hacky, but it should work and get the job done which is our goal here.
  9537. */
  9538. /*
  9539. * A series of checks to make sure we actually have a signed 32-bit number
  9540. */
  9541. function verifsint(value, max, min) {
  9542. assert.ok(typeof (value) == 'number',
  9543. 'cannot write a non-number as a number');
  9544. assert.ok(value <= max, 'value larger than maximum allowed value');
  9545. assert.ok(value >= min, 'value smaller than minimum allowed value');
  9546. assert.ok(Math.floor(value) === value, 'value has a fractional component');
  9547. }
  9548. function verifIEEE754(value, max, min) {
  9549. assert.ok(typeof (value) == 'number',
  9550. 'cannot write a non-number as a number');
  9551. assert.ok(value <= max, 'value larger than maximum allowed value');
  9552. assert.ok(value >= min, 'value smaller than minimum allowed value');
  9553. }
  9554. Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
  9555. var buffer = this;
  9556. if (!noAssert) {
  9557. assert.ok(value !== undefined && value !== null,
  9558. 'missing value');
  9559. assert.ok(offset !== undefined && offset !== null,
  9560. 'missing offset');
  9561. assert.ok(offset < buffer.length,
  9562. 'Trying to write beyond buffer length');
  9563. verifsint(value, 0x7f, -0x80);
  9564. }
  9565. if (value >= 0) {
  9566. buffer.writeUInt8(value, offset, noAssert);
  9567. } else {
  9568. buffer.writeUInt8(0xff + value + 1, offset, noAssert);
  9569. }
  9570. };
  9571. function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
  9572. if (!noAssert) {
  9573. assert.ok(value !== undefined && value !== null,
  9574. 'missing value');
  9575. assert.ok(typeof (isBigEndian) === 'boolean',
  9576. 'missing or invalid endian');
  9577. assert.ok(offset !== undefined && offset !== null,
  9578. 'missing offset');
  9579. assert.ok(offset + 1 < buffer.length,
  9580. 'Trying to write beyond buffer length');
  9581. verifsint(value, 0x7fff, -0x8000);
  9582. }
  9583. if (value >= 0) {
  9584. writeUInt16(buffer, value, offset, isBigEndian, noAssert);
  9585. } else {
  9586. writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
  9587. }
  9588. }
  9589. Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
  9590. writeInt16(this, value, offset, false, noAssert);
  9591. };
  9592. Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
  9593. writeInt16(this, value, offset, true, noAssert);
  9594. };
  9595. function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
  9596. if (!noAssert) {
  9597. assert.ok(value !== undefined && value !== null,
  9598. 'missing value');
  9599. assert.ok(typeof (isBigEndian) === 'boolean',
  9600. 'missing or invalid endian');
  9601. assert.ok(offset !== undefined && offset !== null,
  9602. 'missing offset');
  9603. assert.ok(offset + 3 < buffer.length,
  9604. 'Trying to write beyond buffer length');
  9605. verifsint(value, 0x7fffffff, -0x80000000);
  9606. }
  9607. if (value >= 0) {
  9608. writeUInt32(buffer, value, offset, isBigEndian, noAssert);
  9609. } else {
  9610. writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
  9611. }
  9612. }
  9613. Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
  9614. writeInt32(this, value, offset, false, noAssert);
  9615. };
  9616. Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
  9617. writeInt32(this, value, offset, true, noAssert);
  9618. };
  9619. function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
  9620. if (!noAssert) {
  9621. assert.ok(value !== undefined && value !== null,
  9622. 'missing value');
  9623. assert.ok(typeof (isBigEndian) === 'boolean',
  9624. 'missing or invalid endian');
  9625. assert.ok(offset !== undefined && offset !== null,
  9626. 'missing offset');
  9627. assert.ok(offset + 3 < buffer.length,
  9628. 'Trying to write beyond buffer length');
  9629. verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
  9630. }
  9631. require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
  9632. 23, 4);
  9633. }
  9634. Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
  9635. writeFloat(this, value, offset, false, noAssert);
  9636. };
  9637. Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
  9638. writeFloat(this, value, offset, true, noAssert);
  9639. };
  9640. function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
  9641. if (!noAssert) {
  9642. assert.ok(value !== undefined && value !== null,
  9643. 'missing value');
  9644. assert.ok(typeof (isBigEndian) === 'boolean',
  9645. 'missing or invalid endian');
  9646. assert.ok(offset !== undefined && offset !== null,
  9647. 'missing offset');
  9648. assert.ok(offset + 7 < buffer.length,
  9649. 'Trying to write beyond buffer length');
  9650. verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
  9651. }
  9652. require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
  9653. 52, 8);
  9654. }
  9655. Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
  9656. writeDouble(this, value, offset, false, noAssert);
  9657. };
  9658. Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
  9659. writeDouble(this, value, offset, true, noAssert);
  9660. };
  9661. SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8;
  9662. SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE;
  9663. SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE;
  9664. SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE;
  9665. SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE;
  9666. SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8;
  9667. SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE;
  9668. SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE;
  9669. SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE;
  9670. SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE;
  9671. SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE;
  9672. SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE;
  9673. SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE;
  9674. SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE;
  9675. SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8;
  9676. SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE;
  9677. SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE;
  9678. SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE;
  9679. SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE;
  9680. SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8;
  9681. SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE;
  9682. SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE;
  9683. SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE;
  9684. SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE;
  9685. SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE;
  9686. SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE;
  9687. SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE;
  9688. SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE;
  9689. })()
  9690. },{"assert":12,"./buffer_ieee754":14,"base64-js":15}],15:[function(require,module,exports){
  9691. (function (exports) {
  9692. 'use strict';
  9693. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  9694. function b64ToByteArray(b64) {
  9695. var i, j, l, tmp, placeHolders, arr;
  9696. if (b64.length % 4 > 0) {
  9697. throw 'Invalid string. Length must be a multiple of 4';
  9698. }
  9699. // the number of equal signs (place holders)
  9700. // if there are two placeholders, than the two characters before it
  9701. // represent one byte
  9702. // if there is only one, then the three characters before it represent 2 bytes
  9703. // this is just a cheap hack to not do indexOf twice
  9704. placeHolders = b64.indexOf('=');
  9705. placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
  9706. // base64 is 4/3 + up to two characters of the original data
  9707. arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
  9708. // if there are placeholders, only get up to the last complete 4 chars
  9709. l = placeHolders > 0 ? b64.length - 4 : b64.length;
  9710. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  9711. tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
  9712. arr.push((tmp & 0xFF0000) >> 16);
  9713. arr.push((tmp & 0xFF00) >> 8);
  9714. arr.push(tmp & 0xFF);
  9715. }
  9716. if (placeHolders === 2) {
  9717. tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
  9718. arr.push(tmp & 0xFF);
  9719. } else if (placeHolders === 1) {
  9720. tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
  9721. arr.push((tmp >> 8) & 0xFF);
  9722. arr.push(tmp & 0xFF);
  9723. }
  9724. return arr;
  9725. }
  9726. function uint8ToBase64(uint8) {
  9727. var i,
  9728. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  9729. output = "",
  9730. temp, length;
  9731. function tripletToBase64 (num) {
  9732. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  9733. };
  9734. // go through the array every three bytes, we'll deal with trailing stuff later
  9735. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  9736. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  9737. output += tripletToBase64(temp);
  9738. }
  9739. // pad the end with zeros, but make sure to not forget the extra bytes
  9740. switch (extraBytes) {
  9741. case 1:
  9742. temp = uint8[uint8.length - 1];
  9743. output += lookup[temp >> 2];
  9744. output += lookup[(temp << 4) & 0x3F];
  9745. output += '==';
  9746. break;
  9747. case 2:
  9748. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
  9749. output += lookup[temp >> 10];
  9750. output += lookup[(temp >> 4) & 0x3F];
  9751. output += lookup[(temp << 2) & 0x3F];
  9752. output += '=';
  9753. break;
  9754. }
  9755. return output;
  9756. }
  9757. module.exports.toByteArray = b64ToByteArray;
  9758. module.exports.fromByteArray = uint8ToBase64;
  9759. }());
  9760. },{}]},{},["PeVhMp"])
  9761. ;
  9762. JSHINT = require('jshint').JSHINT;
  9763. }());