jshint.js 328 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660
  1. define(function(require, exports, module) {
  2. module.exports = (function outer (modules, cache, entry) {
  3. var previousRequire = typeof require == "function" && require;
  4. function newRequire(name, jumped){
  5. if(!cache[name]) {
  6. if(!modules[name]) {
  7. var currentRequire = typeof require == "function" && require;
  8. if (!jumped && currentRequire) return currentRequire(name, true);
  9. if (previousRequire) return previousRequire(name, true);
  10. var err = new Error('Cannot find module \'' + name + '\'');
  11. err.code = 'MODULE_NOT_FOUND';
  12. throw err;
  13. }
  14. var m = cache[name] = {exports:{}};
  15. modules[name][0].call(m.exports, function(x){
  16. var id = modules[name][1][x];
  17. return newRequire(id ? id : x);
  18. },m,m.exports,outer,modules,cache,entry);
  19. }
  20. return cache[name].exports;
  21. }
  22. for(var i=0;i<entry.length;i++) newRequire(entry[i]);
  23. return newRequire(entry[0]);
  24. })
  25. ({"/node_modules/browserify/node_modules/events/events.js":[function(_dereq_,module,exports){
  26. // Copyright Joyent, Inc. and other Node contributors.
  27. //
  28. // Permission is hereby granted, free of charge, to any person obtaining a
  29. // copy of this software and associated documentation files (the
  30. // "Software"), to deal in the Software without restriction, including
  31. // without limitation the rights to use, copy, modify, merge, publish,
  32. // distribute, sublicense, and/or sell copies of the Software, and to permit
  33. // persons to whom the Software is furnished to do so, subject to the
  34. // following conditions:
  35. //
  36. // The above copyright notice and this permission notice shall be included
  37. // in all copies or substantial portions of the Software.
  38. //
  39. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  40. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  41. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  42. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  43. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  44. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  45. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  46. function EventEmitter() {
  47. this._events = this._events || {};
  48. this._maxListeners = this._maxListeners || undefined;
  49. }
  50. module.exports = EventEmitter;
  51. // Backwards-compat with node 0.10.x
  52. EventEmitter.EventEmitter = EventEmitter;
  53. EventEmitter.prototype._events = undefined;
  54. EventEmitter.prototype._maxListeners = undefined;
  55. // By default EventEmitters will print a warning if more than 10 listeners are
  56. // added to it. This is a useful default which helps finding memory leaks.
  57. EventEmitter.defaultMaxListeners = 10;
  58. // Obviously not all Emitters should be limited to 10. This function allows
  59. // that to be increased. Set to zero for unlimited.
  60. EventEmitter.prototype.setMaxListeners = function(n) {
  61. if (!isNumber(n) || n < 0 || isNaN(n))
  62. throw TypeError('n must be a positive number');
  63. this._maxListeners = n;
  64. return this;
  65. };
  66. EventEmitter.prototype.emit = function(type) {
  67. var er, handler, len, args, i, listeners;
  68. if (!this._events)
  69. this._events = {};
  70. // If there is no 'error' event listener then throw.
  71. if (type === 'error') {
  72. if (!this._events.error ||
  73. (isObject(this._events.error) && !this._events.error.length)) {
  74. er = arguments[1];
  75. if (er instanceof Error) {
  76. throw er; // Unhandled 'error' event
  77. }
  78. throw TypeError('Uncaught, unspecified "error" event.');
  79. }
  80. }
  81. handler = this._events[type];
  82. if (isUndefined(handler))
  83. return false;
  84. if (isFunction(handler)) {
  85. switch (arguments.length) {
  86. // fast cases
  87. case 1:
  88. handler.call(this);
  89. break;
  90. case 2:
  91. handler.call(this, arguments[1]);
  92. break;
  93. case 3:
  94. handler.call(this, arguments[1], arguments[2]);
  95. break;
  96. // slower
  97. default:
  98. len = arguments.length;
  99. args = new Array(len - 1);
  100. for (i = 1; i < len; i++)
  101. args[i - 1] = arguments[i];
  102. handler.apply(this, args);
  103. }
  104. } else if (isObject(handler)) {
  105. len = arguments.length;
  106. args = new Array(len - 1);
  107. for (i = 1; i < len; i++)
  108. args[i - 1] = arguments[i];
  109. listeners = handler.slice();
  110. len = listeners.length;
  111. for (i = 0; i < len; i++)
  112. listeners[i].apply(this, args);
  113. }
  114. return true;
  115. };
  116. EventEmitter.prototype.addListener = function(type, listener) {
  117. var m;
  118. if (!isFunction(listener))
  119. throw TypeError('listener must be a function');
  120. if (!this._events)
  121. this._events = {};
  122. // To avoid recursion in the case that type === "newListener"! Before
  123. // adding it to the listeners, first emit "newListener".
  124. if (this._events.newListener)
  125. this.emit('newListener', type,
  126. isFunction(listener.listener) ?
  127. listener.listener : listener);
  128. if (!this._events[type])
  129. // Optimize the case of one listener. Don't need the extra array object.
  130. this._events[type] = listener;
  131. else if (isObject(this._events[type]))
  132. // If we've already got an array, just append.
  133. this._events[type].push(listener);
  134. else
  135. // Adding the second element, need to change to array.
  136. this._events[type] = [this._events[type], listener];
  137. // Check for listener leak
  138. if (isObject(this._events[type]) && !this._events[type].warned) {
  139. var m;
  140. if (!isUndefined(this._maxListeners)) {
  141. m = this._maxListeners;
  142. } else {
  143. m = EventEmitter.defaultMaxListeners;
  144. }
  145. if (m && m > 0 && this._events[type].length > m) {
  146. this._events[type].warned = true;
  147. console.error('(node) warning: possible EventEmitter memory ' +
  148. 'leak detected. %d listeners added. ' +
  149. 'Use emitter.setMaxListeners() to increase limit.',
  150. this._events[type].length);
  151. if (typeof console.trace === 'function') {
  152. // not supported in IE 10
  153. console.trace();
  154. }
  155. }
  156. }
  157. return this;
  158. };
  159. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  160. EventEmitter.prototype.once = function(type, listener) {
  161. if (!isFunction(listener))
  162. throw TypeError('listener must be a function');
  163. var fired = false;
  164. function g() {
  165. this.removeListener(type, g);
  166. if (!fired) {
  167. fired = true;
  168. listener.apply(this, arguments);
  169. }
  170. }
  171. g.listener = listener;
  172. this.on(type, g);
  173. return this;
  174. };
  175. // emits a 'removeListener' event iff the listener was removed
  176. EventEmitter.prototype.removeListener = function(type, listener) {
  177. var list, position, length, i;
  178. if (!isFunction(listener))
  179. throw TypeError('listener must be a function');
  180. if (!this._events || !this._events[type])
  181. return this;
  182. list = this._events[type];
  183. length = list.length;
  184. position = -1;
  185. if (list === listener ||
  186. (isFunction(list.listener) && list.listener === listener)) {
  187. delete this._events[type];
  188. if (this._events.removeListener)
  189. this.emit('removeListener', type, listener);
  190. } else if (isObject(list)) {
  191. for (i = length; i-- > 0;) {
  192. if (list[i] === listener ||
  193. (list[i].listener && list[i].listener === listener)) {
  194. position = i;
  195. break;
  196. }
  197. }
  198. if (position < 0)
  199. return this;
  200. if (list.length === 1) {
  201. list.length = 0;
  202. delete this._events[type];
  203. } else {
  204. list.splice(position, 1);
  205. }
  206. if (this._events.removeListener)
  207. this.emit('removeListener', type, listener);
  208. }
  209. return this;
  210. };
  211. EventEmitter.prototype.removeAllListeners = function(type) {
  212. var key, listeners;
  213. if (!this._events)
  214. return this;
  215. // not listening for removeListener, no need to emit
  216. if (!this._events.removeListener) {
  217. if (arguments.length === 0)
  218. this._events = {};
  219. else if (this._events[type])
  220. delete this._events[type];
  221. return this;
  222. }
  223. // emit removeListener for all listeners on all events
  224. if (arguments.length === 0) {
  225. for (key in this._events) {
  226. if (key === 'removeListener') continue;
  227. this.removeAllListeners(key);
  228. }
  229. this.removeAllListeners('removeListener');
  230. this._events = {};
  231. return this;
  232. }
  233. listeners = this._events[type];
  234. if (isFunction(listeners)) {
  235. this.removeListener(type, listeners);
  236. } else {
  237. // LIFO order
  238. while (listeners.length)
  239. this.removeListener(type, listeners[listeners.length - 1]);
  240. }
  241. delete this._events[type];
  242. return this;
  243. };
  244. EventEmitter.prototype.listeners = function(type) {
  245. var ret;
  246. if (!this._events || !this._events[type])
  247. ret = [];
  248. else if (isFunction(this._events[type]))
  249. ret = [this._events[type]];
  250. else
  251. ret = this._events[type].slice();
  252. return ret;
  253. };
  254. EventEmitter.listenerCount = function(emitter, type) {
  255. var ret;
  256. if (!emitter._events || !emitter._events[type])
  257. ret = 0;
  258. else if (isFunction(emitter._events[type]))
  259. ret = 1;
  260. else
  261. ret = emitter._events[type].length;
  262. return ret;
  263. };
  264. function isFunction(arg) {
  265. return typeof arg === 'function';
  266. }
  267. function isNumber(arg) {
  268. return typeof arg === 'number';
  269. }
  270. function isObject(arg) {
  271. return typeof arg === 'object' && arg !== null;
  272. }
  273. function isUndefined(arg) {
  274. return arg === void 0;
  275. }
  276. },{}],"/node_modules/jshint/data/ascii-identifier-data.js":[function(_dereq_,module,exports){
  277. var identifierStartTable = [];
  278. for (var i = 0; i < 128; i++) {
  279. identifierStartTable[i] =
  280. i === 36 || // $
  281. i >= 65 && i <= 90 || // A-Z
  282. i === 95 || // _
  283. i >= 97 && i <= 122; // a-z
  284. }
  285. var identifierPartTable = [];
  286. for (var i = 0; i < 128; i++) {
  287. identifierPartTable[i] =
  288. identifierStartTable[i] || // $, _, A-Z, a-z
  289. i >= 48 && i <= 57; // 0-9
  290. }
  291. module.exports = {
  292. asciiIdentifierStartTable: identifierStartTable,
  293. asciiIdentifierPartTable: identifierPartTable
  294. };
  295. },{}],"/node_modules/jshint/node_modules/underscore/underscore.js":[function(_dereq_,module,exports){
  296. // Underscore.js 1.8.3
  297. // http://underscorejs.org
  298. // (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  299. // Underscore may be freely distributed under the MIT license.
  300. (function() {
  301. // Baseline setup
  302. // --------------
  303. // Establish the root object, `window` in the browser, or `exports` on the server.
  304. var root = this;
  305. // Save the previous value of the `_` variable.
  306. var previousUnderscore = root._;
  307. // Save bytes in the minified (but not gzipped) version:
  308. var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
  309. // Create quick reference variables for speed access to core prototypes.
  310. var
  311. push = ArrayProto.push,
  312. slice = ArrayProto.slice,
  313. toString = ObjProto.toString,
  314. hasOwnProperty = ObjProto.hasOwnProperty;
  315. // All **ECMAScript 5** native function implementations that we hope to use
  316. // are declared here.
  317. var
  318. nativeIsArray = Array.isArray,
  319. nativeKeys = Object.keys,
  320. nativeBind = FuncProto.bind,
  321. nativeCreate = Object.create;
  322. // Naked function reference for surrogate-prototype-swapping.
  323. var Ctor = function(){};
  324. // Create a safe reference to the Underscore object for use below.
  325. var _ = function(obj) {
  326. if (obj instanceof _) return obj;
  327. if (!(this instanceof _)) return new _(obj);
  328. this._wrapped = obj;
  329. };
  330. // Export the Underscore object for **Node.js**, with
  331. // backwards-compatibility for the old `require()` API. If we're in
  332. // the browser, add `_` as a global object.
  333. if (typeof exports !== 'undefined') {
  334. if (typeof module !== 'undefined' && module.exports) {
  335. exports = module.exports = _;
  336. }
  337. exports._ = _;
  338. } else {
  339. root._ = _;
  340. }
  341. // Current version.
  342. _.VERSION = '1.8.3';
  343. // Internal function that returns an efficient (for current engines) version
  344. // of the passed-in callback, to be repeatedly applied in other Underscore
  345. // functions.
  346. var optimizeCb = function(func, context, argCount) {
  347. if (context === void 0) return func;
  348. switch (argCount == null ? 3 : argCount) {
  349. case 1: return function(value) {
  350. return func.call(context, value);
  351. };
  352. case 2: return function(value, other) {
  353. return func.call(context, value, other);
  354. };
  355. case 3: return function(value, index, collection) {
  356. return func.call(context, value, index, collection);
  357. };
  358. case 4: return function(accumulator, value, index, collection) {
  359. return func.call(context, accumulator, value, index, collection);
  360. };
  361. }
  362. return function() {
  363. return func.apply(context, arguments);
  364. };
  365. };
  366. // A mostly-internal function to generate callbacks that can be applied
  367. // to each element in a collection, returning the desired result — either
  368. // identity, an arbitrary callback, a property matcher, or a property accessor.
  369. var cb = function(value, context, argCount) {
  370. if (value == null) return _.identity;
  371. if (_.isFunction(value)) return optimizeCb(value, context, argCount);
  372. if (_.isObject(value)) return _.matcher(value);
  373. return _.property(value);
  374. };
  375. _.iteratee = function(value, context) {
  376. return cb(value, context, Infinity);
  377. };
  378. // An internal function for creating assigner functions.
  379. var createAssigner = function(keysFunc, undefinedOnly) {
  380. return function(obj) {
  381. var length = arguments.length;
  382. if (length < 2 || obj == null) return obj;
  383. for (var index = 1; index < length; index++) {
  384. var source = arguments[index],
  385. keys = keysFunc(source),
  386. l = keys.length;
  387. for (var i = 0; i < l; i++) {
  388. var key = keys[i];
  389. if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key];
  390. }
  391. }
  392. return obj;
  393. };
  394. };
  395. // An internal function for creating a new object that inherits from another.
  396. var baseCreate = function(prototype) {
  397. if (!_.isObject(prototype)) return {};
  398. if (nativeCreate) return nativeCreate(prototype);
  399. Ctor.prototype = prototype;
  400. var result = new Ctor;
  401. Ctor.prototype = null;
  402. return result;
  403. };
  404. var property = function(key) {
  405. return function(obj) {
  406. return obj == null ? void 0 : obj[key];
  407. };
  408. };
  409. // Helper for collection methods to determine whether a collection
  410. // should be iterated as an array or as an object
  411. // Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
  412. // Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
  413. var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
  414. var getLength = property('length');
  415. var isArrayLike = function(collection) {
  416. var length = getLength(collection);
  417. return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
  418. };
  419. // Collection Functions
  420. // --------------------
  421. // The cornerstone, an `each` implementation, aka `forEach`.
  422. // Handles raw objects in addition to array-likes. Treats all
  423. // sparse array-likes as if they were dense.
  424. _.each = _.forEach = function(obj, iteratee, context) {
  425. iteratee = optimizeCb(iteratee, context);
  426. var i, length;
  427. if (isArrayLike(obj)) {
  428. for (i = 0, length = obj.length; i < length; i++) {
  429. iteratee(obj[i], i, obj);
  430. }
  431. } else {
  432. var keys = _.keys(obj);
  433. for (i = 0, length = keys.length; i < length; i++) {
  434. iteratee(obj[keys[i]], keys[i], obj);
  435. }
  436. }
  437. return obj;
  438. };
  439. // Return the results of applying the iteratee to each element.
  440. _.map = _.collect = function(obj, iteratee, context) {
  441. iteratee = cb(iteratee, context);
  442. var keys = !isArrayLike(obj) && _.keys(obj),
  443. length = (keys || obj).length,
  444. results = Array(length);
  445. for (var index = 0; index < length; index++) {
  446. var currentKey = keys ? keys[index] : index;
  447. results[index] = iteratee(obj[currentKey], currentKey, obj);
  448. }
  449. return results;
  450. };
  451. // Create a reducing function iterating left or right.
  452. function createReduce(dir) {
  453. // Optimized iterator function as using arguments.length
  454. // in the main function will deoptimize the, see #1991.
  455. function iterator(obj, iteratee, memo, keys, index, length) {
  456. for (; index >= 0 && index < length; index += dir) {
  457. var currentKey = keys ? keys[index] : index;
  458. memo = iteratee(memo, obj[currentKey], currentKey, obj);
  459. }
  460. return memo;
  461. }
  462. return function(obj, iteratee, memo, context) {
  463. iteratee = optimizeCb(iteratee, context, 4);
  464. var keys = !isArrayLike(obj) && _.keys(obj),
  465. length = (keys || obj).length,
  466. index = dir > 0 ? 0 : length - 1;
  467. // Determine the initial value if none is provided.
  468. if (arguments.length < 3) {
  469. memo = obj[keys ? keys[index] : index];
  470. index += dir;
  471. }
  472. return iterator(obj, iteratee, memo, keys, index, length);
  473. };
  474. }
  475. // **Reduce** builds up a single result from a list of values, aka `inject`,
  476. // or `foldl`.
  477. _.reduce = _.foldl = _.inject = createReduce(1);
  478. // The right-associative version of reduce, also known as `foldr`.
  479. _.reduceRight = _.foldr = createReduce(-1);
  480. // Return the first value which passes a truth test. Aliased as `detect`.
  481. _.find = _.detect = function(obj, predicate, context) {
  482. var key;
  483. if (isArrayLike(obj)) {
  484. key = _.findIndex(obj, predicate, context);
  485. } else {
  486. key = _.findKey(obj, predicate, context);
  487. }
  488. if (key !== void 0 && key !== -1) return obj[key];
  489. };
  490. // Return all the elements that pass a truth test.
  491. // Aliased as `select`.
  492. _.filter = _.select = function(obj, predicate, context) {
  493. var results = [];
  494. predicate = cb(predicate, context);
  495. _.each(obj, function(value, index, list) {
  496. if (predicate(value, index, list)) results.push(value);
  497. });
  498. return results;
  499. };
  500. // Return all the elements for which a truth test fails.
  501. _.reject = function(obj, predicate, context) {
  502. return _.filter(obj, _.negate(cb(predicate)), context);
  503. };
  504. // Determine whether all of the elements match a truth test.
  505. // Aliased as `all`.
  506. _.every = _.all = function(obj, predicate, context) {
  507. predicate = cb(predicate, context);
  508. var keys = !isArrayLike(obj) && _.keys(obj),
  509. length = (keys || obj).length;
  510. for (var index = 0; index < length; index++) {
  511. var currentKey = keys ? keys[index] : index;
  512. if (!predicate(obj[currentKey], currentKey, obj)) return false;
  513. }
  514. return true;
  515. };
  516. // Determine if at least one element in the object matches a truth test.
  517. // Aliased as `any`.
  518. _.some = _.any = function(obj, predicate, context) {
  519. predicate = cb(predicate, context);
  520. var keys = !isArrayLike(obj) && _.keys(obj),
  521. length = (keys || obj).length;
  522. for (var index = 0; index < length; index++) {
  523. var currentKey = keys ? keys[index] : index;
  524. if (predicate(obj[currentKey], currentKey, obj)) return true;
  525. }
  526. return false;
  527. };
  528. // Determine if the array or object contains a given item (using `===`).
  529. // Aliased as `includes` and `include`.
  530. _.contains = _.includes = _.include = function(obj, item, fromIndex, guard) {
  531. if (!isArrayLike(obj)) obj = _.values(obj);
  532. if (typeof fromIndex != 'number' || guard) fromIndex = 0;
  533. return _.indexOf(obj, item, fromIndex) >= 0;
  534. };
  535. // Invoke a method (with arguments) on every item in a collection.
  536. _.invoke = function(obj, method) {
  537. var args = slice.call(arguments, 2);
  538. var isFunc = _.isFunction(method);
  539. return _.map(obj, function(value) {
  540. var func = isFunc ? method : value[method];
  541. return func == null ? func : func.apply(value, args);
  542. });
  543. };
  544. // Convenience version of a common use case of `map`: fetching a property.
  545. _.pluck = function(obj, key) {
  546. return _.map(obj, _.property(key));
  547. };
  548. // Convenience version of a common use case of `filter`: selecting only objects
  549. // containing specific `key:value` pairs.
  550. _.where = function(obj, attrs) {
  551. return _.filter(obj, _.matcher(attrs));
  552. };
  553. // Convenience version of a common use case of `find`: getting the first object
  554. // containing specific `key:value` pairs.
  555. _.findWhere = function(obj, attrs) {
  556. return _.find(obj, _.matcher(attrs));
  557. };
  558. // Return the maximum element (or element-based computation).
  559. _.max = function(obj, iteratee, context) {
  560. var result = -Infinity, lastComputed = -Infinity,
  561. value, computed;
  562. if (iteratee == null && obj != null) {
  563. obj = isArrayLike(obj) ? obj : _.values(obj);
  564. for (var i = 0, length = obj.length; i < length; i++) {
  565. value = obj[i];
  566. if (value > result) {
  567. result = value;
  568. }
  569. }
  570. } else {
  571. iteratee = cb(iteratee, context);
  572. _.each(obj, function(value, index, list) {
  573. computed = iteratee(value, index, list);
  574. if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
  575. result = value;
  576. lastComputed = computed;
  577. }
  578. });
  579. }
  580. return result;
  581. };
  582. // Return the minimum element (or element-based computation).
  583. _.min = function(obj, iteratee, context) {
  584. var result = Infinity, lastComputed = Infinity,
  585. value, computed;
  586. if (iteratee == null && obj != null) {
  587. obj = isArrayLike(obj) ? obj : _.values(obj);
  588. for (var i = 0, length = obj.length; i < length; i++) {
  589. value = obj[i];
  590. if (value < result) {
  591. result = value;
  592. }
  593. }
  594. } else {
  595. iteratee = cb(iteratee, context);
  596. _.each(obj, function(value, index, list) {
  597. computed = iteratee(value, index, list);
  598. if (computed < lastComputed || computed === Infinity && result === Infinity) {
  599. result = value;
  600. lastComputed = computed;
  601. }
  602. });
  603. }
  604. return result;
  605. };
  606. // Shuffle a collection, using the modern version of the
  607. // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
  608. _.shuffle = function(obj) {
  609. var set = isArrayLike(obj) ? obj : _.values(obj);
  610. var length = set.length;
  611. var shuffled = Array(length);
  612. for (var index = 0, rand; index < length; index++) {
  613. rand = _.random(0, index);
  614. if (rand !== index) shuffled[index] = shuffled[rand];
  615. shuffled[rand] = set[index];
  616. }
  617. return shuffled;
  618. };
  619. // Sample **n** random values from a collection.
  620. // If **n** is not specified, returns a single random element.
  621. // The internal `guard` argument allows it to work with `map`.
  622. _.sample = function(obj, n, guard) {
  623. if (n == null || guard) {
  624. if (!isArrayLike(obj)) obj = _.values(obj);
  625. return obj[_.random(obj.length - 1)];
  626. }
  627. return _.shuffle(obj).slice(0, Math.max(0, n));
  628. };
  629. // Sort the object's values by a criterion produced by an iteratee.
  630. _.sortBy = function(obj, iteratee, context) {
  631. iteratee = cb(iteratee, context);
  632. return _.pluck(_.map(obj, function(value, index, list) {
  633. return {
  634. value: value,
  635. index: index,
  636. criteria: iteratee(value, index, list)
  637. };
  638. }).sort(function(left, right) {
  639. var a = left.criteria;
  640. var b = right.criteria;
  641. if (a !== b) {
  642. if (a > b || a === void 0) return 1;
  643. if (a < b || b === void 0) return -1;
  644. }
  645. return left.index - right.index;
  646. }), 'value');
  647. };
  648. // An internal function used for aggregate "group by" operations.
  649. var group = function(behavior) {
  650. return function(obj, iteratee, context) {
  651. var result = {};
  652. iteratee = cb(iteratee, context);
  653. _.each(obj, function(value, index) {
  654. var key = iteratee(value, index, obj);
  655. behavior(result, value, key);
  656. });
  657. return result;
  658. };
  659. };
  660. // Groups the object's values by a criterion. Pass either a string attribute
  661. // to group by, or a function that returns the criterion.
  662. _.groupBy = group(function(result, value, key) {
  663. if (_.has(result, key)) result[key].push(value); else result[key] = [value];
  664. });
  665. // Indexes the object's values by a criterion, similar to `groupBy`, but for
  666. // when you know that your index values will be unique.
  667. _.indexBy = group(function(result, value, key) {
  668. result[key] = value;
  669. });
  670. // Counts instances of an object that group by a certain criterion. Pass
  671. // either a string attribute to count by, or a function that returns the
  672. // criterion.
  673. _.countBy = group(function(result, value, key) {
  674. if (_.has(result, key)) result[key]++; else result[key] = 1;
  675. });
  676. // Safely create a real, live array from anything iterable.
  677. _.toArray = function(obj) {
  678. if (!obj) return [];
  679. if (_.isArray(obj)) return slice.call(obj);
  680. if (isArrayLike(obj)) return _.map(obj, _.identity);
  681. return _.values(obj);
  682. };
  683. // Return the number of elements in an object.
  684. _.size = function(obj) {
  685. if (obj == null) return 0;
  686. return isArrayLike(obj) ? obj.length : _.keys(obj).length;
  687. };
  688. // Split a collection into two arrays: one whose elements all satisfy the given
  689. // predicate, and one whose elements all do not satisfy the predicate.
  690. _.partition = function(obj, predicate, context) {
  691. predicate = cb(predicate, context);
  692. var pass = [], fail = [];
  693. _.each(obj, function(value, key, obj) {
  694. (predicate(value, key, obj) ? pass : fail).push(value);
  695. });
  696. return [pass, fail];
  697. };
  698. // Array Functions
  699. // ---------------
  700. // Get the first element of an array. Passing **n** will return the first N
  701. // values in the array. Aliased as `head` and `take`. The **guard** check
  702. // allows it to work with `_.map`.
  703. _.first = _.head = _.take = function(array, n, guard) {
  704. if (array == null) return void 0;
  705. if (n == null || guard) return array[0];
  706. return _.initial(array, array.length - n);
  707. };
  708. // Returns everything but the last entry of the array. Especially useful on
  709. // the arguments object. Passing **n** will return all the values in
  710. // the array, excluding the last N.
  711. _.initial = function(array, n, guard) {
  712. return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
  713. };
  714. // Get the last element of an array. Passing **n** will return the last N
  715. // values in the array.
  716. _.last = function(array, n, guard) {
  717. if (array == null) return void 0;
  718. if (n == null || guard) return array[array.length - 1];
  719. return _.rest(array, Math.max(0, array.length - n));
  720. };
  721. // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
  722. // Especially useful on the arguments object. Passing an **n** will return
  723. // the rest N values in the array.
  724. _.rest = _.tail = _.drop = function(array, n, guard) {
  725. return slice.call(array, n == null || guard ? 1 : n);
  726. };
  727. // Trim out all falsy values from an array.
  728. _.compact = function(array) {
  729. return _.filter(array, _.identity);
  730. };
  731. // Internal implementation of a recursive `flatten` function.
  732. var flatten = function(input, shallow, strict, startIndex) {
  733. var output = [], idx = 0;
  734. for (var i = startIndex || 0, length = getLength(input); i < length; i++) {
  735. var value = input[i];
  736. if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
  737. //flatten current level of array or arguments object
  738. if (!shallow) value = flatten(value, shallow, strict);
  739. var j = 0, len = value.length;
  740. output.length += len;
  741. while (j < len) {
  742. output[idx++] = value[j++];
  743. }
  744. } else if (!strict) {
  745. output[idx++] = value;
  746. }
  747. }
  748. return output;
  749. };
  750. // Flatten out an array, either recursively (by default), or just one level.
  751. _.flatten = function(array, shallow) {
  752. return flatten(array, shallow, false);
  753. };
  754. // Return a version of the array that does not contain the specified value(s).
  755. _.without = function(array) {
  756. return _.difference(array, slice.call(arguments, 1));
  757. };
  758. // Produce a duplicate-free version of the array. If the array has already
  759. // been sorted, you have the option of using a faster algorithm.
  760. // Aliased as `unique`.
  761. _.uniq = _.unique = function(array, isSorted, iteratee, context) {
  762. if (!_.isBoolean(isSorted)) {
  763. context = iteratee;
  764. iteratee = isSorted;
  765. isSorted = false;
  766. }
  767. if (iteratee != null) iteratee = cb(iteratee, context);
  768. var result = [];
  769. var seen = [];
  770. for (var i = 0, length = getLength(array); i < length; i++) {
  771. var value = array[i],
  772. computed = iteratee ? iteratee(value, i, array) : value;
  773. if (isSorted) {
  774. if (!i || seen !== computed) result.push(value);
  775. seen = computed;
  776. } else if (iteratee) {
  777. if (!_.contains(seen, computed)) {
  778. seen.push(computed);
  779. result.push(value);
  780. }
  781. } else if (!_.contains(result, value)) {
  782. result.push(value);
  783. }
  784. }
  785. return result;
  786. };
  787. // Produce an array that contains the union: each distinct element from all of
  788. // the passed-in arrays.
  789. _.union = function() {
  790. return _.uniq(flatten(arguments, true, true));
  791. };
  792. // Produce an array that contains every item shared between all the
  793. // passed-in arrays.
  794. _.intersection = function(array) {
  795. var result = [];
  796. var argsLength = arguments.length;
  797. for (var i = 0, length = getLength(array); i < length; i++) {
  798. var item = array[i];
  799. if (_.contains(result, item)) continue;
  800. for (var j = 1; j < argsLength; j++) {
  801. if (!_.contains(arguments[j], item)) break;
  802. }
  803. if (j === argsLength) result.push(item);
  804. }
  805. return result;
  806. };
  807. // Take the difference between one array and a number of other arrays.
  808. // Only the elements present in just the first array will remain.
  809. _.difference = function(array) {
  810. var rest = flatten(arguments, true, true, 1);
  811. return _.filter(array, function(value){
  812. return !_.contains(rest, value);
  813. });
  814. };
  815. // Zip together multiple lists into a single array -- elements that share
  816. // an index go together.
  817. _.zip = function() {
  818. return _.unzip(arguments);
  819. };
  820. // Complement of _.zip. Unzip accepts an array of arrays and groups
  821. // each array's elements on shared indices
  822. _.unzip = function(array) {
  823. var length = array && _.max(array, getLength).length || 0;
  824. var result = Array(length);
  825. for (var index = 0; index < length; index++) {
  826. result[index] = _.pluck(array, index);
  827. }
  828. return result;
  829. };
  830. // Converts lists into objects. Pass either a single array of `[key, value]`
  831. // pairs, or two parallel arrays of the same length -- one of keys, and one of
  832. // the corresponding values.
  833. _.object = function(list, values) {
  834. var result = {};
  835. for (var i = 0, length = getLength(list); i < length; i++) {
  836. if (values) {
  837. result[list[i]] = values[i];
  838. } else {
  839. result[list[i][0]] = list[i][1];
  840. }
  841. }
  842. return result;
  843. };
  844. // Generator function to create the findIndex and findLastIndex functions
  845. function createPredicateIndexFinder(dir) {
  846. return function(array, predicate, context) {
  847. predicate = cb(predicate, context);
  848. var length = getLength(array);
  849. var index = dir > 0 ? 0 : length - 1;
  850. for (; index >= 0 && index < length; index += dir) {
  851. if (predicate(array[index], index, array)) return index;
  852. }
  853. return -1;
  854. };
  855. }
  856. // Returns the first index on an array-like that passes a predicate test
  857. _.findIndex = createPredicateIndexFinder(1);
  858. _.findLastIndex = createPredicateIndexFinder(-1);
  859. // Use a comparator function to figure out the smallest index at which
  860. // an object should be inserted so as to maintain order. Uses binary search.
  861. _.sortedIndex = function(array, obj, iteratee, context) {
  862. iteratee = cb(iteratee, context, 1);
  863. var value = iteratee(obj);
  864. var low = 0, high = getLength(array);
  865. while (low < high) {
  866. var mid = Math.floor((low + high) / 2);
  867. if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
  868. }
  869. return low;
  870. };
  871. // Generator function to create the indexOf and lastIndexOf functions
  872. function createIndexFinder(dir, predicateFind, sortedIndex) {
  873. return function(array, item, idx) {
  874. var i = 0, length = getLength(array);
  875. if (typeof idx == 'number') {
  876. if (dir > 0) {
  877. i = idx >= 0 ? idx : Math.max(idx + length, i);
  878. } else {
  879. length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
  880. }
  881. } else if (sortedIndex && idx && length) {
  882. idx = sortedIndex(array, item);
  883. return array[idx] === item ? idx : -1;
  884. }
  885. if (item !== item) {
  886. idx = predicateFind(slice.call(array, i, length), _.isNaN);
  887. return idx >= 0 ? idx + i : -1;
  888. }
  889. for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
  890. if (array[idx] === item) return idx;
  891. }
  892. return -1;
  893. };
  894. }
  895. // Return the position of the first occurrence of an item in an array,
  896. // or -1 if the item is not included in the array.
  897. // If the array is large and already in sort order, pass `true`
  898. // for **isSorted** to use binary search.
  899. _.indexOf = createIndexFinder(1, _.findIndex, _.sortedIndex);
  900. _.lastIndexOf = createIndexFinder(-1, _.findLastIndex);
  901. // Generate an integer Array containing an arithmetic progression. A port of
  902. // the native Python `range()` function. See
  903. // [the Python documentation](http://docs.python.org/library/functions.html#range).
  904. _.range = function(start, stop, step) {
  905. if (stop == null) {
  906. stop = start || 0;
  907. start = 0;
  908. }
  909. step = step || 1;
  910. var length = Math.max(Math.ceil((stop - start) / step), 0);
  911. var range = Array(length);
  912. for (var idx = 0; idx < length; idx++, start += step) {
  913. range[idx] = start;
  914. }
  915. return range;
  916. };
  917. // Function (ahem) Functions
  918. // ------------------
  919. // Determines whether to execute a function as a constructor
  920. // or a normal function with the provided arguments
  921. var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) {
  922. if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
  923. var self = baseCreate(sourceFunc.prototype);
  924. var result = sourceFunc.apply(self, args);
  925. if (_.isObject(result)) return result;
  926. return self;
  927. };
  928. // Create a function bound to a given object (assigning `this`, and arguments,
  929. // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
  930. // available.
  931. _.bind = function(func, context) {
  932. if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
  933. if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
  934. var args = slice.call(arguments, 2);
  935. var bound = function() {
  936. return executeBound(func, bound, context, this, args.concat(slice.call(arguments)));
  937. };
  938. return bound;
  939. };
  940. // Partially apply a function by creating a version that has had some of its
  941. // arguments pre-filled, without changing its dynamic `this` context. _ acts
  942. // as a placeholder, allowing any combination of arguments to be pre-filled.
  943. _.partial = function(func) {
  944. var boundArgs = slice.call(arguments, 1);
  945. var bound = function() {
  946. var position = 0, length = boundArgs.length;
  947. var args = Array(length);
  948. for (var i = 0; i < length; i++) {
  949. args[i] = boundArgs[i] === _ ? arguments[position++] : boundArgs[i];
  950. }
  951. while (position < arguments.length) args.push(arguments[position++]);
  952. return executeBound(func, bound, this, this, args);
  953. };
  954. return bound;
  955. };
  956. // Bind a number of an object's methods to that object. Remaining arguments
  957. // are the method names to be bound. Useful for ensuring that all callbacks
  958. // defined on an object belong to it.
  959. _.bindAll = function(obj) {
  960. var i, length = arguments.length, key;
  961. if (length <= 1) throw new Error('bindAll must be passed function names');
  962. for (i = 1; i < length; i++) {
  963. key = arguments[i];
  964. obj[key] = _.bind(obj[key], obj);
  965. }
  966. return obj;
  967. };
  968. // Memoize an expensive function by storing its results.
  969. _.memoize = function(func, hasher) {
  970. var memoize = function(key) {
  971. var cache = memoize.cache;
  972. var address = '' + (hasher ? hasher.apply(this, arguments) : key);
  973. if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
  974. return cache[address];
  975. };
  976. memoize.cache = {};
  977. return memoize;
  978. };
  979. // Delays a function for the given number of milliseconds, and then calls
  980. // it with the arguments supplied.
  981. _.delay = function(func, wait) {
  982. var args = slice.call(arguments, 2);
  983. return setTimeout(function(){
  984. return func.apply(null, args);
  985. }, wait);
  986. };
  987. // Defers a function, scheduling it to run after the current call stack has
  988. // cleared.
  989. _.defer = _.partial(_.delay, _, 1);
  990. // Returns a function, that, when invoked, will only be triggered at most once
  991. // during a given window of time. Normally, the throttled function will run
  992. // as much as it can, without ever going more than once per `wait` duration;
  993. // but if you'd like to disable the execution on the leading edge, pass
  994. // `{leading: false}`. To disable execution on the trailing edge, ditto.
  995. _.throttle = function(func, wait, options) {
  996. var context, args, result;
  997. var timeout = null;
  998. var previous = 0;
  999. if (!options) options = {};
  1000. var later = function() {
  1001. previous = options.leading === false ? 0 : _.now();
  1002. timeout = null;
  1003. result = func.apply(context, args);
  1004. if (!timeout) context = args = null;
  1005. };
  1006. return function() {
  1007. var now = _.now();
  1008. if (!previous && options.leading === false) previous = now;
  1009. var remaining = wait - (now - previous);
  1010. context = this;
  1011. args = arguments;
  1012. if (remaining <= 0 || remaining > wait) {
  1013. if (timeout) {
  1014. clearTimeout(timeout);
  1015. timeout = null;
  1016. }
  1017. previous = now;
  1018. result = func.apply(context, args);
  1019. if (!timeout) context = args = null;
  1020. } else if (!timeout && options.trailing !== false) {
  1021. timeout = setTimeout(later, remaining);
  1022. }
  1023. return result;
  1024. };
  1025. };
  1026. // Returns a function, that, as long as it continues to be invoked, will not
  1027. // be triggered. The function will be called after it stops being called for
  1028. // N milliseconds. If `immediate` is passed, trigger the function on the
  1029. // leading edge, instead of the trailing.
  1030. _.debounce = function(func, wait, immediate) {
  1031. var timeout, args, context, timestamp, result;
  1032. var later = function() {
  1033. var last = _.now() - timestamp;
  1034. if (last < wait && last >= 0) {
  1035. timeout = setTimeout(later, wait - last);
  1036. } else {
  1037. timeout = null;
  1038. if (!immediate) {
  1039. result = func.apply(context, args);
  1040. if (!timeout) context = args = null;
  1041. }
  1042. }
  1043. };
  1044. return function() {
  1045. context = this;
  1046. args = arguments;
  1047. timestamp = _.now();
  1048. var callNow = immediate && !timeout;
  1049. if (!timeout) timeout = setTimeout(later, wait);
  1050. if (callNow) {
  1051. result = func.apply(context, args);
  1052. context = args = null;
  1053. }
  1054. return result;
  1055. };
  1056. };
  1057. // Returns the first function passed as an argument to the second,
  1058. // allowing you to adjust arguments, run code before and after, and
  1059. // conditionally execute the original function.
  1060. _.wrap = function(func, wrapper) {
  1061. return _.partial(wrapper, func);
  1062. };
  1063. // Returns a negated version of the passed-in predicate.
  1064. _.negate = function(predicate) {
  1065. return function() {
  1066. return !predicate.apply(this, arguments);
  1067. };
  1068. };
  1069. // Returns a function that is the composition of a list of functions, each
  1070. // consuming the return value of the function that follows.
  1071. _.compose = function() {
  1072. var args = arguments;
  1073. var start = args.length - 1;
  1074. return function() {
  1075. var i = start;
  1076. var result = args[start].apply(this, arguments);
  1077. while (i--) result = args[i].call(this, result);
  1078. return result;
  1079. };
  1080. };
  1081. // Returns a function that will only be executed on and after the Nth call.
  1082. _.after = function(times, func) {
  1083. return function() {
  1084. if (--times < 1) {
  1085. return func.apply(this, arguments);
  1086. }
  1087. };
  1088. };
  1089. // Returns a function that will only be executed up to (but not including) the Nth call.
  1090. _.before = function(times, func) {
  1091. var memo;
  1092. return function() {
  1093. if (--times > 0) {
  1094. memo = func.apply(this, arguments);
  1095. }
  1096. if (times <= 1) func = null;
  1097. return memo;
  1098. };
  1099. };
  1100. // Returns a function that will be executed at most one time, no matter how
  1101. // often you call it. Useful for lazy initialization.
  1102. _.once = _.partial(_.before, 2);
  1103. // Object Functions
  1104. // ----------------
  1105. // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
  1106. var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
  1107. var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
  1108. 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
  1109. function collectNonEnumProps(obj, keys) {
  1110. var nonEnumIdx = nonEnumerableProps.length;
  1111. var constructor = obj.constructor;
  1112. var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;
  1113. // Constructor is a special case.
  1114. var prop = 'constructor';
  1115. if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
  1116. while (nonEnumIdx--) {
  1117. prop = nonEnumerableProps[nonEnumIdx];
  1118. if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
  1119. keys.push(prop);
  1120. }
  1121. }
  1122. }
  1123. // Retrieve the names of an object's own properties.
  1124. // Delegates to **ECMAScript 5**'s native `Object.keys`
  1125. _.keys = function(obj) {
  1126. if (!_.isObject(obj)) return [];
  1127. if (nativeKeys) return nativeKeys(obj);
  1128. var keys = [];
  1129. for (var key in obj) if (_.has(obj, key)) keys.push(key);
  1130. // Ahem, IE < 9.
  1131. if (hasEnumBug) collectNonEnumProps(obj, keys);
  1132. return keys;
  1133. };
  1134. // Retrieve all the property names of an object.
  1135. _.allKeys = function(obj) {
  1136. if (!_.isObject(obj)) return [];
  1137. var keys = [];
  1138. for (var key in obj) keys.push(key);
  1139. // Ahem, IE < 9.
  1140. if (hasEnumBug) collectNonEnumProps(obj, keys);
  1141. return keys;
  1142. };
  1143. // Retrieve the values of an object's properties.
  1144. _.values = function(obj) {
  1145. var keys = _.keys(obj);
  1146. var length = keys.length;
  1147. var values = Array(length);
  1148. for (var i = 0; i < length; i++) {
  1149. values[i] = obj[keys[i]];
  1150. }
  1151. return values;
  1152. };
  1153. // Returns the results of applying the iteratee to each element of the object
  1154. // In contrast to _.map it returns an object
  1155. _.mapObject = function(obj, iteratee, context) {
  1156. iteratee = cb(iteratee, context);
  1157. var keys = _.keys(obj),
  1158. length = keys.length,
  1159. results = {},
  1160. currentKey;
  1161. for (var index = 0; index < length; index++) {
  1162. currentKey = keys[index];
  1163. results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
  1164. }
  1165. return results;
  1166. };
  1167. // Convert an object into a list of `[key, value]` pairs.
  1168. _.pairs = function(obj) {
  1169. var keys = _.keys(obj);
  1170. var length = keys.length;
  1171. var pairs = Array(length);
  1172. for (var i = 0; i < length; i++) {
  1173. pairs[i] = [keys[i], obj[keys[i]]];
  1174. }
  1175. return pairs;
  1176. };
  1177. // Invert the keys and values of an object. The values must be serializable.
  1178. _.invert = function(obj) {
  1179. var result = {};
  1180. var keys = _.keys(obj);
  1181. for (var i = 0, length = keys.length; i < length; i++) {
  1182. result[obj[keys[i]]] = keys[i];
  1183. }
  1184. return result;
  1185. };
  1186. // Return a sorted list of the function names available on the object.
  1187. // Aliased as `methods`
  1188. _.functions = _.methods = function(obj) {
  1189. var names = [];
  1190. for (var key in obj) {
  1191. if (_.isFunction(obj[key])) names.push(key);
  1192. }
  1193. return names.sort();
  1194. };
  1195. // Extend a given object with all the properties in passed-in object(s).
  1196. _.extend = createAssigner(_.allKeys);
  1197. // Assigns a given object with all the own properties in the passed-in object(s)
  1198. // (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
  1199. _.extendOwn = _.assign = createAssigner(_.keys);
  1200. // Returns the first key on an object that passes a predicate test
  1201. _.findKey = function(obj, predicate, context) {
  1202. predicate = cb(predicate, context);
  1203. var keys = _.keys(obj), key;
  1204. for (var i = 0, length = keys.length; i < length; i++) {
  1205. key = keys[i];
  1206. if (predicate(obj[key], key, obj)) return key;
  1207. }
  1208. };
  1209. // Return a copy of the object only containing the whitelisted properties.
  1210. _.pick = function(object, oiteratee, context) {
  1211. var result = {}, obj = object, iteratee, keys;
  1212. if (obj == null) return result;
  1213. if (_.isFunction(oiteratee)) {
  1214. keys = _.allKeys(obj);
  1215. iteratee = optimizeCb(oiteratee, context);
  1216. } else {
  1217. keys = flatten(arguments, false, false, 1);
  1218. iteratee = function(value, key, obj) { return key in obj; };
  1219. obj = Object(obj);
  1220. }
  1221. for (var i = 0, length = keys.length; i < length; i++) {
  1222. var key = keys[i];
  1223. var value = obj[key];
  1224. if (iteratee(value, key, obj)) result[key] = value;
  1225. }
  1226. return result;
  1227. };
  1228. // Return a copy of the object without the blacklisted properties.
  1229. _.omit = function(obj, iteratee, context) {
  1230. if (_.isFunction(iteratee)) {
  1231. iteratee = _.negate(iteratee);
  1232. } else {
  1233. var keys = _.map(flatten(arguments, false, false, 1), String);
  1234. iteratee = function(value, key) {
  1235. return !_.contains(keys, key);
  1236. };
  1237. }
  1238. return _.pick(obj, iteratee, context);
  1239. };
  1240. // Fill in a given object with default properties.
  1241. _.defaults = createAssigner(_.allKeys, true);
  1242. // Creates an object that inherits from the given prototype object.
  1243. // If additional properties are provided then they will be added to the
  1244. // created object.
  1245. _.create = function(prototype, props) {
  1246. var result = baseCreate(prototype);
  1247. if (props) _.extendOwn(result, props);
  1248. return result;
  1249. };
  1250. // Create a (shallow-cloned) duplicate of an object.
  1251. _.clone = function(obj) {
  1252. if (!_.isObject(obj)) return obj;
  1253. return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
  1254. };
  1255. // Invokes interceptor with the obj, and then returns obj.
  1256. // The primary purpose of this method is to "tap into" a method chain, in
  1257. // order to perform operations on intermediate results within the chain.
  1258. _.tap = function(obj, interceptor) {
  1259. interceptor(obj);
  1260. return obj;
  1261. };
  1262. // Returns whether an object has a given set of `key:value` pairs.
  1263. _.isMatch = function(object, attrs) {
  1264. var keys = _.keys(attrs), length = keys.length;
  1265. if (object == null) return !length;
  1266. var obj = Object(object);
  1267. for (var i = 0; i < length; i++) {
  1268. var key = keys[i];
  1269. if (attrs[key] !== obj[key] || !(key in obj)) return false;
  1270. }
  1271. return true;
  1272. };
  1273. // Internal recursive comparison function for `isEqual`.
  1274. var eq = function(a, b, aStack, bStack) {
  1275. // Identical objects are equal. `0 === -0`, but they aren't identical.
  1276. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
  1277. if (a === b) return a !== 0 || 1 / a === 1 / b;
  1278. // A strict comparison is necessary because `null == undefined`.
  1279. if (a == null || b == null) return a === b;
  1280. // Unwrap any wrapped objects.
  1281. if (a instanceof _) a = a._wrapped;
  1282. if (b instanceof _) b = b._wrapped;
  1283. // Compare `[[Class]]` names.
  1284. var className = toString.call(a);
  1285. if (className !== toString.call(b)) return false;
  1286. switch (className) {
  1287. // Strings, numbers, regular expressions, dates, and booleans are compared by value.
  1288. case '[object RegExp]':
  1289. // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
  1290. case '[object String]':
  1291. // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  1292. // equivalent to `new String("5")`.
  1293. return '' + a === '' + b;
  1294. case '[object Number]':
  1295. // `NaN`s are equivalent, but non-reflexive.
  1296. // Object(NaN) is equivalent to NaN
  1297. if (+a !== +a) return +b !== +b;
  1298. // An `egal` comparison is performed for other numeric values.
  1299. return +a === 0 ? 1 / +a === 1 / b : +a === +b;
  1300. case '[object Date]':
  1301. case '[object Boolean]':
  1302. // Coerce dates and booleans to numeric primitive values. Dates are compared by their
  1303. // millisecond representations. Note that invalid dates with millisecond representations
  1304. // of `NaN` are not equivalent.
  1305. return +a === +b;
  1306. }
  1307. var areArrays = className === '[object Array]';
  1308. if (!areArrays) {
  1309. if (typeof a != 'object' || typeof b != 'object') return false;
  1310. // Objects with different constructors are not equivalent, but `Object`s or `Array`s
  1311. // from different frames are.
  1312. var aCtor = a.constructor, bCtor = b.constructor;
  1313. if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
  1314. _.isFunction(bCtor) && bCtor instanceof bCtor)
  1315. && ('constructor' in a && 'constructor' in b)) {
  1316. return false;
  1317. }
  1318. }
  1319. // Assume equality for cyclic structures. The algorithm for detecting cyclic
  1320. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  1321. // Initializing stack of traversed objects.
  1322. // It's done here since we only need them for objects and arrays comparison.
  1323. aStack = aStack || [];
  1324. bStack = bStack || [];
  1325. var length = aStack.length;
  1326. while (length--) {
  1327. // Linear search. Performance is inversely proportional to the number of
  1328. // unique nested structures.
  1329. if (aStack[length] === a) return bStack[length] === b;
  1330. }
  1331. // Add the first object to the stack of traversed objects.
  1332. aStack.push(a);
  1333. bStack.push(b);
  1334. // Recursively compare objects and arrays.
  1335. if (areArrays) {
  1336. // Compare array lengths to determine if a deep comparison is necessary.
  1337. length = a.length;
  1338. if (length !== b.length) return false;
  1339. // Deep compare the contents, ignoring non-numeric properties.
  1340. while (length--) {
  1341. if (!eq(a[length], b[length], aStack, bStack)) return false;
  1342. }
  1343. } else {
  1344. // Deep compare objects.
  1345. var keys = _.keys(a), key;
  1346. length = keys.length;
  1347. // Ensure that both objects contain the same number of properties before comparing deep equality.
  1348. if (_.keys(b).length !== length) return false;
  1349. while (length--) {
  1350. // Deep compare each member
  1351. key = keys[length];
  1352. if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
  1353. }
  1354. }
  1355. // Remove the first object from the stack of traversed objects.
  1356. aStack.pop();
  1357. bStack.pop();
  1358. return true;
  1359. };
  1360. // Perform a deep comparison to check if two objects are equal.
  1361. _.isEqual = function(a, b) {
  1362. return eq(a, b);
  1363. };
  1364. // Is a given array, string, or object empty?
  1365. // An "empty" object has no enumerable own-properties.
  1366. _.isEmpty = function(obj) {
  1367. if (obj == null) return true;
  1368. if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0;
  1369. return _.keys(obj).length === 0;
  1370. };
  1371. // Is a given value a DOM element?
  1372. _.isElement = function(obj) {
  1373. return !!(obj && obj.nodeType === 1);
  1374. };
  1375. // Is a given value an array?
  1376. // Delegates to ECMA5's native Array.isArray
  1377. _.isArray = nativeIsArray || function(obj) {
  1378. return toString.call(obj) === '[object Array]';
  1379. };
  1380. // Is a given variable an object?
  1381. _.isObject = function(obj) {
  1382. var type = typeof obj;
  1383. return type === 'function' || type === 'object' && !!obj;
  1384. };
  1385. // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
  1386. _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
  1387. _['is' + name] = function(obj) {
  1388. return toString.call(obj) === '[object ' + name + ']';
  1389. };
  1390. });
  1391. // Define a fallback version of the method in browsers (ahem, IE < 9), where
  1392. // there isn't any inspectable "Arguments" type.
  1393. if (!_.isArguments(arguments)) {
  1394. _.isArguments = function(obj) {
  1395. return _.has(obj, 'callee');
  1396. };
  1397. }
  1398. // Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
  1399. // IE 11 (#1621), and in Safari 8 (#1929).
  1400. if (typeof /./ != 'function' && typeof Int8Array != 'object') {
  1401. _.isFunction = function(obj) {
  1402. return typeof obj == 'function' || false;
  1403. };
  1404. }
  1405. // Is a given object a finite number?
  1406. _.isFinite = function(obj) {
  1407. return isFinite(obj) && !isNaN(parseFloat(obj));
  1408. };
  1409. // Is the given value `NaN`? (NaN is the only number which does not equal itself).
  1410. _.isNaN = function(obj) {
  1411. return _.isNumber(obj) && obj !== +obj;
  1412. };
  1413. // Is a given value a boolean?
  1414. _.isBoolean = function(obj) {
  1415. return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
  1416. };
  1417. // Is a given value equal to null?
  1418. _.isNull = function(obj) {
  1419. return obj === null;
  1420. };
  1421. // Is a given variable undefined?
  1422. _.isUndefined = function(obj) {
  1423. return obj === void 0;
  1424. };
  1425. // Shortcut function for checking if an object has a given property directly
  1426. // on itself (in other words, not on a prototype).
  1427. _.has = function(obj, key) {
  1428. return obj != null && hasOwnProperty.call(obj, key);
  1429. };
  1430. // Utility Functions
  1431. // -----------------
  1432. // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  1433. // previous owner. Returns a reference to the Underscore object.
  1434. _.noConflict = function() {
  1435. root._ = previousUnderscore;
  1436. return this;
  1437. };
  1438. // Keep the identity function around for default iteratees.
  1439. _.identity = function(value) {
  1440. return value;
  1441. };
  1442. // Predicate-generating functions. Often useful outside of Underscore.
  1443. _.constant = function(value) {
  1444. return function() {
  1445. return value;
  1446. };
  1447. };
  1448. _.noop = function(){};
  1449. _.property = property;
  1450. // Generates a function for a given object that returns a given property.
  1451. _.propertyOf = function(obj) {
  1452. return obj == null ? function(){} : function(key) {
  1453. return obj[key];
  1454. };
  1455. };
  1456. // Returns a predicate for checking whether an object has a given set of
  1457. // `key:value` pairs.
  1458. _.matcher = _.matches = function(attrs) {
  1459. attrs = _.extendOwn({}, attrs);
  1460. return function(obj) {
  1461. return _.isMatch(obj, attrs);
  1462. };
  1463. };
  1464. // Run a function **n** times.
  1465. _.times = function(n, iteratee, context) {
  1466. var accum = Array(Math.max(0, n));
  1467. iteratee = optimizeCb(iteratee, context, 1);
  1468. for (var i = 0; i < n; i++) accum[i] = iteratee(i);
  1469. return accum;
  1470. };
  1471. // Return a random integer between min and max (inclusive).
  1472. _.random = function(min, max) {
  1473. if (max == null) {
  1474. max = min;
  1475. min = 0;
  1476. }
  1477. return min + Math.floor(Math.random() * (max - min + 1));
  1478. };
  1479. // A (possibly faster) way to get the current timestamp as an integer.
  1480. _.now = Date.now || function() {
  1481. return new Date().getTime();
  1482. };
  1483. // List of HTML entities for escaping.
  1484. var escapeMap = {
  1485. '&': '&amp;',
  1486. '<': '&lt;',
  1487. '>': '&gt;',
  1488. '"': '&quot;',
  1489. "'": '&#x27;',
  1490. '`': '&#x60;'
  1491. };
  1492. var unescapeMap = _.invert(escapeMap);
  1493. // Functions for escaping and unescaping strings to/from HTML interpolation.
  1494. var createEscaper = function(map) {
  1495. var escaper = function(match) {
  1496. return map[match];
  1497. };
  1498. // Regexes for identifying a key that needs to be escaped
  1499. var source = '(?:' + _.keys(map).join('|') + ')';
  1500. var testRegexp = RegExp(source);
  1501. var replaceRegexp = RegExp(source, 'g');
  1502. return function(string) {
  1503. string = string == null ? '' : '' + string;
  1504. return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
  1505. };
  1506. };
  1507. _.escape = createEscaper(escapeMap);
  1508. _.unescape = createEscaper(unescapeMap);
  1509. // If the value of the named `property` is a function then invoke it with the
  1510. // `object` as context; otherwise, return it.
  1511. _.result = function(object, property, fallback) {
  1512. var value = object == null ? void 0 : object[property];
  1513. if (value === void 0) {
  1514. value = fallback;
  1515. }
  1516. return _.isFunction(value) ? value.call(object) : value;
  1517. };
  1518. // Generate a unique integer id (unique within the entire client session).
  1519. // Useful for temporary DOM ids.
  1520. var idCounter = 0;
  1521. _.uniqueId = function(prefix) {
  1522. var id = ++idCounter + '';
  1523. return prefix ? prefix + id : id;
  1524. };
  1525. // By default, Underscore uses ERB-style template delimiters, change the
  1526. // following template settings to use alternative delimiters.
  1527. _.templateSettings = {
  1528. evaluate : /<%([\s\S]+?)%>/g,
  1529. interpolate : /<%=([\s\S]+?)%>/g,
  1530. escape : /<%-([\s\S]+?)%>/g
  1531. };
  1532. // When customizing `templateSettings`, if you don't want to define an
  1533. // interpolation, evaluation or escaping regex, we need one that is
  1534. // guaranteed not to match.
  1535. var noMatch = /(.)^/;
  1536. // Certain characters need to be escaped so that they can be put into a
  1537. // string literal.
  1538. var escapes = {
  1539. "'": "'",
  1540. '\\': '\\',
  1541. '\r': 'r',
  1542. '\n': 'n',
  1543. '\u2028': 'u2028',
  1544. '\u2029': 'u2029'
  1545. };
  1546. var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
  1547. var escapeChar = function(match) {
  1548. return '\\' + escapes[match];
  1549. };
  1550. // JavaScript micro-templating, similar to John Resig's implementation.
  1551. // Underscore templating handles arbitrary delimiters, preserves whitespace,
  1552. // and correctly escapes quotes within interpolated code.
  1553. // NB: `oldSettings` only exists for backwards compatibility.
  1554. _.template = function(text, settings, oldSettings) {
  1555. if (!settings && oldSettings) settings = oldSettings;
  1556. settings = _.defaults({}, settings, _.templateSettings);
  1557. // Combine delimiters into one regular expression via alternation.
  1558. var matcher = RegExp([
  1559. (settings.escape || noMatch).source,
  1560. (settings.interpolate || noMatch).source,
  1561. (settings.evaluate || noMatch).source
  1562. ].join('|') + '|$', 'g');
  1563. // Compile the template source, escaping string literals appropriately.
  1564. var index = 0;
  1565. var source = "__p+='";
  1566. text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  1567. source += text.slice(index, offset).replace(escaper, escapeChar);
  1568. index = offset + match.length;
  1569. if (escape) {
  1570. source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  1571. } else if (interpolate) {
  1572. source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
  1573. } else if (evaluate) {
  1574. source += "';\n" + evaluate + "\n__p+='";
  1575. }
  1576. // Adobe VMs need the match returned to produce the correct offest.
  1577. return match;
  1578. });
  1579. source += "';\n";
  1580. // If a variable is not specified, place data values in local scope.
  1581. if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  1582. source = "var __t,__p='',__j=Array.prototype.join," +
  1583. "print=function(){__p+=__j.call(arguments,'');};\n" +
  1584. source + 'return __p;\n';
  1585. try {
  1586. var render = new Function(settings.variable || 'obj', '_', source);
  1587. } catch (e) {
  1588. e.source = source;
  1589. throw e;
  1590. }
  1591. var template = function(data) {
  1592. return render.call(this, data, _);
  1593. };
  1594. // Provide the compiled source as a convenience for precompilation.
  1595. var argument = settings.variable || 'obj';
  1596. template.source = 'function(' + argument + '){\n' + source + '}';
  1597. return template;
  1598. };
  1599. // Add a "chain" function. Start chaining a wrapped Underscore object.
  1600. _.chain = function(obj) {
  1601. var instance = _(obj);
  1602. instance._chain = true;
  1603. return instance;
  1604. };
  1605. // OOP
  1606. // ---------------
  1607. // If Underscore is called as a function, it returns a wrapped object that
  1608. // can be used OO-style. This wrapper holds altered versions of all the
  1609. // underscore functions. Wrapped objects may be chained.
  1610. // Helper function to continue chaining intermediate results.
  1611. var result = function(instance, obj) {
  1612. return instance._chain ? _(obj).chain() : obj;
  1613. };
  1614. // Add your own custom functions to the Underscore object.
  1615. _.mixin = function(obj) {
  1616. _.each(_.functions(obj), function(name) {
  1617. var func = _[name] = obj[name];
  1618. _.prototype[name] = function() {
  1619. var args = [this._wrapped];
  1620. push.apply(args, arguments);
  1621. return result(this, func.apply(_, args));
  1622. };
  1623. });
  1624. };
  1625. // Add all of the Underscore functions to the wrapper object.
  1626. _.mixin(_);
  1627. // Add all mutator Array functions to the wrapper.
  1628. _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  1629. var method = ArrayProto[name];
  1630. _.prototype[name] = function() {
  1631. var obj = this._wrapped;
  1632. method.apply(obj, arguments);
  1633. if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
  1634. return result(this, obj);
  1635. };
  1636. });
  1637. // Add all accessor Array functions to the wrapper.
  1638. _.each(['concat', 'join', 'slice'], function(name) {
  1639. var method = ArrayProto[name];
  1640. _.prototype[name] = function() {
  1641. return result(this, method.apply(this._wrapped, arguments));
  1642. };
  1643. });
  1644. // Extracts the result from a wrapped and chained object.
  1645. _.prototype.value = function() {
  1646. return this._wrapped;
  1647. };
  1648. // Provide unwrapping proxy for some methods used in engine operations
  1649. // such as arithmetic and JSON stringification.
  1650. _.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
  1651. _.prototype.toString = function() {
  1652. return '' + this._wrapped;
  1653. };
  1654. // AMD registration happens at the end for compatibility with AMD loaders
  1655. // that may not enforce next-turn semantics on modules. Even though general
  1656. // practice for AMD registration is to be anonymous, underscore registers
  1657. // as a named module because, like jQuery, it is a base library that is
  1658. // popular enough to be bundled in a third party lib, but not be part of
  1659. // an AMD load request. Those cases could generate an error when an
  1660. // anonymous define() is called outside of a loader request.
  1661. if (typeof define === 'function' && define.amd) {
  1662. define('underscore', [], function() {
  1663. return _;
  1664. });
  1665. }
  1666. }.call(this));
  1667. },{}],"/node_modules/jshint/src/jshint.js":[function(_dereq_,module,exports){
  1668. /*!
  1669. * JSHint, by JSHint Community.
  1670. *
  1671. * This file (and this file only) is licensed under the same slightly modified
  1672. * MIT license that JSLint is. It stops evil-doers everywhere:
  1673. *
  1674. * Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
  1675. *
  1676. * Permission is hereby granted, free of charge, to any person obtaining
  1677. * a copy of this software and associated documentation files (the "Software"),
  1678. * to deal in the Software without restriction, including without limitation
  1679. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  1680. * and/or sell copies of the Software, and to permit persons to whom
  1681. * the Software is furnished to do so, subject to the following conditions:
  1682. *
  1683. * The above copyright notice and this permission notice shall be included
  1684. * in all copies or substantial portions of the Software.
  1685. *
  1686. * The Software shall be used for Good, not Evil.
  1687. *
  1688. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1689. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1690. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1691. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1692. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  1693. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  1694. * DEALINGS IN THE SOFTWARE.
  1695. *
  1696. */
  1697. /*jshint quotmark:double */
  1698. /*global console:true */
  1699. /*exported console */
  1700. var _ = _dereq_("underscore");
  1701. var events = _dereq_("events");
  1702. var vars = _dereq_("./vars.js");
  1703. var messages = _dereq_("./messages.js");
  1704. var Lexer = _dereq_("./lex.js").Lexer;
  1705. var reg = _dereq_("./reg.js");
  1706. var state = _dereq_("./state.js").state;
  1707. var style = _dereq_("./style.js");
  1708. var options = _dereq_("./options.js");
  1709. // We build the application inside a function so that we produce only a singleton
  1710. // variable. That function will be invoked immediately, and its return value is
  1711. // the JSHINT function itself.
  1712. var JSHINT = (function() {
  1713. "use strict";
  1714. var api, // Extension API
  1715. // These are operators that should not be used with the ! operator.
  1716. bang = {
  1717. "<" : true,
  1718. "<=" : true,
  1719. "==" : true,
  1720. "===": true,
  1721. "!==": true,
  1722. "!=" : true,
  1723. ">" : true,
  1724. ">=" : true,
  1725. "+" : true,
  1726. "-" : true,
  1727. "*" : true,
  1728. "/" : true,
  1729. "%" : true
  1730. },
  1731. declared, // Globals that were declared using /*global ... */ syntax.
  1732. exported, // Variables that are used outside of the current file.
  1733. functionicity = [
  1734. "closure", "exception", "global", "label",
  1735. "outer", "unused", "var"
  1736. ],
  1737. functions, // All of the functions
  1738. global, // The global scope
  1739. implied, // Implied globals
  1740. inblock,
  1741. indent,
  1742. lookahead,
  1743. lex,
  1744. member,
  1745. membersOnly,
  1746. predefined, // Global variables defined by option
  1747. scope, // The current scope
  1748. stack,
  1749. unuseds,
  1750. urls,
  1751. extraModules = [],
  1752. emitter = new events.EventEmitter();
  1753. function checkOption(name, t) {
  1754. name = name.trim();
  1755. if (/^[+-]W\d{3}$/g.test(name)) {
  1756. return true;
  1757. }
  1758. if (options.validNames.indexOf(name) === -1) {
  1759. if (t.type !== "jslint" && !_.has(options.removed, name)) {
  1760. error("E001", t, name);
  1761. return false;
  1762. }
  1763. }
  1764. return true;
  1765. }
  1766. function isString(obj) {
  1767. return Object.prototype.toString.call(obj) === "[object String]";
  1768. }
  1769. function isIdentifier(tkn, value) {
  1770. if (!tkn)
  1771. return false;
  1772. if (!tkn.identifier || tkn.value !== value)
  1773. return false;
  1774. return true;
  1775. }
  1776. function isReserved(token) {
  1777. if (!token.reserved) {
  1778. return false;
  1779. }
  1780. var meta = token.meta;
  1781. if (meta && meta.isFutureReservedWord && state.inES5()) {
  1782. // ES3 FutureReservedWord in an ES5 environment.
  1783. if (!meta.es5) {
  1784. return false;
  1785. }
  1786. // Some ES5 FutureReservedWord identifiers are active only
  1787. // within a strict mode environment.
  1788. if (meta.strictOnly) {
  1789. if (!state.option.strict && !state.isStrict()) {
  1790. return false;
  1791. }
  1792. }
  1793. if (token.isProperty) {
  1794. return false;
  1795. }
  1796. }
  1797. return true;
  1798. }
  1799. function supplant(str, data) {
  1800. return str.replace(/\{([^{}]*)\}/g, function(a, b) {
  1801. var r = data[b];
  1802. return typeof r === "string" || typeof r === "number" ? r : a;
  1803. });
  1804. }
  1805. function combine(dest, src) {
  1806. Object.keys(src).forEach(function(name) {
  1807. if (_.has(JSHINT.blacklist, name)) return;
  1808. dest[name] = src[name];
  1809. });
  1810. }
  1811. function processenforceall() {
  1812. if (state.option.enforceall) {
  1813. for (var enforceopt in options.bool.enforcing) {
  1814. if (state.option[enforceopt] === undefined &&
  1815. !options.noenforceall[enforceopt]) {
  1816. state.option[enforceopt] = true;
  1817. }
  1818. }
  1819. for (var relaxopt in options.bool.relaxing) {
  1820. if (state.option[relaxopt] === undefined) {
  1821. state.option[relaxopt] = false;
  1822. }
  1823. }
  1824. }
  1825. }
  1826. function assume() {
  1827. processenforceall();
  1828. if (!state.option.es3) {
  1829. combine(predefined, vars.ecmaIdentifiers[5]);
  1830. }
  1831. if (state.option.esnext) {
  1832. combine(predefined, vars.ecmaIdentifiers[6]);
  1833. }
  1834. if (state.option.module) {
  1835. /**
  1836. * TODO: Extend this restriction to *all* "environmental" options.
  1837. */
  1838. if (!hasParsedCode(state.funct)) {
  1839. error("E055", state.tokens.next, "module");
  1840. }
  1841. /**
  1842. * TODO: Extend this restriction to *all* ES6-specific options.
  1843. */
  1844. if (!state.inESNext()) {
  1845. warning("W134", state.tokens.next, "module", 6);
  1846. }
  1847. }
  1848. if (state.option.couch) {
  1849. combine(predefined, vars.couch);
  1850. }
  1851. if (state.option.qunit) {
  1852. combine(predefined, vars.qunit);
  1853. }
  1854. if (state.option.rhino) {
  1855. combine(predefined, vars.rhino);
  1856. }
  1857. if (state.option.shelljs) {
  1858. combine(predefined, vars.shelljs);
  1859. combine(predefined, vars.node);
  1860. }
  1861. if (state.option.typed) {
  1862. combine(predefined, vars.typed);
  1863. }
  1864. if (state.option.phantom) {
  1865. combine(predefined, vars.phantom);
  1866. }
  1867. if (state.option.prototypejs) {
  1868. combine(predefined, vars.prototypejs);
  1869. }
  1870. if (state.option.node) {
  1871. combine(predefined, vars.node);
  1872. combine(predefined, vars.typed);
  1873. }
  1874. if (state.option.devel) {
  1875. combine(predefined, vars.devel);
  1876. }
  1877. if (state.option.dojo) {
  1878. combine(predefined, vars.dojo);
  1879. }
  1880. if (state.option.browser) {
  1881. combine(predefined, vars.browser);
  1882. combine(predefined, vars.typed);
  1883. }
  1884. if (state.option.browserify) {
  1885. combine(predefined, vars.browser);
  1886. combine(predefined, vars.typed);
  1887. combine(predefined, vars.browserify);
  1888. }
  1889. if (state.option.nonstandard) {
  1890. combine(predefined, vars.nonstandard);
  1891. }
  1892. if (state.option.jasmine) {
  1893. combine(predefined, vars.jasmine);
  1894. }
  1895. if (state.option.jquery) {
  1896. combine(predefined, vars.jquery);
  1897. }
  1898. if (state.option.mootools) {
  1899. combine(predefined, vars.mootools);
  1900. }
  1901. if (state.option.worker) {
  1902. combine(predefined, vars.worker);
  1903. }
  1904. if (state.option.wsh) {
  1905. combine(predefined, vars.wsh);
  1906. }
  1907. if (state.option.globalstrict && state.option.strict !== false) {
  1908. state.option.strict = true;
  1909. }
  1910. if (state.option.yui) {
  1911. combine(predefined, vars.yui);
  1912. }
  1913. if (state.option.mocha) {
  1914. combine(predefined, vars.mocha);
  1915. }
  1916. }
  1917. // Produce an error warning.
  1918. function quit(code, line, chr) {
  1919. var percentage = Math.floor((line / state.lines.length) * 100);
  1920. var message = messages.errors[code].desc;
  1921. throw {
  1922. name: "JSHintError",
  1923. line: line,
  1924. character: chr,
  1925. message: message + " (" + percentage + "% scanned).",
  1926. raw: message,
  1927. code: code
  1928. };
  1929. }
  1930. function isundef(scope, code, token, a) {
  1931. if (!state.ignored[code] && state.option.undef !== false) {
  1932. JSHINT.undefs.push([scope, code, token, a]);
  1933. }
  1934. }
  1935. function removeIgnoredMessages() {
  1936. var ignored = state.ignoredLines;
  1937. if (_.isEmpty(ignored)) return;
  1938. JSHINT.errors = _.reject(JSHINT.errors, function(err) { return ignored[err.line] });
  1939. }
  1940. function warning(code, t, a, b, c, d) {
  1941. var ch, l, w, msg;
  1942. if (/^W\d{3}$/.test(code)) {
  1943. if (state.ignored[code])
  1944. return;
  1945. msg = messages.warnings[code];
  1946. } else if (/E\d{3}/.test(code)) {
  1947. msg = messages.errors[code];
  1948. } else if (/I\d{3}/.test(code)) {
  1949. msg = messages.info[code];
  1950. }
  1951. t = t || state.tokens.next || {};
  1952. if (t.id === "(end)") { // `~
  1953. t = state.tokens.curr;
  1954. }
  1955. l = t.line || 0;
  1956. ch = t.from || 0;
  1957. w = {
  1958. id: "(error)",
  1959. raw: msg.desc,
  1960. code: msg.code,
  1961. evidence: state.lines[l - 1] || "",
  1962. line: l,
  1963. character: ch,
  1964. scope: JSHINT.scope,
  1965. a: a,
  1966. b: b,
  1967. c: c,
  1968. d: d
  1969. };
  1970. w.reason = supplant(msg.desc, w);
  1971. JSHINT.errors.push(w);
  1972. removeIgnoredMessages();
  1973. if (JSHINT.errors.length >= state.option.maxerr)
  1974. quit("E043", l, ch);
  1975. return w;
  1976. }
  1977. function warningAt(m, l, ch, a, b, c, d) {
  1978. return warning(m, {
  1979. line: l,
  1980. from: ch
  1981. }, a, b, c, d);
  1982. }
  1983. function error(m, t, a, b, c, d) {
  1984. warning(m, t, a, b, c, d);
  1985. }
  1986. function errorAt(m, l, ch, a, b, c, d) {
  1987. return error(m, {
  1988. line: l,
  1989. from: ch
  1990. }, a, b, c, d);
  1991. }
  1992. // Tracking of "internal" scripts, like eval containing a static string
  1993. function addInternalSrc(elem, src) {
  1994. var i;
  1995. i = {
  1996. id: "(internal)",
  1997. elem: elem,
  1998. value: src
  1999. };
  2000. JSHINT.internals.push(i);
  2001. return i;
  2002. }
  2003. // adds an indentifier to the relevant current scope and creates warnings/errors as necessary
  2004. // name: string
  2005. // opts: { type: string, token: token, isblockscoped: bool }
  2006. function addlabel(name, opts) {
  2007. var type = opts.type;
  2008. var token = opts.token;
  2009. var isblockscoped = opts.isblockscoped;
  2010. // Define label in the current function in the current scope.
  2011. if (type === "exception") {
  2012. if (_.has(state.funct["(context)"], name)) {
  2013. if (state.funct[name] !== true && !state.option.node) {
  2014. warning("W002", state.tokens.next, name);
  2015. }
  2016. }
  2017. }
  2018. if (_.has(state.funct, name) && !state.funct["(global)"]) {
  2019. if (state.funct[name] === true) {
  2020. if (state.option.latedef) {
  2021. if ((state.option.latedef === true && _.contains([state.funct[name], type], "unction")) ||
  2022. !_.contains([state.funct[name], type], "unction")) {
  2023. warning("W003", state.tokens.next, name);
  2024. }
  2025. }
  2026. } else {
  2027. if ((!state.option.shadow || _.contains([ "inner", "outer" ], state.option.shadow)) &&
  2028. type !== "exception" || state.funct["(blockscope)"].getlabel(name)) {
  2029. warning("W004", state.tokens.next, name);
  2030. }
  2031. }
  2032. }
  2033. if (state.funct["(context)"] && _.has(state.funct["(context)"], name) && type !== "function") {
  2034. if (state.option.shadow === "outer") {
  2035. warning("W123", state.tokens.next, name);
  2036. }
  2037. }
  2038. // if the identifier is blockscoped (a let or a const), add it only to the current blockscope
  2039. if (isblockscoped) {
  2040. state.funct["(blockscope)"].current.add(name, type, state.tokens.curr);
  2041. if (state.funct["(blockscope)"].atTop() && exported[name]) {
  2042. state.tokens.curr.exported = true;
  2043. }
  2044. } else {
  2045. state.funct["(blockscope)"].shadow(name);
  2046. state.funct[name] = type;
  2047. if (token) {
  2048. state.funct["(tokens)"][name] = token;
  2049. }
  2050. if (state.funct["(global)"]) {
  2051. global[name] = state.funct;
  2052. if (_.has(implied, name)) {
  2053. if (state.option.latedef) {
  2054. if ((state.option.latedef === true &&
  2055. _.contains([state.funct[name], type], "unction")) ||
  2056. !_.contains([state.funct[name], type], "unction")) {
  2057. warning("W003", state.tokens.next, name);
  2058. }
  2059. }
  2060. delete implied[name];
  2061. }
  2062. } else {
  2063. scope[name] = state.funct;
  2064. }
  2065. }
  2066. }
  2067. function doOption() {
  2068. var nt = state.tokens.next;
  2069. var body = nt.body.match(/(-\s+)?[^\s,:]+(?:\s*:\s*(-\s+)?[^\s,]+)?/g) || [];
  2070. var predef = {};
  2071. if (nt.type === "globals") {
  2072. body.forEach(function(g, idx) {
  2073. g = g.split(":");
  2074. var key = (g[0] || "").trim();
  2075. var val = (g[1] || "").trim();
  2076. if (key === "-" || !key.length) {
  2077. // Ignore trailing comma
  2078. if (idx > 0 && idx === body.length - 1) {
  2079. return;
  2080. }
  2081. error("E002", nt);
  2082. return;
  2083. }
  2084. if (key.charAt(0) === "-") {
  2085. key = key.slice(1);
  2086. val = false;
  2087. JSHINT.blacklist[key] = key;
  2088. delete predefined[key];
  2089. } else {
  2090. predef[key] = (val === "true");
  2091. }
  2092. });
  2093. combine(predefined, predef);
  2094. for (var key in predef) {
  2095. if (_.has(predef, key)) {
  2096. declared[key] = nt;
  2097. }
  2098. }
  2099. }
  2100. if (nt.type === "exported") {
  2101. body.forEach(function(e, idx) {
  2102. if (!e.length) {
  2103. // Ignore trailing comma
  2104. if (idx > 0 && idx === body.length - 1) {
  2105. return;
  2106. }
  2107. error("E002", nt);
  2108. return;
  2109. }
  2110. exported[e] = true;
  2111. });
  2112. }
  2113. if (nt.type === "members") {
  2114. membersOnly = membersOnly || {};
  2115. body.forEach(function(m) {
  2116. var ch1 = m.charAt(0);
  2117. var ch2 = m.charAt(m.length - 1);
  2118. if (ch1 === ch2 && (ch1 === "\"" || ch1 === "'")) {
  2119. m = m
  2120. .substr(1, m.length - 2)
  2121. .replace("\\\"", "\"");
  2122. }
  2123. membersOnly[m] = false;
  2124. });
  2125. }
  2126. var numvals = [
  2127. "maxstatements",
  2128. "maxparams",
  2129. "maxdepth",
  2130. "maxcomplexity",
  2131. "maxerr",
  2132. "maxlen",
  2133. "indent"
  2134. ];
  2135. if (nt.type === "jshint" || nt.type === "jslint") {
  2136. body.forEach(function(g) {
  2137. g = g.split(":");
  2138. var key = (g[0] || "").trim();
  2139. var val = (g[1] || "").trim();
  2140. if (!checkOption(key, nt)) {
  2141. return;
  2142. }
  2143. if (numvals.indexOf(key) >= 0) {
  2144. // GH988 - numeric options can be disabled by setting them to `false`
  2145. if (val !== "false") {
  2146. val = +val;
  2147. if (typeof val !== "number" || !isFinite(val) || val <= 0 || Math.floor(val) !== val) {
  2148. error("E032", nt, g[1].trim());
  2149. return;
  2150. }
  2151. state.option[key] = val;
  2152. } else {
  2153. state.option[key] = key === "indent" ? 4 : false;
  2154. }
  2155. return;
  2156. }
  2157. if (key === "validthis") {
  2158. // `validthis` is valid only within a function scope.
  2159. if (state.funct["(global)"])
  2160. return void error("E009");
  2161. if (val !== "true" && val !== "false")
  2162. return void error("E002", nt);
  2163. state.option.validthis = (val === "true");
  2164. return;
  2165. }
  2166. if (key === "quotmark") {
  2167. switch (val) {
  2168. case "true":
  2169. case "false":
  2170. state.option.quotmark = (val === "true");
  2171. break;
  2172. case "double":
  2173. case "single":
  2174. state.option.quotmark = val;
  2175. break;
  2176. default:
  2177. error("E002", nt);
  2178. }
  2179. return;
  2180. }
  2181. if (key === "shadow") {
  2182. switch (val) {
  2183. case "true":
  2184. state.option.shadow = true;
  2185. break;
  2186. case "outer":
  2187. state.option.shadow = "outer";
  2188. break;
  2189. case "false":
  2190. case "inner":
  2191. state.option.shadow = "inner";
  2192. break;
  2193. default:
  2194. error("E002", nt);
  2195. }
  2196. return;
  2197. }
  2198. if (key === "unused") {
  2199. switch (val) {
  2200. case "true":
  2201. state.option.unused = true;
  2202. break;
  2203. case "false":
  2204. state.option.unused = false;
  2205. break;
  2206. case "vars":
  2207. case "strict":
  2208. state.option.unused = val;
  2209. break;
  2210. default:
  2211. error("E002", nt);
  2212. }
  2213. return;
  2214. }
  2215. if (key === "latedef") {
  2216. switch (val) {
  2217. case "true":
  2218. state.option.latedef = true;
  2219. break;
  2220. case "false":
  2221. state.option.latedef = false;
  2222. break;
  2223. case "nofunc":
  2224. state.option.latedef = "nofunc";
  2225. break;
  2226. default:
  2227. error("E002", nt);
  2228. }
  2229. return;
  2230. }
  2231. if (key === "ignore") {
  2232. switch (val) {
  2233. case "start":
  2234. state.ignoreLinterErrors = true;
  2235. break;
  2236. case "end":
  2237. state.ignoreLinterErrors = false;
  2238. break;
  2239. case "line":
  2240. state.ignoredLines[nt.line] = true;
  2241. removeIgnoredMessages();
  2242. break;
  2243. default:
  2244. error("E002", nt);
  2245. }
  2246. return;
  2247. }
  2248. var match = /^([+-])(W\d{3})$/g.exec(key);
  2249. if (match) {
  2250. // ignore for -W..., unignore for +W...
  2251. state.ignored[match[2]] = (match[1] === "-");
  2252. return;
  2253. }
  2254. var tn;
  2255. if (val === "true" || val === "false") {
  2256. if (nt.type === "jslint") {
  2257. tn = options.renamed[key] || key;
  2258. state.option[tn] = (val === "true");
  2259. if (options.inverted[tn] !== undefined) {
  2260. state.option[tn] = !state.option[tn];
  2261. }
  2262. } else {
  2263. state.option[key] = (val === "true");
  2264. }
  2265. if (key === "newcap") {
  2266. state.option["(explicitNewcap)"] = true;
  2267. }
  2268. return;
  2269. }
  2270. error("E002", nt);
  2271. });
  2272. assume();
  2273. }
  2274. }
  2275. // We need a peek function. If it has an argument, it peeks that much farther
  2276. // ahead. It is used to distinguish
  2277. // for ( var i in ...
  2278. // from
  2279. // for ( var i = ...
  2280. function peek(p) {
  2281. var i = p || 0, j = 0, t;
  2282. while (j <= i) {
  2283. t = lookahead[j];
  2284. if (!t) {
  2285. t = lookahead[j] = lex.token();
  2286. }
  2287. j += 1;
  2288. }
  2289. // Peeking past the end of the program should produce the "(end)" token.
  2290. if (!t && state.tokens.next.id === "(end)") {
  2291. return state.tokens.next;
  2292. }
  2293. return t;
  2294. }
  2295. function peekIgnoreEOL() {
  2296. var i = 0;
  2297. var t;
  2298. do {
  2299. t = peek(i++);
  2300. } while (t.id === "(endline)");
  2301. return t;
  2302. }
  2303. // Produce the next token. It looks for programming errors.
  2304. function advance(id, t) {
  2305. switch (state.tokens.curr.id) {
  2306. case "(number)":
  2307. if (state.tokens.next.id === ".") {
  2308. warning("W005", state.tokens.curr);
  2309. }
  2310. break;
  2311. case "-":
  2312. if (state.tokens.next.id === "-" || state.tokens.next.id === "--") {
  2313. warning("W006");
  2314. }
  2315. break;
  2316. case "+":
  2317. if (state.tokens.next.id === "+" || state.tokens.next.id === "++") {
  2318. warning("W007");
  2319. }
  2320. break;
  2321. }
  2322. if (id && state.tokens.next.id !== id) {
  2323. if (t) {
  2324. if (state.tokens.next.id === "(end)") {
  2325. error("E019", t, t.id);
  2326. } else {
  2327. error("E020", state.tokens.next, id, t.id, t.line, state.tokens.next.value);
  2328. }
  2329. } else if (state.tokens.next.type !== "(identifier)" || state.tokens.next.value !== id) {
  2330. warning("W116", state.tokens.next, id, state.tokens.next.value);
  2331. }
  2332. }
  2333. state.tokens.prev = state.tokens.curr;
  2334. state.tokens.curr = state.tokens.next;
  2335. for (;;) {
  2336. state.tokens.next = lookahead.shift() || lex.token();
  2337. if (!state.tokens.next) { // No more tokens left, give up
  2338. quit("E041", state.tokens.curr.line);
  2339. }
  2340. if (state.tokens.next.id === "(end)" || state.tokens.next.id === "(error)") {
  2341. return;
  2342. }
  2343. if (state.tokens.next.check) {
  2344. state.tokens.next.check();
  2345. }
  2346. if (state.tokens.next.isSpecial) {
  2347. doOption();
  2348. } else {
  2349. if (state.tokens.next.id !== "(endline)") {
  2350. break;
  2351. }
  2352. }
  2353. }
  2354. }
  2355. function isInfix(token) {
  2356. return token.infix || (!token.identifier && !token.template && !!token.led);
  2357. }
  2358. function isEndOfExpr() {
  2359. var curr = state.tokens.curr;
  2360. var next = state.tokens.next;
  2361. if (next.id === ";" || next.id === "}" || next.id === ":") {
  2362. return true;
  2363. }
  2364. if (isInfix(next) === isInfix(curr) || (curr.id === "yield" && state.inMoz())) {
  2365. return curr.line !== startLine(next);
  2366. }
  2367. return false;
  2368. }
  2369. function isBeginOfExpr(prev) {
  2370. return !prev.left && prev.arity !== "unary";
  2371. }
  2372. // This is the heart of JSHINT, the Pratt parser. In addition to parsing, it
  2373. // is looking for ad hoc lint patterns. We add .fud to Pratt's model, which is
  2374. // like .nud except that it is only used on the first token of a statement.
  2375. // Having .fud makes it much easier to define statement-oriented languages like
  2376. // JavaScript. I retained Pratt's nomenclature.
  2377. // .nud Null denotation
  2378. // .fud First null denotation
  2379. // .led Left denotation
  2380. // lbp Left binding power
  2381. // rbp Right binding power
  2382. // They are elements of the parsing method called Top Down Operator Precedence.
  2383. function expression(rbp, initial) {
  2384. var left, isArray = false, isObject = false, isLetExpr = false;
  2385. state.nameStack.push();
  2386. // if current expression is a let expression
  2387. if (!initial && state.tokens.next.value === "let" && peek(0).value === "(") {
  2388. if (!state.inMoz()) {
  2389. warning("W118", state.tokens.next, "let expressions");
  2390. }
  2391. isLetExpr = true;
  2392. // create a new block scope we use only for the current expression
  2393. state.funct["(blockscope)"].stack();
  2394. advance("let");
  2395. advance("(");
  2396. state.tokens.prev.fud();
  2397. advance(")");
  2398. }
  2399. if (state.tokens.next.id === "(end)")
  2400. error("E006", state.tokens.curr);
  2401. var isDangerous =
  2402. state.option.asi &&
  2403. state.tokens.prev.line !== startLine(state.tokens.curr) &&
  2404. _.contains(["]", ")"], state.tokens.prev.id) &&
  2405. _.contains(["[", "("], state.tokens.curr.id);
  2406. if (isDangerous)
  2407. warning("W014", state.tokens.curr, state.tokens.curr.id);
  2408. advance();
  2409. if (initial) {
  2410. state.funct["(verb)"] = state.tokens.curr.value;
  2411. state.tokens.curr.beginsStmt = true;
  2412. }
  2413. if (initial === true && state.tokens.curr.fud) {
  2414. left = state.tokens.curr.fud();
  2415. } else {
  2416. if (state.tokens.curr.nud) {
  2417. left = state.tokens.curr.nud();
  2418. } else {
  2419. error("E030", state.tokens.curr, state.tokens.curr.id);
  2420. }
  2421. // TODO: use pratt mechanics rather than special casing template tokens
  2422. while ((rbp < state.tokens.next.lbp || state.tokens.next.type === "(template)") &&
  2423. !isEndOfExpr()) {
  2424. isArray = state.tokens.curr.value === "Array";
  2425. isObject = state.tokens.curr.value === "Object";
  2426. // #527, new Foo.Array(), Foo.Array(), new Foo.Object(), Foo.Object()
  2427. // Line breaks in IfStatement heads exist to satisfy the checkJSHint
  2428. // "Line too long." error.
  2429. if (left && (left.value || (left.first && left.first.value))) {
  2430. // If the left.value is not "new", or the left.first.value is a "."
  2431. // then safely assume that this is not "new Array()" and possibly
  2432. // not "new Object()"...
  2433. if (left.value !== "new" ||
  2434. (left.first && left.first.value && left.first.value === ".")) {
  2435. isArray = false;
  2436. // ...In the case of Object, if the left.value and state.tokens.curr.value
  2437. // are not equal, then safely assume that this not "new Object()"
  2438. if (left.value !== state.tokens.curr.value) {
  2439. isObject = false;
  2440. }
  2441. }
  2442. }
  2443. advance();
  2444. if (isArray && state.tokens.curr.id === "(" && state.tokens.next.id === ")") {
  2445. warning("W009", state.tokens.curr);
  2446. }
  2447. if (isObject && state.tokens.curr.id === "(" && state.tokens.next.id === ")") {
  2448. warning("W010", state.tokens.curr);
  2449. }
  2450. if (left && state.tokens.curr.led) {
  2451. left = state.tokens.curr.led(left);
  2452. } else {
  2453. error("E033", state.tokens.curr, state.tokens.curr.id);
  2454. }
  2455. }
  2456. }
  2457. if (isLetExpr) {
  2458. state.funct["(blockscope)"].unstack();
  2459. }
  2460. state.nameStack.pop();
  2461. return left;
  2462. }
  2463. // Functions for conformance of style.
  2464. function startLine(token) {
  2465. return token.startLine || token.line;
  2466. }
  2467. function nobreaknonadjacent(left, right) {
  2468. left = left || state.tokens.curr;
  2469. right = right || state.tokens.next;
  2470. if (!state.option.laxbreak && left.line !== startLine(right)) {
  2471. warning("W014", right, right.value);
  2472. }
  2473. }
  2474. function nolinebreak(t) {
  2475. t = t || state.tokens.curr;
  2476. if (t.line !== startLine(state.tokens.next)) {
  2477. warning("E022", t, t.value);
  2478. }
  2479. }
  2480. function nobreakcomma(left, right) {
  2481. if (left.line !== startLine(right)) {
  2482. if (!state.option.laxcomma) {
  2483. if (comma.first) {
  2484. warning("I001");
  2485. comma.first = false;
  2486. }
  2487. warning("W014", left, right.value);
  2488. }
  2489. }
  2490. }
  2491. function comma(opts) {
  2492. opts = opts || {};
  2493. if (!opts.peek) {
  2494. nobreakcomma(state.tokens.curr, state.tokens.next);
  2495. advance(",");
  2496. } else {
  2497. nobreakcomma(state.tokens.prev, state.tokens.curr);
  2498. }
  2499. if (state.tokens.next.identifier && !(opts.property && state.inES5())) {
  2500. // Keywords that cannot follow a comma operator.
  2501. switch (state.tokens.next.value) {
  2502. case "break":
  2503. case "case":
  2504. case "catch":
  2505. case "continue":
  2506. case "default":
  2507. case "do":
  2508. case "else":
  2509. case "finally":
  2510. case "for":
  2511. case "if":
  2512. case "in":
  2513. case "instanceof":
  2514. case "return":
  2515. case "switch":
  2516. case "throw":
  2517. case "try":
  2518. case "var":
  2519. case "let":
  2520. case "while":
  2521. case "with":
  2522. error("E024", state.tokens.next, state.tokens.next.value);
  2523. return false;
  2524. }
  2525. }
  2526. if (state.tokens.next.type === "(punctuator)") {
  2527. switch (state.tokens.next.value) {
  2528. case "}":
  2529. case "]":
  2530. case ",":
  2531. if (opts.allowTrailing) {
  2532. return true;
  2533. }
  2534. /* falls through */
  2535. case ")":
  2536. error("E024", state.tokens.next, state.tokens.next.value);
  2537. return false;
  2538. }
  2539. }
  2540. return true;
  2541. }
  2542. // Functional constructors for making the symbols that will be inherited by
  2543. // tokens.
  2544. function symbol(s, p) {
  2545. var x = state.syntax[s];
  2546. if (!x || typeof x !== "object") {
  2547. state.syntax[s] = x = {
  2548. id: s,
  2549. lbp: p,
  2550. value: s
  2551. };
  2552. }
  2553. return x;
  2554. }
  2555. function delim(s) {
  2556. var x = symbol(s, 0);
  2557. x.delim = true;
  2558. return x;
  2559. }
  2560. function stmt(s, f) {
  2561. var x = delim(s);
  2562. x.identifier = x.reserved = true;
  2563. x.fud = f;
  2564. return x;
  2565. }
  2566. function blockstmt(s, f) {
  2567. var x = stmt(s, f);
  2568. x.block = true;
  2569. return x;
  2570. }
  2571. function reserveName(x) {
  2572. var c = x.id.charAt(0);
  2573. if ((c >= "a" && c <= "z") || (c >= "A" && c <= "Z")) {
  2574. x.identifier = x.reserved = true;
  2575. }
  2576. return x;
  2577. }
  2578. function prefix(s, f) {
  2579. var x = symbol(s, 150);
  2580. reserveName(x);
  2581. x.nud = (typeof f === "function") ? f : function() {
  2582. this.arity = "unary";
  2583. this.right = expression(150);
  2584. if (this.id === "++" || this.id === "--") {
  2585. if (state.option.plusplus) {
  2586. warning("W016", this, this.id);
  2587. } else if (this.right && (!this.right.identifier || isReserved(this.right)) &&
  2588. this.right.id !== "." && this.right.id !== "[") {
  2589. warning("W017", this);
  2590. }
  2591. // detect increment/decrement of a const
  2592. // in the case of a.b, right will be the "." punctuator
  2593. if (this.right && this.right.identifier) {
  2594. if (state.funct["(blockscope)"].labeltype(this.right.value) === "const") {
  2595. error("E013", this, this.right.value);
  2596. }
  2597. }
  2598. }
  2599. return this;
  2600. };
  2601. return x;
  2602. }
  2603. function type(s, f) {
  2604. var x = delim(s);
  2605. x.type = s;
  2606. x.nud = f;
  2607. return x;
  2608. }
  2609. function reserve(name, func) {
  2610. var x = type(name, func);
  2611. x.identifier = true;
  2612. x.reserved = true;
  2613. return x;
  2614. }
  2615. function FutureReservedWord(name, meta) {
  2616. var x = type(name, (meta && meta.nud) || function() {
  2617. return this;
  2618. });
  2619. meta = meta || {};
  2620. meta.isFutureReservedWord = true;
  2621. x.value = name;
  2622. x.identifier = true;
  2623. x.reserved = true;
  2624. x.meta = meta;
  2625. return x;
  2626. }
  2627. function reservevar(s, v) {
  2628. return reserve(s, function() {
  2629. if (typeof v === "function") {
  2630. v(this);
  2631. }
  2632. return this;
  2633. });
  2634. }
  2635. function infix(s, f, p, w) {
  2636. var x = symbol(s, p);
  2637. reserveName(x);
  2638. x.infix = true;
  2639. x.led = function(left) {
  2640. if (!w) {
  2641. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  2642. }
  2643. if ((s === "in" || s === "instanceof") && left.id === "!") {
  2644. warning("W018", left, "!");
  2645. }
  2646. if (typeof f === "function") {
  2647. return f(left, this);
  2648. } else {
  2649. this.left = left;
  2650. this.right = expression(p);
  2651. return this;
  2652. }
  2653. };
  2654. return x;
  2655. }
  2656. function application(s) {
  2657. var x = symbol(s, 42);
  2658. x.led = function(left) {
  2659. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  2660. this.left = left;
  2661. this.right = doFunction({ type: "arrow", loneArg: left });
  2662. return this;
  2663. };
  2664. return x;
  2665. }
  2666. function relation(s, f) {
  2667. var x = symbol(s, 100);
  2668. x.led = function(left) {
  2669. nobreaknonadjacent(state.tokens.prev, state.tokens.curr);
  2670. this.left = left;
  2671. var right = this.right = expression(100);
  2672. if (isIdentifier(left, "NaN") || isIdentifier(right, "NaN")) {
  2673. warning("W019", this);
  2674. } else if (f) {
  2675. f.apply(this, [left, right]);
  2676. }
  2677. if (!left || !right) {
  2678. quit("E041", state.tokens.curr.line);
  2679. }
  2680. if (left.id === "!") {
  2681. warning("W018", left, "!");
  2682. }
  2683. if (right.id === "!") {
  2684. warning("W018", right, "!");
  2685. }
  2686. return this;
  2687. };
  2688. return x;
  2689. }
  2690. function isPoorRelation(node) {
  2691. return node &&
  2692. ((node.type === "(number)" && +node.value === 0) ||
  2693. (node.type === "(string)" && node.value === "") ||
  2694. (node.type === "null" && !state.option.eqnull) ||
  2695. node.type === "true" ||
  2696. node.type === "false" ||
  2697. node.type === "undefined");
  2698. }
  2699. var typeofValues = {};
  2700. typeofValues.legacy = [
  2701. // E4X extended the `typeof` operator to return "xml" for the XML and
  2702. // XMLList types it introduced.
  2703. // Ref: 11.3.2 The typeof Operator
  2704. // http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-357.pdf
  2705. "xml",
  2706. // IE<9 reports "unknown" when the `typeof` operator is applied to an
  2707. // object existing across a COM+ bridge. In lieu of official documentation
  2708. // (which does not exist), see:
  2709. // http://robertnyman.com/2005/12/21/what-is-typeof-unknown/
  2710. "unknown"
  2711. ];
  2712. typeofValues.es3 = [
  2713. "undefined", "boolean", "number", "string", "function", "object",
  2714. ];
  2715. typeofValues.es3 = typeofValues.es3.concat(typeofValues.legacy);
  2716. typeofValues.es6 = typeofValues.es3.concat("symbol");
  2717. // Checks whether the 'typeof' operator is used with the correct
  2718. // value. For docs on 'typeof' see:
  2719. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
  2720. function isTypoTypeof(left, right, state) {
  2721. var values;
  2722. if (state.option.notypeof)
  2723. return false;
  2724. if (!left || !right)
  2725. return false;
  2726. values = state.inESNext() ? typeofValues.es6 : typeofValues.es3;
  2727. if (right.type === "(identifier)" && right.value === "typeof" && left.type === "(string)")
  2728. return !_.contains(values, left.value);
  2729. return false;
  2730. }
  2731. function isGlobalEval(left, state) {
  2732. var isGlobal = false;
  2733. // permit methods to refer to an "eval" key in their own context
  2734. if (left.type === "this" && state.funct["(context)"] === null) {
  2735. isGlobal = true;
  2736. }
  2737. // permit use of "eval" members of objects
  2738. else if (left.type === "(identifier)") {
  2739. if (state.option.node && left.value === "global") {
  2740. isGlobal = true;
  2741. }
  2742. else if (state.option.browser && (left.value === "window" || left.value === "document")) {
  2743. isGlobal = true;
  2744. }
  2745. }
  2746. return isGlobal;
  2747. }
  2748. function findNativePrototype(left) {
  2749. var natives = [
  2750. "Array", "ArrayBuffer", "Boolean", "Collator", "DataView", "Date",
  2751. "DateTimeFormat", "Error", "EvalError", "Float32Array", "Float64Array",
  2752. "Function", "Infinity", "Intl", "Int16Array", "Int32Array", "Int8Array",
  2753. "Iterator", "Number", "NumberFormat", "Object", "RangeError",
  2754. "ReferenceError", "RegExp", "StopIteration", "String", "SyntaxError",
  2755. "TypeError", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray",
  2756. "URIError"
  2757. ];
  2758. function walkPrototype(obj) {
  2759. if (typeof obj !== "object") return;
  2760. return obj.right === "prototype" ? obj : walkPrototype(obj.left);
  2761. }
  2762. function walkNative(obj) {
  2763. while (!obj.identifier && typeof obj.left === "object")
  2764. obj = obj.left;
  2765. if (obj.identifier && natives.indexOf(obj.value) >= 0)
  2766. return obj.value;
  2767. }
  2768. var prototype = walkPrototype(left);
  2769. if (prototype) return walkNative(prototype);
  2770. }
  2771. function assignop(s, f, p) {
  2772. var x = infix(s, typeof f === "function" ? f : function(left, that) {
  2773. that.left = left;
  2774. if (left) {
  2775. if (state.option.freeze) {
  2776. var nativeObject = findNativePrototype(left);
  2777. if (nativeObject)
  2778. warning("W121", left, nativeObject);
  2779. }
  2780. if (predefined[left.value] === false &&
  2781. scope[left.value]["(global)"] === true) {
  2782. warning("W020", left);
  2783. } else if (left["function"]) {
  2784. warning("W021", left, left.value);
  2785. }
  2786. if (state.funct["(blockscope)"].labeltype(left.value) === "const") {
  2787. error("E013", left, left.value);
  2788. }
  2789. if (left.id === ".") {
  2790. if (!left.left) {
  2791. warning("E031", that);
  2792. } else if (left.left.value === "arguments" && !state.isStrict()) {
  2793. warning("E031", that);
  2794. }
  2795. state.nameStack.set(state.tokens.prev);
  2796. that.right = expression(10);
  2797. return that;
  2798. } else if (left.id === "[") {
  2799. if (state.tokens.curr.left.first) {
  2800. state.tokens.curr.left.first.forEach(function(t) {
  2801. if (t && state.funct[t.value] === "const") {
  2802. error("E013", t, t.value);
  2803. }
  2804. });
  2805. } else if (!left.left) {
  2806. warning("E031", that);
  2807. } else if (left.left.value === "arguments" && !state.isStrict()) {
  2808. warning("E031", that);
  2809. }
  2810. state.nameStack.set(left.right);
  2811. that.right = expression(10);
  2812. return that;
  2813. } else if (left.identifier && !isReserved(left)) {
  2814. if (state.funct[left.value] === "exception") {
  2815. warning("W022", left);
  2816. }
  2817. state.nameStack.set(left);
  2818. that.right = expression(10);
  2819. return that;
  2820. }
  2821. if (left === state.syntax["function"]) {
  2822. warning("W023", state.tokens.curr);
  2823. }
  2824. }
  2825. error("E031", that);
  2826. }, p);
  2827. x.exps = true;
  2828. x.assign = true;
  2829. return x;
  2830. }
  2831. function bitwise(s, f, p) {
  2832. var x = symbol(s, p);
  2833. reserveName(x);
  2834. x.led = (typeof f === "function") ? f : function(left) {
  2835. if (state.option.bitwise) {
  2836. warning("W016", this, this.id);
  2837. }
  2838. this.left = left;
  2839. this.right = expression(p);
  2840. return this;
  2841. };
  2842. return x;
  2843. }
  2844. function bitwiseassignop(s) {
  2845. return assignop(s, function(left, that) {
  2846. if (state.option.bitwise) {
  2847. warning("W016", that, that.id);
  2848. }
  2849. if (left) {
  2850. if (left.id === "." || left.id === "[" ||
  2851. (left.identifier && !isReserved(left))) {
  2852. expression(10);
  2853. return that;
  2854. }
  2855. if (left === state.syntax["function"]) {
  2856. warning("W023", state.tokens.curr);
  2857. }
  2858. return that;
  2859. }
  2860. error("E031", that);
  2861. }, 20);
  2862. }
  2863. function suffix(s) {
  2864. var x = symbol(s, 150);
  2865. x.led = function(left) {
  2866. // this = suffix e.g. "++" punctuator
  2867. // left = symbol operated e.g. "a" identifier or "a.b" punctuator
  2868. if (state.option.plusplus) {
  2869. warning("W016", this, this.id);
  2870. } else if ((!left.identifier || isReserved(left)) && left.id !== "." && left.id !== "[") {
  2871. warning("W017", this);
  2872. }
  2873. // detect increment/decrement of a const
  2874. // in the case of a.b, left will be the "." punctuator
  2875. if (left && left.identifier) {
  2876. if (state.funct["(blockscope)"].labeltype(left.value) === "const") {
  2877. error("E013", this, left.value);
  2878. }
  2879. }
  2880. this.left = left;
  2881. return this;
  2882. };
  2883. return x;
  2884. }
  2885. // fnparam means that this identifier is being defined as a function
  2886. // argument (see identifier())
  2887. // prop means that this identifier is that of an object property
  2888. function optionalidentifier(fnparam, prop, preserve) {
  2889. if (!state.tokens.next.identifier) {
  2890. return;
  2891. }
  2892. if (!preserve) {
  2893. advance();
  2894. }
  2895. var curr = state.tokens.curr;
  2896. var val = state.tokens.curr.value;
  2897. if (!isReserved(curr)) {
  2898. return val;
  2899. }
  2900. if (prop) {
  2901. if (state.inES5()) {
  2902. return val;
  2903. }
  2904. }
  2905. if (fnparam && val === "undefined") {
  2906. return val;
  2907. }
  2908. warning("W024", state.tokens.curr, state.tokens.curr.id);
  2909. return val;
  2910. }
  2911. // fnparam means that this identifier is being defined as a function
  2912. // argument
  2913. // prop means that this identifier is that of an object property
  2914. function identifier(fnparam, prop) {
  2915. var i = optionalidentifier(fnparam, prop, false);
  2916. if (i) {
  2917. return i;
  2918. }
  2919. // parameter destructuring with rest operator
  2920. if (state.tokens.next.value === "...") {
  2921. if (!state.option.esnext) {
  2922. warning("W119", state.tokens.next, "spread/rest operator");
  2923. }
  2924. advance();
  2925. if (checkPunctuators(state.tokens.next, ["..."])) {
  2926. warning("E024", state.tokens.next, "...");
  2927. while (checkPunctuators(state.tokens.next, ["..."])) {
  2928. advance();
  2929. }
  2930. }
  2931. if (!state.tokens.next.identifier) {
  2932. warning("E024", state.tokens.curr, "...");
  2933. return;
  2934. }
  2935. return identifier(fnparam, prop);
  2936. } else {
  2937. error("E030", state.tokens.next, state.tokens.next.value);
  2938. // The token should be consumed after a warning is issued so the parser
  2939. // can continue as though an identifier were found. The semicolon token
  2940. // should not be consumed in this way so that the parser interprets it as
  2941. // a statement delimeter;
  2942. if (state.tokens.next.id !== ";") {
  2943. advance();
  2944. }
  2945. }
  2946. }
  2947. function reachable(controlToken) {
  2948. var i = 0, t;
  2949. if (state.tokens.next.id !== ";" || controlToken.inBracelessBlock) {
  2950. return;
  2951. }
  2952. for (;;) {
  2953. do {
  2954. t = peek(i);
  2955. i += 1;
  2956. } while (t.id !== "(end)" && t.id === "(comment)");
  2957. if (t.reach) {
  2958. return;
  2959. }
  2960. if (t.id !== "(endline)") {
  2961. if (t.id === "function") {
  2962. if (state.option.latedef === true) {
  2963. warning("W026", t);
  2964. }
  2965. break;
  2966. }
  2967. warning("W027", t, t.value, controlToken.value);
  2968. break;
  2969. }
  2970. }
  2971. }
  2972. function parseFinalSemicolon() {
  2973. if (state.tokens.next.id !== ";") {
  2974. // don't complain about unclosed templates / strings
  2975. if (state.tokens.next.isUnclosed) return advance();
  2976. if (!state.option.asi) {
  2977. // If this is the last statement in a block that ends on
  2978. // the same line *and* option lastsemic is on, ignore the warning.
  2979. // Otherwise, complain about missing semicolon.
  2980. if (!state.option.lastsemic || state.tokens.next.id !== "}" ||
  2981. startLine(state.tokens.next) !== state.tokens.curr.line) {
  2982. warningAt("W033", state.tokens.curr.line, state.tokens.curr.character);
  2983. }
  2984. }
  2985. } else {
  2986. advance(";");
  2987. }
  2988. }
  2989. function statement() {
  2990. var i = indent, r, s = scope, t = state.tokens.next;
  2991. if (t.id === ";") {
  2992. advance(";");
  2993. return;
  2994. }
  2995. // Is this a labelled statement?
  2996. var res = isReserved(t);
  2997. // We're being more tolerant here: if someone uses
  2998. // a FutureReservedWord as a label, we warn but proceed
  2999. // anyway.
  3000. if (res && t.meta && t.meta.isFutureReservedWord && peek().id === ":") {
  3001. warning("W024", t, t.id);
  3002. res = false;
  3003. }
  3004. // detect a module import declaration
  3005. if (t.value === "module" && t.type === "(identifier)") {
  3006. if (peek().type === "(identifier)") {
  3007. if (!state.inESNext()) {
  3008. warning("W119", state.tokens.curr, "module");
  3009. }
  3010. advance("module");
  3011. var name = identifier();
  3012. addlabel(name, { type: "unused", token: state.tokens.curr });
  3013. advance("from");
  3014. advance("(string)");
  3015. parseFinalSemicolon();
  3016. return;
  3017. }
  3018. }
  3019. if (t.identifier && !res && peek().id === ":") {
  3020. advance();
  3021. advance(":");
  3022. scope = Object.create(s);
  3023. addlabel(t.value, { type: "label" });
  3024. if (!state.tokens.next.labelled && state.tokens.next.value !== "{") {
  3025. warning("W028", state.tokens.next, t.value, state.tokens.next.value);
  3026. }
  3027. state.tokens.next.label = t.value;
  3028. t = state.tokens.next;
  3029. }
  3030. // Is it a lonely block?
  3031. if (t.id === "{") {
  3032. // Is it a switch case block?
  3033. //
  3034. // switch (foo) {
  3035. // case bar: { <= here.
  3036. // ...
  3037. // }
  3038. // }
  3039. var iscase = (state.funct["(verb)"] === "case" && state.tokens.curr.value === ":");
  3040. block(true, true, false, false, iscase);
  3041. return;
  3042. }
  3043. // Parse the statement.
  3044. r = expression(0, true);
  3045. if (r && (!r.identifier || r.value !== "function") && (r.type !== "(punctuator)")) {
  3046. if (!state.isStrict() &&
  3047. state.option.globalstrict &&
  3048. state.option.strict) {
  3049. warning("E007");
  3050. }
  3051. }
  3052. // Look for the final semicolon.
  3053. if (!t.block) {
  3054. if (!state.option.expr && (!r || !r.exps)) {
  3055. warning("W030", state.tokens.curr);
  3056. } else if (state.option.nonew && r && r.left && r.id === "(" && r.left.id === "new") {
  3057. warning("W031", t);
  3058. }
  3059. parseFinalSemicolon();
  3060. }
  3061. // Restore the indentation.
  3062. indent = i;
  3063. scope = s;
  3064. return r;
  3065. }
  3066. function statements() {
  3067. var a = [], p;
  3068. while (!state.tokens.next.reach && state.tokens.next.id !== "(end)") {
  3069. if (state.tokens.next.id === ";") {
  3070. p = peek();
  3071. if (!p || (p.id !== "(" && p.id !== "[")) {
  3072. warning("W032");
  3073. }
  3074. advance(";");
  3075. } else {
  3076. a.push(statement());
  3077. }
  3078. }
  3079. return a;
  3080. }
  3081. /*
  3082. * read all directives
  3083. * recognizes a simple form of asi, but always
  3084. * warns, if it is used
  3085. */
  3086. function directives() {
  3087. var i, p, pn;
  3088. while (state.tokens.next.id === "(string)") {
  3089. p = peek(0);
  3090. if (p.id === "(endline)") {
  3091. i = 1;
  3092. do {
  3093. pn = peek(i++);
  3094. } while (pn.id === "(endline)");
  3095. if (pn.id === ";") {
  3096. p = pn;
  3097. } else if (pn.value === "[" || pn.value === ".") {
  3098. // string -> [ | . is a valid production
  3099. return;
  3100. } else if (!state.option.asi || pn.value === "(") {
  3101. // string -> ( is not a valid production
  3102. warning("W033", state.tokens.next);
  3103. }
  3104. } else if (p.id === "." || p.id === "[") {
  3105. return;
  3106. } else if (p.id !== ";") {
  3107. warning("W033", p);
  3108. }
  3109. advance();
  3110. if (state.directive[state.tokens.curr.value]) {
  3111. warning("W034", state.tokens.curr, state.tokens.curr.value);
  3112. }
  3113. if (state.tokens.curr.value === "use strict") {
  3114. if (!state.option["(explicitNewcap)"]) {
  3115. state.option.newcap = true;
  3116. }
  3117. state.option.undef = true;
  3118. }
  3119. // there's no directive negation, so always set to true
  3120. state.directive[state.tokens.curr.value] = true;
  3121. if (p.id === ";") {
  3122. advance(";");
  3123. }
  3124. }
  3125. }
  3126. /*
  3127. * Parses a single block. A block is a sequence of statements wrapped in
  3128. * braces.
  3129. *
  3130. * ordinary - true for everything but function bodies and try blocks.
  3131. * stmt - true if block can be a single statement (e.g. in if/for/while).
  3132. * isfunc - true if block is a function body
  3133. * isfatarrow - true if its a body of a fat arrow function
  3134. * iscase - true if block is a switch case block
  3135. */
  3136. function block(ordinary, stmt, isfunc, isfatarrow, iscase) {
  3137. var a,
  3138. b = inblock,
  3139. old_indent = indent,
  3140. m,
  3141. s = scope,
  3142. t,
  3143. line,
  3144. d;
  3145. inblock = ordinary;
  3146. if (!ordinary || !state.option.funcscope)
  3147. scope = Object.create(scope);
  3148. t = state.tokens.next;
  3149. var metrics = state.funct["(metrics)"];
  3150. metrics.nestedBlockDepth += 1;
  3151. metrics.verifyMaxNestedBlockDepthPerFunction();
  3152. if (state.tokens.next.id === "{") {
  3153. advance("{");
  3154. // create a new block scope
  3155. state.funct["(blockscope)"].stack();
  3156. line = state.tokens.curr.line;
  3157. if (state.tokens.next.id !== "}") {
  3158. indent += state.option.indent;
  3159. while (!ordinary && state.tokens.next.from > indent) {
  3160. indent += state.option.indent;
  3161. }
  3162. if (isfunc) {
  3163. m = {};
  3164. for (d in state.directive) {
  3165. if (_.has(state.directive, d)) {
  3166. m[d] = state.directive[d];
  3167. }
  3168. }
  3169. directives();
  3170. if (state.option.strict && state.funct["(context)"]["(global)"]) {
  3171. if (!m["use strict"] && !state.isStrict()) {
  3172. warning("E007");
  3173. }
  3174. }
  3175. }
  3176. a = statements();
  3177. metrics.statementCount += a.length;
  3178. if (isfunc) {
  3179. state.directive = m;
  3180. }
  3181. indent -= state.option.indent;
  3182. }
  3183. advance("}", t);
  3184. state.funct["(blockscope)"].unstack();
  3185. indent = old_indent;
  3186. } else if (!ordinary) {
  3187. if (isfunc) {
  3188. m = {};
  3189. if (stmt && !isfatarrow && !state.inMoz()) {
  3190. error("W118", state.tokens.curr, "function closure expressions");
  3191. }
  3192. if (!stmt) {
  3193. for (d in state.directive) {
  3194. if (_.has(state.directive, d)) {
  3195. m[d] = state.directive[d];
  3196. }
  3197. }
  3198. }
  3199. expression(10);
  3200. if (state.option.strict && state.funct["(context)"]["(global)"]) {
  3201. if (!m["use strict"] && !state.isStrict()) {
  3202. warning("E007");
  3203. }
  3204. }
  3205. } else {
  3206. error("E021", state.tokens.next, "{", state.tokens.next.value);
  3207. }
  3208. } else {
  3209. // check to avoid let declaration not within a block
  3210. state.funct["(noblockscopedvar)"] = true;
  3211. if (!stmt || state.option.curly) {
  3212. warning("W116", state.tokens.next, "{", state.tokens.next.value);
  3213. }
  3214. state.tokens.next.inBracelessBlock = true;
  3215. indent += state.option.indent;
  3216. // test indentation only if statement is in new line
  3217. a = [statement()];
  3218. indent -= state.option.indent;
  3219. delete state.funct["(noblockscopedvar)"];
  3220. }
  3221. // Don't clear and let it propagate out if it is "break", "return" or similar in switch case
  3222. switch (state.funct["(verb)"]) {
  3223. case "break":
  3224. case "continue":
  3225. case "return":
  3226. case "throw":
  3227. if (iscase) {
  3228. break;
  3229. }
  3230. /* falls through */
  3231. default:
  3232. state.funct["(verb)"] = null;
  3233. }
  3234. if (!ordinary || !state.option.funcscope) scope = s;
  3235. inblock = b;
  3236. if (ordinary && state.option.noempty && (!a || a.length === 0)) {
  3237. warning("W035", state.tokens.prev);
  3238. }
  3239. metrics.nestedBlockDepth -= 1;
  3240. return a;
  3241. }
  3242. function countMember(m) {
  3243. if (membersOnly && typeof membersOnly[m] !== "boolean") {
  3244. warning("W036", state.tokens.curr, m);
  3245. }
  3246. if (typeof member[m] === "number") {
  3247. member[m] += 1;
  3248. } else {
  3249. member[m] = 1;
  3250. }
  3251. }
  3252. function note_implied(tkn) {
  3253. var name = tkn.value;
  3254. var desc = Object.getOwnPropertyDescriptor(implied, name);
  3255. if (!desc)
  3256. implied[name] = [tkn.line];
  3257. else
  3258. desc.value.push(tkn.line);
  3259. }
  3260. // Build the syntax table by declaring the syntactic elements of the language.
  3261. type("(number)", function() {
  3262. return this;
  3263. });
  3264. type("(string)", function() {
  3265. return this;
  3266. });
  3267. state.syntax["(identifier)"] = {
  3268. type: "(identifier)",
  3269. lbp: 0,
  3270. identifier: true,
  3271. nud: function() {
  3272. var v = this.value;
  3273. // s will be either the function object 'state.funct' that the identifier points at
  3274. // or it will be a boolean if it is a predefined variable
  3275. var s = scope[v];
  3276. var f;
  3277. var block;
  3278. // If this identifier is the lone parameter to a shorthand "fat arrow"
  3279. // function definition, i.e.
  3280. //
  3281. // x => x;
  3282. //
  3283. // ...it should not be considered as a variable in the current scope. It
  3284. // will be added to the scope of the new function when the next token is
  3285. // parsed, so it can be safely ignored for now.
  3286. if (state.tokens.next.id === "=>") {
  3287. return this;
  3288. }
  3289. block = state.funct["(blockscope)"].getlabel(v);
  3290. if (typeof s === "function") {
  3291. // Protection against accidental inheritance.
  3292. s = undefined;
  3293. } else if (!block && typeof s === "boolean") {
  3294. f = state.funct;
  3295. state.funct = functions[0];
  3296. addlabel(v, { type: "var" });
  3297. s = state.funct;
  3298. state.funct = f;
  3299. }
  3300. // The name is in scope and defined in the current function or it exists in the blockscope.
  3301. if (state.funct === s || block) {
  3302. // Change 'unused' to 'var', and reject labels.
  3303. // the name is in a block scope.
  3304. switch (block ? block[v]["(type)"] : state.funct[v]) {
  3305. case "unused":
  3306. if (block) block[v]["(type)"] = "var";
  3307. else state.funct[v] = "var";
  3308. break;
  3309. case "unction":
  3310. if (block) block[v]["(type)"] = "function";
  3311. else state.funct[v] = "function";
  3312. this["function"] = true;
  3313. break;
  3314. case "const":
  3315. // consts can only exist inside block
  3316. // because they are never added to the scope, s
  3317. block[v]["(unused)"] = false;
  3318. break;
  3319. case "function":
  3320. this["function"] = true;
  3321. break;
  3322. case "label":
  3323. warning("W037", state.tokens.curr, v);
  3324. break;
  3325. }
  3326. } else {
  3327. // If the name is already defined in the current
  3328. // function, but not as outer, then there is a scope error.
  3329. switch (state.funct[v]) {
  3330. case "closure":
  3331. case "function":
  3332. case "var":
  3333. case "unused":
  3334. warning("W038", state.tokens.curr, v);
  3335. break;
  3336. case "label":
  3337. warning("W037", state.tokens.curr, v);
  3338. break;
  3339. case "outer":
  3340. case "global":
  3341. break;
  3342. default:
  3343. // If the name is defined in an outer function, make an outer entry,
  3344. // and if it was unused, make it var.
  3345. if (s === true) {
  3346. state.funct[v] = true;
  3347. } else if (s === null) {
  3348. warning("W039", state.tokens.curr, v);
  3349. note_implied(state.tokens.curr);
  3350. } else if (typeof s !== "object") {
  3351. // if we're in a list comprehension, variables are declared
  3352. // locally and used before being defined. So we check
  3353. // the presence of the given variable in the comp array
  3354. // before declaring it undefined.
  3355. if (!state.funct["(comparray)"].check(v)) {
  3356. isundef(state.funct, "W117", state.tokens.curr, v);
  3357. }
  3358. // Explicitly mark the variable as used within function scopes
  3359. if (!state.funct["(global)"]) {
  3360. state.funct[v] = true;
  3361. }
  3362. note_implied(state.tokens.curr);
  3363. } else {
  3364. switch (s[v]) {
  3365. case "function":
  3366. case "unction":
  3367. this["function"] = true;
  3368. s[v] = "closure";
  3369. state.funct[v] = s["(global)"] ? "global" : "outer";
  3370. break;
  3371. case "var":
  3372. case "unused":
  3373. s[v] = "closure";
  3374. state.funct[v] = s["(global)"] ? "global" : "outer";
  3375. break;
  3376. case "closure":
  3377. state.funct[v] = s["(global)"] ? "global" : "outer";
  3378. break;
  3379. case "label":
  3380. warning("W037", state.tokens.curr, v);
  3381. }
  3382. }
  3383. }
  3384. }
  3385. return this;
  3386. },
  3387. led: function() {
  3388. error("E033", state.tokens.next, state.tokens.next.value);
  3389. }
  3390. };
  3391. var baseTemplateSyntax = {
  3392. lbp: 0,
  3393. identifier: false,
  3394. template: true,
  3395. };
  3396. state.syntax["(template)"] = _.extend({
  3397. type: "(template)",
  3398. nud: doTemplateLiteral,
  3399. led: doTemplateLiteral,
  3400. noSubst: false
  3401. }, baseTemplateSyntax);
  3402. state.syntax["(template middle)"] = _.extend({
  3403. type: "(template middle)",
  3404. middle: true,
  3405. noSubst: false
  3406. }, baseTemplateSyntax);
  3407. state.syntax["(template tail)"] = _.extend({
  3408. type: "(template tail)",
  3409. tail: true,
  3410. noSubst: false
  3411. }, baseTemplateSyntax);
  3412. state.syntax["(no subst template)"] = _.extend({
  3413. type: "(template)",
  3414. nud: doTemplateLiteral,
  3415. led: doTemplateLiteral,
  3416. noSubst: true,
  3417. tail: true // mark as tail, since it's always the last component
  3418. }, baseTemplateSyntax);
  3419. type("(regexp)", function() {
  3420. return this;
  3421. });
  3422. // ECMAScript parser
  3423. delim("(endline)");
  3424. delim("(begin)");
  3425. delim("(end)").reach = true;
  3426. delim("(error)").reach = true;
  3427. delim("}").reach = true;
  3428. delim(")");
  3429. delim("]");
  3430. delim("\"").reach = true;
  3431. delim("'").reach = true;
  3432. delim(";");
  3433. delim(":").reach = true;
  3434. delim("#");
  3435. reserve("else");
  3436. reserve("case").reach = true;
  3437. reserve("catch");
  3438. reserve("default").reach = true;
  3439. reserve("finally");
  3440. reservevar("arguments", function(x) {
  3441. if (state.isStrict() && state.funct["(global)"]) {
  3442. warning("E008", x);
  3443. }
  3444. });
  3445. reservevar("eval");
  3446. reservevar("false");
  3447. reservevar("Infinity");
  3448. reservevar("null");
  3449. reservevar("this", function(x) {
  3450. if (state.isStrict() && !isMethod() &&
  3451. !state.option.validthis && ((state.funct["(statement)"] &&
  3452. state.funct["(name)"].charAt(0) > "Z") || state.funct["(global)"])) {
  3453. warning("W040", x);
  3454. }
  3455. });
  3456. reservevar("true");
  3457. reservevar("undefined");
  3458. assignop("=", "assign", 20);
  3459. assignop("+=", "assignadd", 20);
  3460. assignop("-=", "assignsub", 20);
  3461. assignop("*=", "assignmult", 20);
  3462. assignop("/=", "assigndiv", 20).nud = function() {
  3463. error("E014");
  3464. };
  3465. assignop("%=", "assignmod", 20);
  3466. bitwiseassignop("&=");
  3467. bitwiseassignop("|=");
  3468. bitwiseassignop("^=");
  3469. bitwiseassignop("<<=");
  3470. bitwiseassignop(">>=");
  3471. bitwiseassignop(">>>=");
  3472. infix(",", function(left, that) {
  3473. var expr;
  3474. that.exprs = [left];
  3475. if (state.option.nocomma) {
  3476. warning("W127");
  3477. }
  3478. if (!comma({ peek: true })) {
  3479. return that;
  3480. }
  3481. while (true) {
  3482. if (!(expr = expression(10))) {
  3483. break;
  3484. }
  3485. that.exprs.push(expr);
  3486. if (state.tokens.next.value !== "," || !comma()) {
  3487. break;
  3488. }
  3489. }
  3490. return that;
  3491. }, 10, true);
  3492. infix("?", function(left, that) {
  3493. increaseComplexityCount();
  3494. that.left = left;
  3495. that.right = expression(10);
  3496. advance(":");
  3497. that["else"] = expression(10);
  3498. return that;
  3499. }, 30);
  3500. var orPrecendence = 40;
  3501. infix("||", function(left, that) {
  3502. increaseComplexityCount();
  3503. that.left = left;
  3504. that.right = expression(orPrecendence);
  3505. return that;
  3506. }, orPrecendence);
  3507. infix("&&", "and", 50);
  3508. bitwise("|", "bitor", 70);
  3509. bitwise("^", "bitxor", 80);
  3510. bitwise("&", "bitand", 90);
  3511. relation("==", function(left, right) {
  3512. var eqnull = state.option.eqnull && (left.value === "null" || right.value === "null");
  3513. switch (true) {
  3514. case !eqnull && state.option.eqeqeq:
  3515. this.from = this.character;
  3516. warning("W116", this, "===", "==");
  3517. break;
  3518. case isPoorRelation(left):
  3519. warning("W041", this, "===", left.value);
  3520. break;
  3521. case isPoorRelation(right):
  3522. warning("W041", this, "===", right.value);
  3523. break;
  3524. case isTypoTypeof(right, left, state):
  3525. warning("W122", this, right.value);
  3526. break;
  3527. case isTypoTypeof(left, right, state):
  3528. warning("W122", this, left.value);
  3529. break;
  3530. }
  3531. return this;
  3532. });
  3533. relation("===", function(left, right) {
  3534. if (isTypoTypeof(right, left, state)) {
  3535. warning("W122", this, right.value);
  3536. } else if (isTypoTypeof(left, right, state)) {
  3537. warning("W122", this, left.value);
  3538. }
  3539. return this;
  3540. });
  3541. relation("!=", function(left, right) {
  3542. var eqnull = state.option.eqnull &&
  3543. (left.value === "null" || right.value === "null");
  3544. if (!eqnull && state.option.eqeqeq) {
  3545. this.from = this.character;
  3546. warning("W116", this, "!==", "!=");
  3547. } else if (isPoorRelation(left)) {
  3548. warning("W041", this, "!==", left.value);
  3549. } else if (isPoorRelation(right)) {
  3550. warning("W041", this, "!==", right.value);
  3551. } else if (isTypoTypeof(right, left, state)) {
  3552. warning("W122", this, right.value);
  3553. } else if (isTypoTypeof(left, right, state)) {
  3554. warning("W122", this, left.value);
  3555. }
  3556. return this;
  3557. });
  3558. relation("!==", function(left, right) {
  3559. if (isTypoTypeof(right, left, state)) {
  3560. warning("W122", this, right.value);
  3561. } else if (isTypoTypeof(left, right, state)) {
  3562. warning("W122", this, left.value);
  3563. }
  3564. return this;
  3565. });
  3566. relation("<");
  3567. relation(">");
  3568. relation("<=");
  3569. relation(">=");
  3570. bitwise("<<", "shiftleft", 120);
  3571. bitwise(">>", "shiftright", 120);
  3572. bitwise(">>>", "shiftrightunsigned", 120);
  3573. infix("in", "in", 120);
  3574. infix("instanceof", "instanceof", 120);
  3575. infix("+", function(left, that) {
  3576. var right;
  3577. that.left = left;
  3578. that.right = right = expression(130);
  3579. if (left && right && left.id === "(string)" && right.id === "(string)") {
  3580. left.value += right.value;
  3581. left.character = right.character;
  3582. if (!state.option.scripturl && reg.javascriptURL.test(left.value)) {
  3583. warning("W050", left);
  3584. }
  3585. return left;
  3586. }
  3587. return that;
  3588. }, 130);
  3589. prefix("+", "num");
  3590. prefix("+++", function() {
  3591. warning("W007");
  3592. this.arity = "unary";
  3593. this.right = expression(150);
  3594. return this;
  3595. });
  3596. infix("+++", function(left) {
  3597. warning("W007");
  3598. this.left = left;
  3599. this.right = expression(130);
  3600. return this;
  3601. }, 130);
  3602. infix("-", "sub", 130);
  3603. prefix("-", "neg");
  3604. prefix("---", function() {
  3605. warning("W006");
  3606. this.arity = "unary";
  3607. this.right = expression(150);
  3608. return this;
  3609. });
  3610. infix("---", function(left) {
  3611. warning("W006");
  3612. this.left = left;
  3613. this.right = expression(130);
  3614. return this;
  3615. }, 130);
  3616. infix("*", "mult", 140);
  3617. infix("/", "div", 140);
  3618. infix("%", "mod", 140);
  3619. suffix("++");
  3620. prefix("++", "preinc");
  3621. state.syntax["++"].exps = true;
  3622. suffix("--");
  3623. prefix("--", "predec");
  3624. state.syntax["--"].exps = true;
  3625. prefix("delete", function() {
  3626. var p = expression(10);
  3627. if (!p) {
  3628. return this;
  3629. }
  3630. if (p.id !== "." && p.id !== "[") {
  3631. warning("W051");
  3632. }
  3633. this.first = p;
  3634. // The `delete` operator accepts unresolvable references when not in strict
  3635. // mode, so the operand may be undefined.
  3636. if (p.identifier && !state.isStrict()) {
  3637. p.forgiveUndef = true;
  3638. }
  3639. return this;
  3640. }).exps = true;
  3641. prefix("~", function() {
  3642. if (state.option.bitwise) {
  3643. warning("W016", this, "~");
  3644. }
  3645. this.arity = "unary";
  3646. expression(150);
  3647. return this;
  3648. });
  3649. prefix("...", function() {
  3650. if (!state.option.esnext) {
  3651. warning("W119", this, "spread/rest operator");
  3652. }
  3653. // TODO: Allow all AssignmentExpression
  3654. // once parsing permits.
  3655. //
  3656. // How to handle eg. number, boolean when the built-in
  3657. // prototype of may have an @@iterator definition?
  3658. //
  3659. // Number.prototype[Symbol.iterator] = function * () {
  3660. // yield this.valueOf();
  3661. // };
  3662. //
  3663. // var a = [ ...1 ];
  3664. // console.log(a); // [1];
  3665. //
  3666. // for (let n of [...10]) {
  3667. // console.log(n);
  3668. // }
  3669. // // 10
  3670. //
  3671. //
  3672. // Boolean.prototype[Symbol.iterator] = function * () {
  3673. // yield this.valueOf();
  3674. // };
  3675. //
  3676. // var a = [ ...true ];
  3677. // console.log(a); // [true];
  3678. //
  3679. // for (let n of [...false]) {
  3680. // console.log(n);
  3681. // }
  3682. // // false
  3683. //
  3684. if (!state.tokens.next.identifier &&
  3685. state.tokens.next.type !== "(string)" &&
  3686. !checkPunctuators(state.tokens.next, ["[", "("])) {
  3687. error("E030", state.tokens.next, state.tokens.next.value);
  3688. }
  3689. expression(150);
  3690. return this;
  3691. });
  3692. prefix("!", function() {
  3693. this.arity = "unary";
  3694. this.right = expression(150);
  3695. if (!this.right) { // '!' followed by nothing? Give up.
  3696. quit("E041", this.line || 0);
  3697. }
  3698. if (bang[this.right.id] === true) {
  3699. warning("W018", this, "!");
  3700. }
  3701. return this;
  3702. });
  3703. prefix("typeof", (function() {
  3704. var p = expression(150);
  3705. this.first = p;
  3706. // The `typeof` operator accepts unresolvable references, so the operand
  3707. // may be undefined.
  3708. if (p.identifier) {
  3709. p.forgiveUndef = true;
  3710. }
  3711. return this;
  3712. }));
  3713. prefix("new", function() {
  3714. var c = expression(155), i;
  3715. if (c && c.id !== "function") {
  3716. if (c.identifier) {
  3717. c["new"] = true;
  3718. switch (c.value) {
  3719. case "Number":
  3720. case "String":
  3721. case "Boolean":
  3722. case "Math":
  3723. case "JSON":
  3724. warning("W053", state.tokens.prev, c.value);
  3725. break;
  3726. case "Symbol":
  3727. if (state.option.esnext) {
  3728. warning("W053", state.tokens.prev, c.value);
  3729. }
  3730. break;
  3731. case "Function":
  3732. if (!state.option.evil) {
  3733. warning("W054");
  3734. }
  3735. break;
  3736. case "Date":
  3737. case "RegExp":
  3738. case "this":
  3739. break;
  3740. default:
  3741. if (c.id !== "function") {
  3742. i = c.value.substr(0, 1);
  3743. if (state.option.newcap && (i < "A" || i > "Z") && !_.has(global, c.value)) {
  3744. warning("W055", state.tokens.curr);
  3745. }
  3746. }
  3747. }
  3748. } else {
  3749. if (c.id !== "." && c.id !== "[" && c.id !== "(") {
  3750. warning("W056", state.tokens.curr);
  3751. }
  3752. }
  3753. } else {
  3754. if (!state.option.supernew)
  3755. warning("W057", this);
  3756. }
  3757. if (state.tokens.next.id !== "(" && !state.option.supernew) {
  3758. warning("W058", state.tokens.curr, state.tokens.curr.value);
  3759. }
  3760. this.first = c;
  3761. return this;
  3762. });
  3763. state.syntax["new"].exps = true;
  3764. prefix("void").exps = true;
  3765. infix(".", function(left, that) {
  3766. var m = identifier(false, true);
  3767. if (typeof m === "string") {
  3768. countMember(m);
  3769. }
  3770. that.left = left;
  3771. that.right = m;
  3772. if (m && m === "hasOwnProperty" && state.tokens.next.value === "=") {
  3773. warning("W001");
  3774. }
  3775. if (left && left.value === "arguments" && (m === "callee" || m === "caller")) {
  3776. if (state.option.noarg)
  3777. warning("W059", left, m);
  3778. else if (state.isStrict())
  3779. error("E008");
  3780. } else if (!state.option.evil && left && left.value === "document" &&
  3781. (m === "write" || m === "writeln")) {
  3782. warning("W060", left);
  3783. }
  3784. if (!state.option.evil && (m === "eval" || m === "execScript")) {
  3785. if (isGlobalEval(left, state)) {
  3786. warning("W061");
  3787. }
  3788. }
  3789. return that;
  3790. }, 160, true);
  3791. infix("(", function(left, that) {
  3792. if (state.option.immed && left && !left.immed && left.id === "function") {
  3793. warning("W062");
  3794. }
  3795. var n = 0;
  3796. var p = [];
  3797. if (left) {
  3798. if (left.type === "(identifier)") {
  3799. if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) {
  3800. if ("Number String Boolean Date Object Error Symbol".indexOf(left.value) === -1) {
  3801. if (left.value === "Math") {
  3802. warning("W063", left);
  3803. } else if (state.option.newcap) {
  3804. warning("W064", left);
  3805. }
  3806. }
  3807. }
  3808. }
  3809. }
  3810. if (state.tokens.next.id !== ")") {
  3811. for (;;) {
  3812. p[p.length] = expression(10);
  3813. n += 1;
  3814. if (state.tokens.next.id !== ",") {
  3815. break;
  3816. }
  3817. comma();
  3818. }
  3819. }
  3820. advance(")");
  3821. if (typeof left === "object") {
  3822. if (state.inES3() && left.value === "parseInt" && n === 1) {
  3823. warning("W065", state.tokens.curr);
  3824. }
  3825. if (!state.option.evil) {
  3826. if (left.value === "eval" || left.value === "Function" ||
  3827. left.value === "execScript") {
  3828. warning("W061", left);
  3829. if (p[0] && [0].id === "(string)") {
  3830. addInternalSrc(left, p[0].value);
  3831. }
  3832. } else if (p[0] && p[0].id === "(string)" &&
  3833. (left.value === "setTimeout" ||
  3834. left.value === "setInterval")) {
  3835. warning("W066", left);
  3836. addInternalSrc(left, p[0].value);
  3837. // window.setTimeout/setInterval
  3838. } else if (p[0] && p[0].id === "(string)" &&
  3839. left.value === "." &&
  3840. left.left.value === "window" &&
  3841. (left.right === "setTimeout" ||
  3842. left.right === "setInterval")) {
  3843. warning("W066", left);
  3844. addInternalSrc(left, p[0].value);
  3845. }
  3846. }
  3847. if (!left.identifier && left.id !== "." && left.id !== "[" &&
  3848. left.id !== "(" && left.id !== "&&" && left.id !== "||" &&
  3849. left.id !== "?" && !(state.option.esnext && left["(name)"])) {
  3850. warning("W067", that);
  3851. }
  3852. }
  3853. that.left = left;
  3854. return that;
  3855. }, 155, true).exps = true;
  3856. prefix("(", function() {
  3857. var pn = state.tokens.next, pn1, i = -1;
  3858. var ret, triggerFnExpr, first, last;
  3859. var parens = 1;
  3860. var opening = state.tokens.curr;
  3861. var preceeding = state.tokens.prev;
  3862. var isNecessary = !state.option.singleGroups;
  3863. do {
  3864. if (pn.value === "(") {
  3865. parens += 1;
  3866. } else if (pn.value === ")") {
  3867. parens -= 1;
  3868. }
  3869. i += 1;
  3870. pn1 = pn;
  3871. pn = peek(i);
  3872. } while (!(parens === 0 && pn1.value === ")") && pn.value !== ";" && pn.type !== "(end)");
  3873. if (state.tokens.next.id === "function") {
  3874. triggerFnExpr = state.tokens.next.immed = true;
  3875. }
  3876. // If the balanced grouping operator is followed by a "fat arrow", the
  3877. // current token marks the beginning of a "fat arrow" function and parsing
  3878. // should proceed accordingly.
  3879. if (pn.value === "=>") {
  3880. return doFunction({ type: "arrow", parsedOpening: true });
  3881. }
  3882. var exprs = [];
  3883. if (state.tokens.next.id !== ")") {
  3884. for (;;) {
  3885. exprs.push(expression(10));
  3886. if (state.tokens.next.id !== ",") {
  3887. break;
  3888. }
  3889. if (state.option.nocomma) {
  3890. warning("W127");
  3891. }
  3892. comma();
  3893. }
  3894. }
  3895. advance(")", this);
  3896. if (state.option.immed && exprs[0] && exprs[0].id === "function") {
  3897. if (state.tokens.next.id !== "(" &&
  3898. state.tokens.next.id !== "." && state.tokens.next.id !== "[") {
  3899. warning("W068", this);
  3900. }
  3901. }
  3902. if (!exprs.length) {
  3903. return;
  3904. }
  3905. if (exprs.length > 1) {
  3906. ret = Object.create(state.syntax[","]);
  3907. ret.exprs = exprs;
  3908. first = exprs[0];
  3909. last = exprs[exprs.length - 1];
  3910. if (!isNecessary) {
  3911. isNecessary = preceeding.assign || preceeding.delim;
  3912. }
  3913. } else {
  3914. ret = first = last = exprs[0];
  3915. if (!isNecessary) {
  3916. isNecessary =
  3917. // Used to distinguish from an ExpressionStatement which may not
  3918. // begin with the `{` and `function` tokens
  3919. (opening.beginsStmt && (ret.id === "{" || triggerFnExpr || isFunctor(ret))) ||
  3920. // Used to signal that a function expression is being supplied to
  3921. // some other operator.
  3922. (triggerFnExpr &&
  3923. // For parenthesis wrapping a function expression to be considered
  3924. // necessary, the grouping operator should be the left-hand-side of
  3925. // some other operator--either within the parenthesis or directly
  3926. // following them.
  3927. (!isEndOfExpr() || state.tokens.prev.id !== "}")) ||
  3928. // Used to demarcate an arrow function as the left-hand side of some
  3929. // operator.
  3930. (isFunctor(ret) && !isEndOfExpr()) ||
  3931. // Used as the return value of a single-statement arrow function
  3932. (ret.id === "{" && preceeding.id === "=>");
  3933. }
  3934. }
  3935. if (ret) {
  3936. // The operator may be necessary to override the default binding power of
  3937. // neighboring operators (whenever there is an operator in use within the
  3938. // first expression *or* the current group contains multiple expressions)
  3939. if (!isNecessary && (first.left || ret.exprs)) {
  3940. isNecessary =
  3941. (!isBeginOfExpr(preceeding) && first.lbp <= preceeding.lbp) ||
  3942. (!isEndOfExpr() && last.lbp < state.tokens.next.lbp);
  3943. }
  3944. if (!isNecessary) {
  3945. warning("W126", opening);
  3946. }
  3947. ret.paren = true;
  3948. }
  3949. return ret;
  3950. });
  3951. application("=>");
  3952. infix("[", function(left, that) {
  3953. var e = expression(10), s;
  3954. if (e && e.type === "(string)") {
  3955. if (!state.option.evil && (e.value === "eval" || e.value === "execScript")) {
  3956. if (isGlobalEval(left, state)) {
  3957. warning("W061");
  3958. }
  3959. }
  3960. countMember(e.value);
  3961. if (!state.option.sub && reg.identifier.test(e.value)) {
  3962. s = state.syntax[e.value];
  3963. if (!s || !isReserved(s)) {
  3964. warning("W069", state.tokens.prev, e.value);
  3965. }
  3966. }
  3967. }
  3968. advance("]", that);
  3969. if (e && e.value === "hasOwnProperty" && state.tokens.next.value === "=") {
  3970. warning("W001");
  3971. }
  3972. that.left = left;
  3973. that.right = e;
  3974. return that;
  3975. }, 160, true);
  3976. function comprehensiveArrayExpression() {
  3977. var res = {};
  3978. res.exps = true;
  3979. state.funct["(comparray)"].stack();
  3980. // Handle reversed for expressions, used in spidermonkey
  3981. var reversed = false;
  3982. if (state.tokens.next.value !== "for") {
  3983. reversed = true;
  3984. if (!state.inMoz()) {
  3985. warning("W116", state.tokens.next, "for", state.tokens.next.value);
  3986. }
  3987. state.funct["(comparray)"].setState("use");
  3988. res.right = expression(10);
  3989. }
  3990. advance("for");
  3991. if (state.tokens.next.value === "each") {
  3992. advance("each");
  3993. if (!state.inMoz()) {
  3994. warning("W118", state.tokens.curr, "for each");
  3995. }
  3996. }
  3997. advance("(");
  3998. state.funct["(comparray)"].setState("define");
  3999. res.left = expression(130);
  4000. if (_.contains(["in", "of"], state.tokens.next.value)) {
  4001. advance();
  4002. } else {
  4003. error("E045", state.tokens.curr);
  4004. }
  4005. state.funct["(comparray)"].setState("generate");
  4006. expression(10);
  4007. advance(")");
  4008. if (state.tokens.next.value === "if") {
  4009. advance("if");
  4010. advance("(");
  4011. state.funct["(comparray)"].setState("filter");
  4012. res.filter = expression(10);
  4013. advance(")");
  4014. }
  4015. if (!reversed) {
  4016. state.funct["(comparray)"].setState("use");
  4017. res.right = expression(10);
  4018. }
  4019. advance("]");
  4020. state.funct["(comparray)"].unstack();
  4021. return res;
  4022. }
  4023. prefix("[", function() {
  4024. var blocktype = lookupBlockType();
  4025. if (blocktype.isCompArray) {
  4026. if (!state.inESNext()) {
  4027. warning("W119", state.tokens.curr, "array comprehension");
  4028. }
  4029. return comprehensiveArrayExpression();
  4030. } else if (blocktype.isDestAssign && !state.inESNext()) {
  4031. warning("W104", state.tokens.curr, "destructuring assignment");
  4032. }
  4033. var b = state.tokens.curr.line !== startLine(state.tokens.next);
  4034. this.first = [];
  4035. if (b) {
  4036. indent += state.option.indent;
  4037. if (state.tokens.next.from === indent + state.option.indent) {
  4038. indent += state.option.indent;
  4039. }
  4040. }
  4041. while (state.tokens.next.id !== "(end)") {
  4042. while (state.tokens.next.id === ",") {
  4043. if (!state.option.elision) {
  4044. if (!state.inES5()) {
  4045. // Maintain compat with old options --- ES5 mode without
  4046. // elision=true will warn once per comma
  4047. warning("W070");
  4048. } else {
  4049. warning("W128");
  4050. do {
  4051. advance(",");
  4052. } while (state.tokens.next.id === ",");
  4053. continue;
  4054. }
  4055. }
  4056. advance(",");
  4057. }
  4058. if (state.tokens.next.id === "]") {
  4059. break;
  4060. }
  4061. this.first.push(expression(10));
  4062. if (state.tokens.next.id === ",") {
  4063. comma({ allowTrailing: true });
  4064. if (state.tokens.next.id === "]" && !state.inES5(true)) {
  4065. warning("W070", state.tokens.curr);
  4066. break;
  4067. }
  4068. } else {
  4069. break;
  4070. }
  4071. }
  4072. if (b) {
  4073. indent -= state.option.indent;
  4074. }
  4075. advance("]", this);
  4076. return this;
  4077. });
  4078. function isMethod() {
  4079. return state.funct["(statement)"] && state.funct["(statement)"].type === "class" ||
  4080. state.funct["(context)"] && state.funct["(context)"]["(verb)"] === "class";
  4081. }
  4082. function isPropertyName(token) {
  4083. return token.identifier || token.id === "(string)" || token.id === "(number)";
  4084. }
  4085. function propertyName(preserveOrToken) {
  4086. var id;
  4087. var preserve = true;
  4088. if (typeof preserveOrToken === "object") {
  4089. id = preserveOrToken;
  4090. } else {
  4091. preserve = preserveOrToken;
  4092. id = optionalidentifier(false, true, preserve);
  4093. }
  4094. if (!id) {
  4095. if (state.tokens.next.id === "(string)") {
  4096. id = state.tokens.next.value;
  4097. if (!preserve) {
  4098. advance();
  4099. }
  4100. } else if (state.tokens.next.id === "(number)") {
  4101. id = state.tokens.next.value.toString();
  4102. if (!preserve) {
  4103. advance();
  4104. }
  4105. }
  4106. } else if (typeof id === "object") {
  4107. if (id.id === "(string)" || id.id === "(identifier)") id = id.value;
  4108. else if (id.id === "(number)") id = id.value.toString();
  4109. }
  4110. if (id === "hasOwnProperty") {
  4111. warning("W001");
  4112. }
  4113. return id;
  4114. }
  4115. /**
  4116. * @param {Object} [options]
  4117. * @param {token} [options.loneArg] The argument to the function in cases
  4118. * where it was defined using the
  4119. * single-argument shorthand.
  4120. * @param {bool} [options.parsedOpening] Whether the opening parenthesis has
  4121. * already been parsed.
  4122. */
  4123. function functionparams(options) {
  4124. var next;
  4125. var params = [];
  4126. var ident;
  4127. var tokens = [];
  4128. var t;
  4129. var pastDefault = false;
  4130. var pastRest = false;
  4131. var loneArg = options && options.loneArg;
  4132. if (loneArg && loneArg.identifier === true) {
  4133. addlabel(loneArg.value, { type: "unused", token: loneArg });
  4134. return [loneArg.value];
  4135. }
  4136. next = state.tokens.next;
  4137. if (!options || !options.parsedOpening) {
  4138. advance("(");
  4139. }
  4140. if (state.tokens.next.id === ")") {
  4141. advance(")");
  4142. return;
  4143. }
  4144. for (;;) {
  4145. if (_.contains(["{", "["], state.tokens.next.id)) {
  4146. tokens = destructuringExpression();
  4147. for (t in tokens) {
  4148. t = tokens[t];
  4149. if (t.id) {
  4150. params.push(t.id);
  4151. addlabel(t.id, { type: "unused", token: t.token });
  4152. }
  4153. }
  4154. } else {
  4155. if (checkPunctuators(state.tokens.next, ["..."])) pastRest = true;
  4156. ident = identifier(true);
  4157. if (ident) {
  4158. params.push(ident);
  4159. addlabel(ident, { type: "unused", token: state.tokens.curr });
  4160. } else {
  4161. // Skip invalid parameter.
  4162. while (!checkPunctuators(state.tokens.next, [",", ")"])) advance();
  4163. }
  4164. }
  4165. // it is a syntax error to have a regular argument after a default argument
  4166. if (pastDefault) {
  4167. if (state.tokens.next.id !== "=") {
  4168. error("E051", state.tokens.current);
  4169. }
  4170. }
  4171. if (state.tokens.next.id === "=") {
  4172. if (!state.inESNext()) {
  4173. warning("W119", state.tokens.next, "default parameters");
  4174. }
  4175. advance("=");
  4176. pastDefault = true;
  4177. expression(10);
  4178. }
  4179. if (state.tokens.next.id === ",") {
  4180. if (pastRest) {
  4181. warning("W131", state.tokens.next);
  4182. }
  4183. comma();
  4184. } else {
  4185. advance(")", next);
  4186. return params;
  4187. }
  4188. }
  4189. }
  4190. function functor(name, token, scope, overwrites) {
  4191. var funct = {
  4192. "(name)" : name,
  4193. "(breakage)" : 0,
  4194. "(loopage)" : 0,
  4195. "(scope)" : scope,
  4196. "(tokens)" : {},
  4197. "(properties)": {},
  4198. "(catch)" : false,
  4199. "(global)" : false,
  4200. "(line)" : null,
  4201. "(character)" : null,
  4202. "(metrics)" : null,
  4203. "(statement)" : null,
  4204. "(context)" : null,
  4205. "(blockscope)": null,
  4206. "(comparray)" : null,
  4207. "(generator)" : null,
  4208. "(params)" : null
  4209. };
  4210. if (token) {
  4211. _.extend(funct, {
  4212. "(line)" : token.line,
  4213. "(character)": token.character,
  4214. "(metrics)" : createMetrics(token)
  4215. });
  4216. }
  4217. _.extend(funct, overwrites);
  4218. if (funct["(context)"]) {
  4219. funct["(blockscope)"] = funct["(context)"]["(blockscope)"];
  4220. funct["(comparray)"] = funct["(context)"]["(comparray)"];
  4221. }
  4222. return funct;
  4223. }
  4224. function isFunctor(token) {
  4225. return "(scope)" in token;
  4226. }
  4227. /**
  4228. * Determine if the parser has begun parsing executable code.
  4229. *
  4230. * @param {Token} funct - The current "functor" token
  4231. *
  4232. * @returns {boolean}
  4233. */
  4234. function hasParsedCode(funct) {
  4235. return funct["(global)"] && !funct["(verb)"];
  4236. }
  4237. function doTemplateLiteral(left) {
  4238. // ASSERT: this.type === "(template)"
  4239. // jshint validthis: true
  4240. var ctx = this.context;
  4241. var noSubst = this.noSubst;
  4242. var depth = this.depth;
  4243. if (!noSubst) {
  4244. while (!end()) {
  4245. if (!state.tokens.next.template || state.tokens.next.depth > depth) {
  4246. expression(0); // should probably have different rbp?
  4247. } else {
  4248. // skip template start / middle
  4249. advance();
  4250. }
  4251. }
  4252. }
  4253. return {
  4254. id: "(template)",
  4255. type: "(template)",
  4256. tag: left
  4257. };
  4258. function end() {
  4259. if (state.tokens.curr.template && state.tokens.curr.tail &&
  4260. state.tokens.curr.context === ctx) return true;
  4261. var complete = (state.tokens.next.template && state.tokens.next.tail &&
  4262. state.tokens.next.context === ctx);
  4263. if (complete) advance();
  4264. return complete || state.tokens.next.isUnclosed;
  4265. }
  4266. }
  4267. /**
  4268. * @param {Object} [options]
  4269. * @param {token} [options.name] The identifier belonging to the function (if
  4270. * any)
  4271. * @param {boolean} [options.statement] The statement that triggered creation
  4272. * of the current function.
  4273. * @param {string} [options.type] If specified, either "generator" or "arrow"
  4274. * @param {token} [options.loneArg] The argument to the function in cases
  4275. * where it was defined using the
  4276. * single-argument shorthand
  4277. * @param {bool} [options.parsedOpening] Whether the opening parenthesis has
  4278. * already been parsed
  4279. * @param {token} [options.classExprBinding] Define a function with this
  4280. * identifier in the new function's
  4281. * scope, mimicking the bahavior of
  4282. * class expression names within
  4283. * the body of member functions.
  4284. */
  4285. function doFunction(options) {
  4286. var f, name, statement, classExprBinding, isGenerator, isArrow;
  4287. var oldOption = state.option;
  4288. var oldIgnored = state.ignored;
  4289. var oldScope = scope;
  4290. if (options) {
  4291. name = options.name;
  4292. statement = options.statement;
  4293. classExprBinding = options.classExprBinding;
  4294. isGenerator = options.type === "generator";
  4295. isArrow = options.type === "arrow";
  4296. }
  4297. state.option = Object.create(state.option);
  4298. state.ignored = Object.create(state.ignored);
  4299. scope = Object.create(scope);
  4300. state.funct = functor(name || state.nameStack.infer(), state.tokens.next, scope, {
  4301. "(statement)": statement,
  4302. "(context)": state.funct,
  4303. "(generator)": isGenerator
  4304. });
  4305. f = state.funct;
  4306. state.tokens.curr.funct = state.funct;
  4307. functions.push(state.funct);
  4308. if (name) {
  4309. addlabel(name, { type: "function" });
  4310. }
  4311. if (classExprBinding) {
  4312. addlabel(classExprBinding, { type: "function" });
  4313. }
  4314. state.funct["(params)"] = functionparams(options);
  4315. state.funct["(metrics)"].verifyMaxParametersPerFunction(state.funct["(params)"]);
  4316. if (isArrow) {
  4317. if (!state.option.esnext) {
  4318. warning("W119", state.tokens.curr, "arrow function syntax (=>)");
  4319. }
  4320. if (!options.loneArg) {
  4321. advance("=>");
  4322. }
  4323. }
  4324. block(false, true, true, isArrow);
  4325. if (!state.option.noyield && isGenerator &&
  4326. state.funct["(generator)"] !== "yielded") {
  4327. warning("W124", state.tokens.curr);
  4328. }
  4329. state.funct["(metrics)"].verifyMaxStatementsPerFunction();
  4330. state.funct["(metrics)"].verifyMaxComplexityPerFunction();
  4331. state.funct["(unusedOption)"] = state.option.unused;
  4332. scope = oldScope;
  4333. state.option = oldOption;
  4334. state.ignored = oldIgnored;
  4335. state.funct["(last)"] = state.tokens.curr.line;
  4336. state.funct["(lastcharacter)"] = state.tokens.curr.character;
  4337. _.map(Object.keys(state.funct), function(key) {
  4338. if (key[0] === "(") return;
  4339. state.funct["(blockscope)"].unshadow(key);
  4340. });
  4341. state.funct = state.funct["(context)"];
  4342. return f;
  4343. }
  4344. function createMetrics(functionStartToken) {
  4345. return {
  4346. statementCount: 0,
  4347. nestedBlockDepth: -1,
  4348. ComplexityCount: 1,
  4349. verifyMaxStatementsPerFunction: function() {
  4350. if (state.option.maxstatements &&
  4351. this.statementCount > state.option.maxstatements) {
  4352. warning("W071", functionStartToken, this.statementCount);
  4353. }
  4354. },
  4355. verifyMaxParametersPerFunction: function(params) {
  4356. params = params || [];
  4357. if (_.isNumber(state.option.maxparams) && params.length > state.option.maxparams) {
  4358. warning("W072", functionStartToken, params.length);
  4359. }
  4360. },
  4361. verifyMaxNestedBlockDepthPerFunction: function() {
  4362. if (state.option.maxdepth &&
  4363. this.nestedBlockDepth > 0 &&
  4364. this.nestedBlockDepth === state.option.maxdepth + 1) {
  4365. warning("W073", null, this.nestedBlockDepth);
  4366. }
  4367. },
  4368. verifyMaxComplexityPerFunction: function() {
  4369. var max = state.option.maxcomplexity;
  4370. var cc = this.ComplexityCount;
  4371. if (max && cc > max) {
  4372. warning("W074", functionStartToken, cc);
  4373. }
  4374. }
  4375. };
  4376. }
  4377. function increaseComplexityCount() {
  4378. state.funct["(metrics)"].ComplexityCount += 1;
  4379. }
  4380. // Parse assignments that were found instead of conditionals.
  4381. // For example: if (a = 1) { ... }
  4382. function checkCondAssignment(expr) {
  4383. var id, paren;
  4384. if (expr) {
  4385. id = expr.id;
  4386. paren = expr.paren;
  4387. if (id === "," && (expr = expr.exprs[expr.exprs.length - 1])) {
  4388. id = expr.id;
  4389. paren = paren || expr.paren;
  4390. }
  4391. }
  4392. switch (id) {
  4393. case "=":
  4394. case "+=":
  4395. case "-=":
  4396. case "*=":
  4397. case "%=":
  4398. case "&=":
  4399. case "|=":
  4400. case "^=":
  4401. case "/=":
  4402. if (!paren && !state.option.boss) {
  4403. warning("W084");
  4404. }
  4405. }
  4406. }
  4407. /**
  4408. * @param {object} props Collection of property descriptors for a given
  4409. * object.
  4410. */
  4411. function checkProperties(props) {
  4412. // Check for lonely setters if in the ES5 mode.
  4413. if (state.inES5()) {
  4414. for (var name in props) {
  4415. if (_.has(props, name) && props[name].setterToken && !props[name].getterToken) {
  4416. warning("W078", props[name].setterToken);
  4417. }
  4418. }
  4419. }
  4420. }
  4421. (function(x) {
  4422. x.nud = function() {
  4423. var b, f, i, p, t, isGeneratorMethod = false, nextVal;
  4424. var props = {}; // All properties, including accessors
  4425. b = state.tokens.curr.line !== startLine(state.tokens.next);
  4426. if (b) {
  4427. indent += state.option.indent;
  4428. if (state.tokens.next.from === indent + state.option.indent) {
  4429. indent += state.option.indent;
  4430. }
  4431. }
  4432. for (;;) {
  4433. if (state.tokens.next.id === "}") {
  4434. break;
  4435. }
  4436. nextVal = state.tokens.next.value;
  4437. if (state.tokens.next.identifier &&
  4438. (peekIgnoreEOL().id === "," || peekIgnoreEOL().id === "}")) {
  4439. if (!state.inESNext()) {
  4440. warning("W104", state.tokens.next, "object short notation");
  4441. }
  4442. i = propertyName(true);
  4443. saveProperty(props, i, state.tokens.next);
  4444. expression(10);
  4445. } else if (peek().id !== ":" && (nextVal === "get" || nextVal === "set")) {
  4446. advance(nextVal);
  4447. if (!state.inES5()) {
  4448. error("E034");
  4449. }
  4450. i = propertyName();
  4451. // ES6 allows for get() {...} and set() {...} method
  4452. // definition shorthand syntax, so we don't produce an error
  4453. // if the esnext option is enabled.
  4454. if (!i && !state.inESNext()) {
  4455. error("E035");
  4456. }
  4457. // We don't want to save this getter unless it's an actual getter
  4458. // and not an ES6 concise method
  4459. if (i) {
  4460. saveAccessor(nextVal, props, i, state.tokens.curr);
  4461. }
  4462. t = state.tokens.next;
  4463. f = doFunction();
  4464. p = f["(params)"];
  4465. // Don't warn about getter/setter pairs if this is an ES6 concise method
  4466. if (nextVal === "get" && i && p) {
  4467. warning("W076", t, p[0], i);
  4468. } else if (nextVal === "set" && i && (!p || p.length !== 1)) {
  4469. warning("W077", t, i);
  4470. }
  4471. } else {
  4472. if (state.tokens.next.value === "*" && state.tokens.next.type === "(punctuator)") {
  4473. if (!state.inESNext()) {
  4474. warning("W104", state.tokens.next, "generator functions");
  4475. }
  4476. advance("*");
  4477. isGeneratorMethod = true;
  4478. } else {
  4479. isGeneratorMethod = false;
  4480. }
  4481. if (state.tokens.next.id === "[") {
  4482. i = computedPropertyName();
  4483. state.nameStack.set(i);
  4484. } else {
  4485. state.nameStack.set(state.tokens.next);
  4486. i = propertyName();
  4487. saveProperty(props, i, state.tokens.next);
  4488. if (typeof i !== "string") {
  4489. break;
  4490. }
  4491. }
  4492. if (state.tokens.next.value === "(") {
  4493. if (!state.inESNext()) {
  4494. warning("W104", state.tokens.curr, "concise methods");
  4495. }
  4496. doFunction({ type: isGeneratorMethod ? "generator" : null });
  4497. } else {
  4498. advance(":");
  4499. expression(10);
  4500. }
  4501. }
  4502. countMember(i);
  4503. if (state.tokens.next.id === ",") {
  4504. comma({ allowTrailing: true, property: true });
  4505. if (state.tokens.next.id === ",") {
  4506. warning("W070", state.tokens.curr);
  4507. } else if (state.tokens.next.id === "}" && !state.inES5(true)) {
  4508. warning("W070", state.tokens.curr);
  4509. }
  4510. } else {
  4511. break;
  4512. }
  4513. }
  4514. if (b) {
  4515. indent -= state.option.indent;
  4516. }
  4517. advance("}", this);
  4518. checkProperties(props);
  4519. return this;
  4520. };
  4521. x.fud = function() {
  4522. error("E036", state.tokens.curr);
  4523. };
  4524. }(delim("{")));
  4525. function destructuringExpression() {
  4526. var id, ids;
  4527. var identifiers = [];
  4528. if (!state.inESNext()) {
  4529. warning("W104", state.tokens.curr, "destructuring expression");
  4530. }
  4531. var nextInnerDE = function() {
  4532. var ident;
  4533. if (checkPunctuators(state.tokens.next, ["[", "{"])) {
  4534. ids = destructuringExpression();
  4535. for (var id in ids) {
  4536. id = ids[id];
  4537. identifiers.push({ id: id.id, token: id.token });
  4538. }
  4539. } else if (checkPunctuators(state.tokens.next, [","])) {
  4540. identifiers.push({ id: null, token: state.tokens.curr });
  4541. } else if (checkPunctuators(state.tokens.next, ["("])) {
  4542. advance("(");
  4543. nextInnerDE();
  4544. advance(")");
  4545. } else {
  4546. var is_rest = checkPunctuators(state.tokens.next, ["..."]);
  4547. ident = identifier();
  4548. if (ident)
  4549. identifiers.push({ id: ident, token: state.tokens.curr });
  4550. return is_rest;
  4551. }
  4552. return false;
  4553. };
  4554. if (checkPunctuators(state.tokens.next, ["["])) {
  4555. advance("[");
  4556. var element_after_rest = false;
  4557. if (nextInnerDE() && checkPunctuators(state.tokens.next, [","]) &&
  4558. !element_after_rest) {
  4559. warning("W130", state.tokens.next);
  4560. element_after_rest = true;
  4561. }
  4562. while (!checkPunctuators(state.tokens.next, ["]"])) {
  4563. advance(",");
  4564. if (checkPunctuators(state.tokens.next, ["]"])) {
  4565. // Trailing comma
  4566. break;
  4567. }
  4568. if (nextInnerDE() && checkPunctuators(state.tokens.next, [","]) &&
  4569. !element_after_rest) {
  4570. warning("W130", state.tokens.next);
  4571. element_after_rest = true;
  4572. }
  4573. }
  4574. advance("]");
  4575. } else if (checkPunctuators(state.tokens.next, ["{"])) {
  4576. advance("{");
  4577. id = identifier();
  4578. if (checkPunctuators(state.tokens.next, [":"])) {
  4579. advance(":");
  4580. nextInnerDE();
  4581. } else {
  4582. identifiers.push({ id: id, token: state.tokens.curr });
  4583. }
  4584. while (!checkPunctuators(state.tokens.next, ["}"])) {
  4585. advance(",");
  4586. if (checkPunctuators(state.tokens.next, ["}"])) {
  4587. // Trailing comma
  4588. // ObjectBindingPattern: { BindingPropertyList , }
  4589. break;
  4590. }
  4591. id = identifier();
  4592. if (checkPunctuators(state.tokens.next, [":"])) {
  4593. advance(":");
  4594. nextInnerDE();
  4595. } else {
  4596. identifiers.push({ id: id, token: state.tokens.curr });
  4597. }
  4598. }
  4599. advance("}");
  4600. }
  4601. return identifiers;
  4602. }
  4603. function destructuringExpressionMatch(tokens, value) {
  4604. var first = value.first;
  4605. if (!first)
  4606. return;
  4607. _.zip(tokens, Array.isArray(first) ? first : [ first ]).forEach(function(val) {
  4608. var token = val[0];
  4609. var value = val[1];
  4610. if (token && value)
  4611. token.first = value;
  4612. else if (token && token.first && !value)
  4613. warning("W080", token.first, token.first.value);
  4614. });
  4615. }
  4616. function blockVariableStatement(type, statement, context) {
  4617. // used for both let and const statements
  4618. var prefix = context && context.prefix;
  4619. var inexport = context && context.inexport;
  4620. var isLet = type === "let";
  4621. var isConst = type === "const";
  4622. var tokens, lone, value, letblock;
  4623. if (!state.inESNext()) {
  4624. warning("W104", state.tokens.curr, type);
  4625. }
  4626. if (isLet && state.tokens.next.value === "(") {
  4627. if (!state.inMoz()) {
  4628. warning("W118", state.tokens.next, "let block");
  4629. }
  4630. advance("(");
  4631. state.funct["(blockscope)"].stack();
  4632. letblock = true;
  4633. } else if (state.funct["(noblockscopedvar)"]) {
  4634. error("E048", state.tokens.curr, isConst ? "Const" : "Let");
  4635. }
  4636. statement.first = [];
  4637. for (;;) {
  4638. var names = [];
  4639. if (_.contains(["{", "["], state.tokens.next.value)) {
  4640. tokens = destructuringExpression();
  4641. lone = false;
  4642. } else {
  4643. tokens = [ { id: identifier(), token: state.tokens.curr } ];
  4644. lone = true;
  4645. if (inexport) {
  4646. exported[state.tokens.curr.value] = true;
  4647. state.tokens.curr.exported = true;
  4648. }
  4649. }
  4650. for (var t in tokens) {
  4651. if (tokens.hasOwnProperty(t)) {
  4652. t = tokens[t];
  4653. if (state.inESNext()) {
  4654. // only look in the latest scope because we can shadow
  4655. if (state.funct["(blockscope)"].current.labeltype(t.id) === "const") {
  4656. warning("E011", null, t.id);
  4657. }
  4658. }
  4659. if (state.funct["(global)"]) {
  4660. if (predefined[t.id] === false) {
  4661. warning("W079", t.token, t.id);
  4662. }
  4663. }
  4664. if (t.id && !state.funct["(noblockscopedvar)"]) {
  4665. addlabel(t.id, {
  4666. type: isConst ? "const" : "unused",
  4667. token: t.token,
  4668. isblockscoped: true });
  4669. names.push(t.token);
  4670. }
  4671. }
  4672. }
  4673. statement.first = statement.first.concat(names);
  4674. if (!prefix && isConst && state.tokens.next.id !== "=") {
  4675. warning("E012", state.tokens.curr, state.tokens.curr.value);
  4676. }
  4677. if (state.tokens.next.id === "=") {
  4678. advance("=");
  4679. if (!prefix && state.tokens.next.id === "undefined") {
  4680. warning("W080", state.tokens.prev, state.tokens.prev.value);
  4681. }
  4682. if (!prefix && peek(0).id === "=" && state.tokens.next.identifier) {
  4683. warning("W120", state.tokens.next, state.tokens.next.value);
  4684. }
  4685. // don't accept `in` in expression if prefix is used for ForIn/Of loop.
  4686. value = expression(prefix ? 120 : 10);
  4687. if (lone) {
  4688. tokens[0].first = value;
  4689. } else {
  4690. destructuringExpressionMatch(names, value);
  4691. }
  4692. }
  4693. if (state.tokens.next.id !== ",") {
  4694. break;
  4695. }
  4696. comma();
  4697. }
  4698. if (letblock) {
  4699. advance(")");
  4700. block(true, true);
  4701. statement.block = true;
  4702. state.funct["(blockscope)"].unstack();
  4703. }
  4704. return statement;
  4705. }
  4706. var conststatement = stmt("const", function(context) {
  4707. return blockVariableStatement("const", this, context);
  4708. });
  4709. conststatement.exps = true;
  4710. var letstatement = stmt("let", function(context) {
  4711. return blockVariableStatement("let", this, context);
  4712. });
  4713. letstatement.exps = true;
  4714. var varstatement = stmt("var", function(context) {
  4715. var prefix = context && context.prefix;
  4716. var inexport = context && context.inexport;
  4717. var tokens, lone, value;
  4718. // If the `implied` option is set, bindings are set differently.
  4719. var implied = context && context.implied;
  4720. var report = !(context && context.ignore);
  4721. this.first = [];
  4722. for (;;) {
  4723. var names = [];
  4724. if (_.contains(["{", "["], state.tokens.next.value)) {
  4725. tokens = destructuringExpression();
  4726. lone = false;
  4727. } else {
  4728. tokens = [ { id: identifier(), token: state.tokens.curr } ];
  4729. lone = true;
  4730. if (inexport) {
  4731. exported[state.tokens.curr.value] = true;
  4732. state.tokens.curr.exported = true;
  4733. }
  4734. }
  4735. for (var t in tokens) {
  4736. if (tokens.hasOwnProperty(t)) {
  4737. t = tokens[t];
  4738. if (state.inESNext()) {
  4739. // because var is function scoped, look in the whole function
  4740. if (state.funct["(blockscope)"].labeltype(t.id) === "const") {
  4741. warning("E011", null, t.id);
  4742. }
  4743. }
  4744. if (!implied && state.funct["(global)"]) {
  4745. if (predefined[t.id] === false) {
  4746. warning("W079", t.token, t.id);
  4747. } else if (state.option.futurehostile === false) {
  4748. if ((!state.inES5() && vars.ecmaIdentifiers[5][t.id] === false) ||
  4749. (!state.inESNext() && vars.ecmaIdentifiers[6][t.id] === false)) {
  4750. warning("W129", t.token, t.id);
  4751. }
  4752. }
  4753. }
  4754. if (t.id) {
  4755. if (implied === "for") {
  4756. var ident = t.token.value;
  4757. switch (state.funct[ident]) {
  4758. case "unused":
  4759. state.funct[ident] = "var";
  4760. break;
  4761. case "var":
  4762. break;
  4763. default:
  4764. if (!state.funct["(blockscope)"].getlabel(ident) &&
  4765. !(scope[ident] || {})[ident]) {
  4766. if (report) warning("W088", t.token, ident);
  4767. }
  4768. }
  4769. } else {
  4770. addlabel(t.id, { type: "unused", token: t.token });
  4771. }
  4772. names.push(t.token);
  4773. }
  4774. }
  4775. }
  4776. if (!prefix && report && state.option.varstmt) {
  4777. warning("W132", this);
  4778. }
  4779. this.first = this.first.concat(names);
  4780. if (state.tokens.next.id === "=") {
  4781. state.nameStack.set(state.tokens.curr);
  4782. advance("=");
  4783. if (!prefix && report && state.tokens.next.id === "undefined") {
  4784. warning("W080", state.tokens.prev, state.tokens.prev.value);
  4785. }
  4786. if (peek(0).id === "=" && state.tokens.next.identifier) {
  4787. if (!prefix && report &&
  4788. !state.funct["(params)"] ||
  4789. state.funct["(params)"].indexOf(state.tokens.next.value) === -1) {
  4790. warning("W120", state.tokens.next, state.tokens.next.value);
  4791. }
  4792. }
  4793. // don't accept `in` in expression if prefix is used for ForIn/Of loop.
  4794. value = expression(prefix ? 120 : 10);
  4795. if (lone) {
  4796. tokens[0].first = value;
  4797. } else {
  4798. destructuringExpressionMatch(names, value);
  4799. }
  4800. }
  4801. if (state.tokens.next.id !== ",") {
  4802. break;
  4803. }
  4804. comma();
  4805. }
  4806. return this;
  4807. });
  4808. varstatement.exps = true;
  4809. blockstmt("class", function() {
  4810. return classdef.call(this, true);
  4811. });
  4812. function classdef(isStatement) {
  4813. /*jshint validthis:true */
  4814. if (!state.inESNext()) {
  4815. warning("W104", state.tokens.curr, "class");
  4816. }
  4817. if (isStatement) {
  4818. // BindingIdentifier
  4819. this.name = identifier();
  4820. addlabel(this.name, { type: "unused", token: state.tokens.curr });
  4821. } else if (state.tokens.next.identifier && state.tokens.next.value !== "extends") {
  4822. // BindingIdentifier(opt)
  4823. this.name = identifier();
  4824. this.namedExpr = true;
  4825. } else {
  4826. this.name = state.nameStack.infer();
  4827. }
  4828. classtail(this);
  4829. return this;
  4830. }
  4831. function classtail(c) {
  4832. var wasInClassBody = state.inClassBody;
  4833. // ClassHeritage(opt)
  4834. if (state.tokens.next.value === "extends") {
  4835. advance("extends");
  4836. c.heritage = expression(10);
  4837. }
  4838. state.inClassBody = true;
  4839. advance("{");
  4840. // ClassBody(opt)
  4841. c.body = classbody(c);
  4842. advance("}");
  4843. state.inClassBody = wasInClassBody;
  4844. }
  4845. function classbody(c) {
  4846. var name;
  4847. var isStatic;
  4848. var isGenerator;
  4849. var getset;
  4850. var props = {};
  4851. var staticProps = {};
  4852. var computed;
  4853. for (var i = 0; state.tokens.next.id !== "}"; ++i) {
  4854. name = state.tokens.next;
  4855. isStatic = false;
  4856. isGenerator = false;
  4857. getset = null;
  4858. // The ES6 grammar for ClassElement includes the `;` token, but it is
  4859. // defined only as a placeholder to facilitate future language
  4860. // extensions. In ES6 code, it serves no purpose.
  4861. if (name.id === ";") {
  4862. warning("W032");
  4863. advance(";");
  4864. continue;
  4865. }
  4866. if (name.id === "*") {
  4867. isGenerator = true;
  4868. advance("*");
  4869. name = state.tokens.next;
  4870. }
  4871. if (name.id === "[") {
  4872. name = computedPropertyName();
  4873. computed = true;
  4874. } else if (isPropertyName(name)) {
  4875. // Non-Computed PropertyName
  4876. advance();
  4877. computed = false;
  4878. if (name.identifier && name.value === "static") {
  4879. if (checkPunctuators(state.tokens.next, ["*"])) {
  4880. isGenerator = true;
  4881. advance("*");
  4882. }
  4883. if (isPropertyName(state.tokens.next) || state.tokens.next.id === "[") {
  4884. computed = state.tokens.next.id === "[";
  4885. isStatic = true;
  4886. name = state.tokens.next;
  4887. if (state.tokens.next.id === "[") {
  4888. name = computedPropertyName();
  4889. } else advance();
  4890. }
  4891. }
  4892. if (name.identifier && (name.value === "get" || name.value === "set")) {
  4893. if (isPropertyName(state.tokens.next) || state.tokens.next.id === "[") {
  4894. computed = state.tokens.next.id === "[";
  4895. getset = name;
  4896. name = state.tokens.next;
  4897. if (state.tokens.next.id === "[") {
  4898. name = computedPropertyName();
  4899. } else advance();
  4900. }
  4901. }
  4902. } else {
  4903. warning("W052", state.tokens.next, state.tokens.next.value || state.tokens.next.type);
  4904. advance();
  4905. continue;
  4906. }
  4907. if (!checkPunctuators(state.tokens.next, ["("])) {
  4908. // error --- class properties must be methods
  4909. error("E054", state.tokens.next, state.tokens.next.value);
  4910. while (state.tokens.next.id !== "}" &&
  4911. !checkPunctuators(state.tokens.next, ["("])) {
  4912. advance();
  4913. }
  4914. if (state.tokens.next.value !== "(") {
  4915. doFunction({ statement: c });
  4916. }
  4917. }
  4918. if (!computed) {
  4919. // We don't know how to determine if we have duplicate computed property names :(
  4920. if (getset) {
  4921. saveAccessor(
  4922. getset.value, isStatic ? staticProps : props, name.value, name, true, isStatic);
  4923. } else {
  4924. if (name.value === "constructor") {
  4925. state.nameStack.set(c);
  4926. } else {
  4927. state.nameStack.set(name);
  4928. }
  4929. saveProperty(isStatic ? staticProps : props, name.value, name, true, isStatic);
  4930. }
  4931. }
  4932. if (getset && name.value === "constructor") {
  4933. var propDesc = getset.value === "get" ? "class getter method" : "class setter method";
  4934. error("E049", name, propDesc, "constructor");
  4935. } else if (name.value === "prototype") {
  4936. error("E049", name, "class method", "prototype");
  4937. }
  4938. propertyName(name);
  4939. doFunction({
  4940. statement: c,
  4941. type: isGenerator ? "generator" : null,
  4942. classExprBinding: c.namedExpr ? c.name : null
  4943. });
  4944. }
  4945. checkProperties(props);
  4946. }
  4947. blockstmt("function", function() {
  4948. var generator = false;
  4949. if (state.tokens.next.value === "*") {
  4950. advance("*");
  4951. if (state.inESNext({ strict: true })) {
  4952. generator = true;
  4953. } else {
  4954. warning("W119", state.tokens.curr, "function*");
  4955. }
  4956. }
  4957. if (inblock) {
  4958. warning("W082", state.tokens.curr);
  4959. }
  4960. var i = optionalidentifier();
  4961. if (i === undefined) {
  4962. warning("W025");
  4963. }
  4964. // check if a identifier with the same name is already defined
  4965. // in the blockscope as a const
  4966. if (state.funct["(blockscope)"].labeltype(i) === "const") {
  4967. warning("E011", null, i);
  4968. }
  4969. addlabel(i, { type: "unction", token: state.tokens.curr });
  4970. doFunction({
  4971. name: i,
  4972. statement: this,
  4973. type: generator ? "generator" : null
  4974. });
  4975. if (state.tokens.next.id === "(" && state.tokens.next.line === state.tokens.curr.line) {
  4976. error("E039");
  4977. }
  4978. return this;
  4979. });
  4980. prefix("function", function() {
  4981. var generator = false;
  4982. if (state.tokens.next.value === "*") {
  4983. if (!state.inESNext()) {
  4984. warning("W119", state.tokens.curr, "function*");
  4985. }
  4986. advance("*");
  4987. generator = true;
  4988. }
  4989. var i = optionalidentifier();
  4990. var fn = doFunction({ name: i, type: generator ? "generator" : null });
  4991. function isVariable(name) { return name[0] !== "("; }
  4992. function isLocal(name) { return fn[name] === "var"; }
  4993. if (!state.option.loopfunc && state.funct["(loopage)"]) {
  4994. // If the function we just parsed accesses any non-local variables
  4995. // trigger a warning. Otherwise, the function is safe even within
  4996. // a loop.
  4997. if (_.some(fn, function(val, name) { return isVariable(name) && !isLocal(name); })) {
  4998. warning("W083");
  4999. }
  5000. }
  5001. return this;
  5002. });
  5003. blockstmt("if", function() {
  5004. var t = state.tokens.next;
  5005. increaseComplexityCount();
  5006. state.condition = true;
  5007. advance("(");
  5008. var expr = expression(0);
  5009. checkCondAssignment(expr);
  5010. // When the if is within a for-in loop, check if the condition
  5011. // starts with a negation operator
  5012. var forinifcheck = null;
  5013. if (state.option.forin && state.forinifcheckneeded) {
  5014. state.forinifcheckneeded = false; // We only need to analyze the first if inside the loop
  5015. forinifcheck = state.forinifchecks[state.forinifchecks.length - 1];
  5016. if (expr.type === "(punctuator)" && expr.value === "!") {
  5017. forinifcheck.type = "(negative)";
  5018. } else {
  5019. forinifcheck.type = "(positive)";
  5020. }
  5021. }
  5022. advance(")", t);
  5023. state.condition = false;
  5024. var s = block(true, true);
  5025. // When the if is within a for-in loop and the condition has a negative form,
  5026. // check if the body contains nothing but a continue statement
  5027. if (forinifcheck && forinifcheck.type === "(negative)") {
  5028. if (s && s.length === 1 && s[0].type === "(identifier)" && s[0].value === "continue") {
  5029. forinifcheck.type = "(negative-with-continue)";
  5030. }
  5031. }
  5032. if (state.tokens.next.id === "else") {
  5033. advance("else");
  5034. if (state.tokens.next.id === "if" || state.tokens.next.id === "switch") {
  5035. statement();
  5036. } else {
  5037. block(true, true);
  5038. }
  5039. }
  5040. return this;
  5041. });
  5042. blockstmt("try", function() {
  5043. var b;
  5044. function doCatch() {
  5045. var oldScope = scope;
  5046. var e;
  5047. advance("catch");
  5048. advance("(");
  5049. scope = Object.create(oldScope);
  5050. e = state.tokens.next.value;
  5051. if (state.tokens.next.type !== "(identifier)") {
  5052. e = null;
  5053. warning("E030", state.tokens.next, e);
  5054. }
  5055. advance();
  5056. state.funct = functor("(catch)", state.tokens.next, scope, {
  5057. "(context)" : state.funct,
  5058. "(breakage)" : state.funct["(breakage)"],
  5059. "(loopage)" : state.funct["(loopage)"],
  5060. "(statement)": false,
  5061. "(catch)" : true
  5062. });
  5063. if (e) {
  5064. addlabel(e, { type: "exception" });
  5065. }
  5066. if (state.tokens.next.value === "if") {
  5067. if (!state.inMoz()) {
  5068. warning("W118", state.tokens.curr, "catch filter");
  5069. }
  5070. advance("if");
  5071. expression(0);
  5072. }
  5073. advance(")");
  5074. state.tokens.curr.funct = state.funct;
  5075. functions.push(state.funct);
  5076. block(false);
  5077. scope = oldScope;
  5078. state.funct["(last)"] = state.tokens.curr.line;
  5079. state.funct["(lastcharacter)"] = state.tokens.curr.character;
  5080. state.funct = state.funct["(context)"];
  5081. }
  5082. block(true);
  5083. while (state.tokens.next.id === "catch") {
  5084. increaseComplexityCount();
  5085. if (b && (!state.inMoz())) {
  5086. warning("W118", state.tokens.next, "multiple catch blocks");
  5087. }
  5088. doCatch();
  5089. b = true;
  5090. }
  5091. if (state.tokens.next.id === "finally") {
  5092. advance("finally");
  5093. block(true);
  5094. return;
  5095. }
  5096. if (!b) {
  5097. error("E021", state.tokens.next, "catch", state.tokens.next.value);
  5098. }
  5099. return this;
  5100. });
  5101. blockstmt("while", function() {
  5102. var t = state.tokens.next;
  5103. state.funct["(breakage)"] += 1;
  5104. state.funct["(loopage)"] += 1;
  5105. increaseComplexityCount();
  5106. advance("(");
  5107. checkCondAssignment(expression(0));
  5108. advance(")", t);
  5109. block(true, true);
  5110. state.funct["(breakage)"] -= 1;
  5111. state.funct["(loopage)"] -= 1;
  5112. return this;
  5113. }).labelled = true;
  5114. blockstmt("with", function() {
  5115. var t = state.tokens.next;
  5116. if (state.isStrict()) {
  5117. error("E010", state.tokens.curr);
  5118. } else if (!state.option.withstmt) {
  5119. warning("W085", state.tokens.curr);
  5120. }
  5121. advance("(");
  5122. expression(0);
  5123. advance(")", t);
  5124. block(true, true);
  5125. return this;
  5126. });
  5127. blockstmt("switch", function() {
  5128. var t = state.tokens.next;
  5129. var g = false;
  5130. var noindent = false;
  5131. state.funct["(breakage)"] += 1;
  5132. advance("(");
  5133. checkCondAssignment(expression(0));
  5134. advance(")", t);
  5135. t = state.tokens.next;
  5136. advance("{");
  5137. if (state.tokens.next.from === indent)
  5138. noindent = true;
  5139. if (!noindent)
  5140. indent += state.option.indent;
  5141. this.cases = [];
  5142. for (;;) {
  5143. switch (state.tokens.next.id) {
  5144. case "case":
  5145. switch (state.funct["(verb)"]) {
  5146. case "yield":
  5147. case "break":
  5148. case "case":
  5149. case "continue":
  5150. case "return":
  5151. case "switch":
  5152. case "throw":
  5153. break;
  5154. default:
  5155. // You can tell JSHint that you don't use break intentionally by
  5156. // adding a comment /* falls through */ on a line just before
  5157. // the next `case`.
  5158. if (!reg.fallsThrough.test(state.lines[state.tokens.next.line - 2])) {
  5159. warning("W086", state.tokens.curr, "case");
  5160. }
  5161. }
  5162. advance("case");
  5163. this.cases.push(expression(0));
  5164. increaseComplexityCount();
  5165. g = true;
  5166. advance(":");
  5167. state.funct["(verb)"] = "case";
  5168. break;
  5169. case "default":
  5170. switch (state.funct["(verb)"]) {
  5171. case "yield":
  5172. case "break":
  5173. case "continue":
  5174. case "return":
  5175. case "throw":
  5176. break;
  5177. default:
  5178. // Do not display a warning if 'default' is the first statement or if
  5179. // there is a special /* falls through */ comment.
  5180. if (this.cases.length) {
  5181. if (!reg.fallsThrough.test(state.lines[state.tokens.next.line - 2])) {
  5182. warning("W086", state.tokens.curr, "default");
  5183. }
  5184. }
  5185. }
  5186. advance("default");
  5187. g = true;
  5188. advance(":");
  5189. break;
  5190. case "}":
  5191. if (!noindent)
  5192. indent -= state.option.indent;
  5193. advance("}", t);
  5194. state.funct["(breakage)"] -= 1;
  5195. state.funct["(verb)"] = undefined;
  5196. return;
  5197. case "(end)":
  5198. error("E023", state.tokens.next, "}");
  5199. return;
  5200. default:
  5201. indent += state.option.indent;
  5202. if (g) {
  5203. switch (state.tokens.curr.id) {
  5204. case ",":
  5205. error("E040");
  5206. return;
  5207. case ":":
  5208. g = false;
  5209. statements();
  5210. break;
  5211. default:
  5212. error("E025", state.tokens.curr);
  5213. return;
  5214. }
  5215. } else {
  5216. if (state.tokens.curr.id === ":") {
  5217. advance(":");
  5218. error("E024", state.tokens.curr, ":");
  5219. statements();
  5220. } else {
  5221. error("E021", state.tokens.next, "case", state.tokens.next.value);
  5222. return;
  5223. }
  5224. }
  5225. indent -= state.option.indent;
  5226. }
  5227. }
  5228. }).labelled = true;
  5229. stmt("debugger", function() {
  5230. if (!state.option.debug) {
  5231. warning("W087", this);
  5232. }
  5233. return this;
  5234. }).exps = true;
  5235. (function() {
  5236. var x = stmt("do", function() {
  5237. state.funct["(breakage)"] += 1;
  5238. state.funct["(loopage)"] += 1;
  5239. increaseComplexityCount();
  5240. this.first = block(true, true);
  5241. advance("while");
  5242. var t = state.tokens.next;
  5243. advance("(");
  5244. checkCondAssignment(expression(0));
  5245. advance(")", t);
  5246. state.funct["(breakage)"] -= 1;
  5247. state.funct["(loopage)"] -= 1;
  5248. return this;
  5249. });
  5250. x.labelled = true;
  5251. x.exps = true;
  5252. }());
  5253. blockstmt("for", function() {
  5254. var s, t = state.tokens.next;
  5255. var letscope = false;
  5256. var foreachtok = null;
  5257. if (t.value === "each") {
  5258. foreachtok = t;
  5259. advance("each");
  5260. if (!state.inMoz()) {
  5261. warning("W118", state.tokens.curr, "for each");
  5262. }
  5263. }
  5264. state.funct["(breakage)"] += 1;
  5265. state.funct["(loopage)"] += 1;
  5266. increaseComplexityCount();
  5267. advance("(");
  5268. // what kind of for(…) statement it is? for(…of…)? for(…in…)? for(…;…;…)?
  5269. var nextop; // contains the token of the "in" or "of" operator
  5270. var i = 0;
  5271. var inof = ["in", "of"];
  5272. var level = 0; // BindingPattern "level" --- level 0 === no BindingPattern
  5273. var comma; // First comma punctuator at level 0
  5274. var initializer; // First initializer at level 0
  5275. // If initial token is a BindingPattern, count it as such.
  5276. if (checkPunctuators(state.tokens.next, ["{", "["])) ++level;
  5277. do {
  5278. nextop = peek(i);
  5279. ++i;
  5280. if (checkPunctuators(nextop, ["{", "["])) ++level;
  5281. else if (checkPunctuators(nextop, ["}", "]"])) --level;
  5282. if (level < 0) break;
  5283. if (level === 0) {
  5284. if (!comma && checkPunctuators(nextop, [","])) comma = nextop;
  5285. else if (!initializer && checkPunctuators(nextop, ["="])) initializer = nextop;
  5286. }
  5287. } while (level > 0 || !_.contains(inof, nextop.value) && nextop.value !== ";" &&
  5288. nextop.type !== "(end)"); // Is this a JSCS bug? This looks really weird.
  5289. // if we're in a for (… in|of …) statement
  5290. if (_.contains(inof, nextop.value)) {
  5291. if (!state.inESNext() && nextop.value === "of") {
  5292. error("W104", nextop, "for of");
  5293. }
  5294. var ok = !(initializer || comma);
  5295. if (initializer) {
  5296. error("W133", comma, nextop.value, "initializer is forbidden");
  5297. }
  5298. if (comma) {
  5299. error("W133", comma, nextop.value, "more than one ForBinding");
  5300. }
  5301. if (state.tokens.next.id === "var") {
  5302. advance("var");
  5303. state.tokens.curr.fud({ prefix: true });
  5304. } else if (state.tokens.next.id === "let" || state.tokens.next.id === "const") {
  5305. advance(state.tokens.next.id);
  5306. // create a new block scope
  5307. letscope = true;
  5308. state.funct["(blockscope)"].stack();
  5309. state.tokens.curr.fud({ prefix: true });
  5310. } else {
  5311. // Parse as a var statement, with implied bindings. Ignore errors if an error
  5312. // was already reported
  5313. Object.create(varstatement).fud({ prefix: true, implied: "for", ignore: !ok });
  5314. }
  5315. advance(nextop.value);
  5316. expression(20);
  5317. advance(")", t);
  5318. if (nextop.value === "in" && state.option.forin) {
  5319. state.forinifcheckneeded = true;
  5320. if (state.forinifchecks === undefined) {
  5321. state.forinifchecks = [];
  5322. }
  5323. // Push a new for-in-if check onto the stack. The type will be modified
  5324. // when the loop's body is parsed and a suitable if statement exists.
  5325. state.forinifchecks.push({
  5326. type: "(none)"
  5327. });
  5328. }
  5329. s = block(true, true);
  5330. if (nextop.value === "in" && state.option.forin) {
  5331. if (state.forinifchecks && state.forinifchecks.length > 0) {
  5332. var check = state.forinifchecks.pop();
  5333. if (// No if statement or not the first statement in loop body
  5334. s && s.length > 0 && (typeof s[0] !== "object" || s[0].value !== "if") ||
  5335. // Positive if statement is not the only one in loop body
  5336. check.type === "(positive)" && s.length > 1 ||
  5337. // Negative if statement but no continue
  5338. check.type === "(negative)") {
  5339. warning("W089", this);
  5340. }
  5341. }
  5342. // Reset the flag in case no if statement was contained in the loop body
  5343. state.forinifcheckneeded = false;
  5344. }
  5345. state.funct["(breakage)"] -= 1;
  5346. state.funct["(loopage)"] -= 1;
  5347. } else {
  5348. if (foreachtok) {
  5349. error("E045", foreachtok);
  5350. }
  5351. if (state.tokens.next.id !== ";") {
  5352. if (state.tokens.next.id === "var") {
  5353. advance("var");
  5354. state.tokens.curr.fud();
  5355. } else if (state.tokens.next.id === "let") {
  5356. advance("let");
  5357. // create a new block scope
  5358. letscope = true;
  5359. state.funct["(blockscope)"].stack();
  5360. state.tokens.curr.fud();
  5361. } else {
  5362. for (;;) {
  5363. expression(0, "for");
  5364. if (state.tokens.next.id !== ",") {
  5365. break;
  5366. }
  5367. comma();
  5368. }
  5369. }
  5370. }
  5371. nolinebreak(state.tokens.curr);
  5372. advance(";");
  5373. if (state.tokens.next.id !== ";") {
  5374. checkCondAssignment(expression(0));
  5375. }
  5376. nolinebreak(state.tokens.curr);
  5377. advance(";");
  5378. if (state.tokens.next.id === ";") {
  5379. error("E021", state.tokens.next, ")", ";");
  5380. }
  5381. if (state.tokens.next.id !== ")") {
  5382. for (;;) {
  5383. expression(0, "for");
  5384. if (state.tokens.next.id !== ",") {
  5385. break;
  5386. }
  5387. comma();
  5388. }
  5389. }
  5390. advance(")", t);
  5391. block(true, true);
  5392. state.funct["(breakage)"] -= 1;
  5393. state.funct["(loopage)"] -= 1;
  5394. }
  5395. // unstack loop blockscope
  5396. if (letscope) {
  5397. state.funct["(blockscope)"].unstack();
  5398. }
  5399. return this;
  5400. }).labelled = true;
  5401. stmt("break", function() {
  5402. var v = state.tokens.next.value;
  5403. if (state.funct["(breakage)"] === 0)
  5404. warning("W052", state.tokens.next, this.value);
  5405. if (!state.option.asi)
  5406. nolinebreak(this);
  5407. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  5408. if (state.tokens.curr.line === startLine(state.tokens.next)) {
  5409. if (state.funct[v] !== "label") {
  5410. warning("W090", state.tokens.next, v);
  5411. } else if (scope[v] !== state.funct) {
  5412. warning("W091", state.tokens.next, v);
  5413. }
  5414. this.first = state.tokens.next;
  5415. advance();
  5416. }
  5417. }
  5418. reachable(this);
  5419. return this;
  5420. }).exps = true;
  5421. stmt("continue", function() {
  5422. var v = state.tokens.next.value;
  5423. if (state.funct["(breakage)"] === 0)
  5424. warning("W052", state.tokens.next, this.value);
  5425. if (!state.option.asi)
  5426. nolinebreak(this);
  5427. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  5428. if (state.tokens.curr.line === startLine(state.tokens.next)) {
  5429. if (state.funct[v] !== "label") {
  5430. warning("W090", state.tokens.next, v);
  5431. } else if (scope[v] !== state.funct) {
  5432. warning("W091", state.tokens.next, v);
  5433. }
  5434. this.first = state.tokens.next;
  5435. advance();
  5436. }
  5437. } else if (!state.funct["(loopage)"]) {
  5438. warning("W052", state.tokens.next, this.value);
  5439. }
  5440. reachable(this);
  5441. return this;
  5442. }).exps = true;
  5443. stmt("return", function() {
  5444. if (this.line === startLine(state.tokens.next)) {
  5445. if (state.tokens.next.id !== ";" && !state.tokens.next.reach) {
  5446. this.first = expression(0);
  5447. if (this.first &&
  5448. this.first.type === "(punctuator)" && this.first.value === "=" &&
  5449. !this.first.paren && !state.option.boss) {
  5450. warningAt("W093", this.first.line, this.first.character);
  5451. }
  5452. }
  5453. } else {
  5454. if (state.tokens.next.type === "(punctuator)" &&
  5455. ["[", "{", "+", "-"].indexOf(state.tokens.next.value) > -1) {
  5456. nolinebreak(this); // always warn (Line breaking error)
  5457. }
  5458. }
  5459. reachable(this);
  5460. return this;
  5461. }).exps = true;
  5462. (function(x) {
  5463. x.exps = true;
  5464. x.lbp = 25;
  5465. }(prefix("yield", function() {
  5466. var prev = state.tokens.prev;
  5467. if (state.inESNext(true) && !state.funct["(generator)"]) {
  5468. // If it's a yield within a catch clause inside a generator then that's ok
  5469. if (!("(catch)" === state.funct["(name)"] && state.funct["(context)"]["(generator)"])) {
  5470. error("E046", state.tokens.curr, "yield");
  5471. }
  5472. } else if (!state.inESNext()) {
  5473. warning("W104", state.tokens.curr, "yield");
  5474. }
  5475. state.funct["(generator)"] = "yielded";
  5476. var delegatingYield = false;
  5477. if (state.tokens.next.value === "*") {
  5478. delegatingYield = true;
  5479. advance("*");
  5480. }
  5481. if (this.line === startLine(state.tokens.next) || !state.inMoz()) {
  5482. if (delegatingYield ||
  5483. (state.tokens.next.id !== ";" && !state.tokens.next.reach && state.tokens.next.nud)) {
  5484. nobreaknonadjacent(state.tokens.curr, state.tokens.next);
  5485. this.first = expression(10);
  5486. if (this.first.type === "(punctuator)" && this.first.value === "=" &&
  5487. !this.first.paren && !state.option.boss) {
  5488. warningAt("W093", this.first.line, this.first.character);
  5489. }
  5490. }
  5491. if (state.inMoz() && state.tokens.next.id !== ")" &&
  5492. (prev.lbp > 30 || (!prev.assign && !isEndOfExpr()) || prev.id === "yield")) {
  5493. error("E050", this);
  5494. }
  5495. } else if (!state.option.asi) {
  5496. nolinebreak(this); // always warn (Line breaking error)
  5497. }
  5498. return this;
  5499. })));
  5500. stmt("throw", function() {
  5501. nolinebreak(this);
  5502. this.first = expression(20);
  5503. reachable(this);
  5504. return this;
  5505. }).exps = true;
  5506. stmt("import", function() {
  5507. if (!state.inESNext()) {
  5508. warning("W119", state.tokens.curr, "import");
  5509. }
  5510. if (state.tokens.next.type === "(string)") {
  5511. // ModuleSpecifier :: StringLiteral
  5512. advance("(string)");
  5513. return this;
  5514. }
  5515. if (state.tokens.next.identifier) {
  5516. // ImportClause :: ImportedDefaultBinding
  5517. this.name = identifier();
  5518. addlabel(this.name, { type: "unused", token: state.tokens.curr });
  5519. if (state.tokens.next.value === ",") {
  5520. // ImportClause :: ImportedDefaultBinding , NameSpaceImport
  5521. // ImportClause :: ImportedDefaultBinding , NamedImports
  5522. advance(",");
  5523. // At this point, we intentionally fall through to continue matching
  5524. // either NameSpaceImport or NamedImports.
  5525. // Discussion:
  5526. // https://github.com/jshint/jshint/pull/2144#discussion_r23978406
  5527. } else {
  5528. advance("from");
  5529. advance("(string)");
  5530. return this;
  5531. }
  5532. }
  5533. if (state.tokens.next.id === "*") {
  5534. // ImportClause :: NameSpaceImport
  5535. advance("*");
  5536. advance("as");
  5537. if (state.tokens.next.identifier) {
  5538. this.name = identifier();
  5539. addlabel(this.name, { type: "unused", token: state.tokens.curr });
  5540. }
  5541. } else {
  5542. // ImportClause :: NamedImports
  5543. advance("{");
  5544. for (;;) {
  5545. if (state.tokens.next.value === "}") {
  5546. advance("}");
  5547. break;
  5548. }
  5549. var importName;
  5550. if (state.tokens.next.type === "default") {
  5551. importName = "default";
  5552. advance("default");
  5553. } else {
  5554. importName = identifier();
  5555. }
  5556. if (state.tokens.next.value === "as") {
  5557. advance("as");
  5558. importName = identifier();
  5559. }
  5560. addlabel(importName, { type: "unused", token: state.tokens.curr });
  5561. if (state.tokens.next.value === ",") {
  5562. advance(",");
  5563. } else if (state.tokens.next.value === "}") {
  5564. advance("}");
  5565. break;
  5566. } else {
  5567. error("E024", state.tokens.next, state.tokens.next.value);
  5568. break;
  5569. }
  5570. }
  5571. }
  5572. // FromClause
  5573. advance("from");
  5574. advance("(string)");
  5575. return this;
  5576. }).exps = true;
  5577. stmt("export", function() {
  5578. var ok = true;
  5579. var token;
  5580. var identifier;
  5581. if (!state.inESNext()) {
  5582. warning("W119", state.tokens.curr, "export");
  5583. ok = false;
  5584. }
  5585. if (!state.funct["(global)"] || !state.funct["(blockscope)"].atTop()) {
  5586. error("E053", state.tokens.curr);
  5587. ok = false;
  5588. }
  5589. if (state.tokens.next.value === "*") {
  5590. // ExportDeclaration :: export * FromClause
  5591. advance("*");
  5592. advance("from");
  5593. advance("(string)");
  5594. return this;
  5595. }
  5596. if (state.tokens.next.type === "default") {
  5597. // ExportDeclaration :: export default HoistableDeclaration
  5598. // ExportDeclaration :: export default ClassDeclaration
  5599. state.nameStack.set(state.tokens.next);
  5600. advance("default");
  5601. if (state.tokens.next.id === "function" || state.tokens.next.id === "class") {
  5602. this.block = true;
  5603. }
  5604. token = peek();
  5605. expression(10);
  5606. if (state.tokens.next.id === "class") {
  5607. identifier = token.name;
  5608. } else {
  5609. identifier = token.value;
  5610. }
  5611. addlabel(identifier, {
  5612. type: "function", token: token
  5613. });
  5614. return this;
  5615. }
  5616. if (state.tokens.next.value === "{") {
  5617. // ExportDeclaration :: export ExportClause
  5618. advance("{");
  5619. var exportedTokens = [];
  5620. for (;;) {
  5621. if (!state.tokens.next.identifier) {
  5622. error("E030", state.tokens.next, state.tokens.next.value);
  5623. }
  5624. advance();
  5625. state.tokens.curr.exported = ok;
  5626. exportedTokens.push(state.tokens.curr);
  5627. if (state.tokens.next.value === "as") {
  5628. advance("as");
  5629. if (!state.tokens.next.identifier) {
  5630. error("E030", state.tokens.next, state.tokens.next.value);
  5631. }
  5632. advance();
  5633. }
  5634. if (state.tokens.next.value === ",") {
  5635. advance(",");
  5636. } else if (state.tokens.next.value === "}") {
  5637. advance("}");
  5638. break;
  5639. } else {
  5640. error("E024", state.tokens.next, state.tokens.next.value);
  5641. break;
  5642. }
  5643. }
  5644. if (state.tokens.next.value === "from") {
  5645. // ExportDeclaration :: export ExportClause FromClause
  5646. advance("from");
  5647. advance("(string)");
  5648. } else if (ok) {
  5649. exportedTokens.forEach(function(token) {
  5650. if (!state.funct[token.value]) {
  5651. isundef(state.funct, "W117", token, token.value);
  5652. }
  5653. exported[token.value] = true;
  5654. state.funct["(blockscope)"].setExported(token.value);
  5655. });
  5656. }
  5657. return this;
  5658. }
  5659. if (state.tokens.next.id === "var") {
  5660. // ExportDeclaration :: export VariableStatement
  5661. advance("var");
  5662. state.tokens.curr.fud({ inexport:true });
  5663. } else if (state.tokens.next.id === "let") {
  5664. // ExportDeclaration :: export VariableStatement
  5665. advance("let");
  5666. state.tokens.curr.fud({ inexport:true });
  5667. } else if (state.tokens.next.id === "const") {
  5668. // ExportDeclaration :: export VariableStatement
  5669. advance("const");
  5670. state.tokens.curr.fud({ inexport:true });
  5671. } else if (state.tokens.next.id === "function") {
  5672. // ExportDeclaration :: export Declaration
  5673. this.block = true;
  5674. advance("function");
  5675. exported[state.tokens.next.value] = ok;
  5676. state.tokens.next.exported = true;
  5677. state.syntax["function"].fud();
  5678. } else if (state.tokens.next.id === "class") {
  5679. // ExportDeclaration :: export Declaration
  5680. this.block = true;
  5681. advance("class");
  5682. exported[state.tokens.next.value] = ok;
  5683. state.tokens.next.exported = true;
  5684. state.syntax["class"].fud();
  5685. } else {
  5686. error("E024", state.tokens.next, state.tokens.next.value);
  5687. }
  5688. return this;
  5689. }).exps = true;
  5690. // Future Reserved Words
  5691. FutureReservedWord("abstract");
  5692. FutureReservedWord("boolean");
  5693. FutureReservedWord("byte");
  5694. FutureReservedWord("char");
  5695. FutureReservedWord("class", { es5: true, nud: classdef });
  5696. FutureReservedWord("double");
  5697. FutureReservedWord("enum", { es5: true });
  5698. FutureReservedWord("export", { es5: true });
  5699. FutureReservedWord("extends", { es5: true });
  5700. FutureReservedWord("final");
  5701. FutureReservedWord("float");
  5702. FutureReservedWord("goto");
  5703. FutureReservedWord("implements", { es5: true, strictOnly: true });
  5704. FutureReservedWord("import", { es5: true });
  5705. FutureReservedWord("int");
  5706. FutureReservedWord("interface", { es5: true, strictOnly: true });
  5707. FutureReservedWord("long");
  5708. FutureReservedWord("native");
  5709. FutureReservedWord("package", { es5: true, strictOnly: true });
  5710. FutureReservedWord("private", { es5: true, strictOnly: true });
  5711. FutureReservedWord("protected", { es5: true, strictOnly: true });
  5712. FutureReservedWord("public", { es5: true, strictOnly: true });
  5713. FutureReservedWord("short");
  5714. FutureReservedWord("static", { es5: true, strictOnly: true });
  5715. FutureReservedWord("super", { es5: true });
  5716. FutureReservedWord("synchronized");
  5717. FutureReservedWord("transient");
  5718. FutureReservedWord("volatile");
  5719. // this function is used to determine whether a squarebracket or a curlybracket
  5720. // expression is a comprehension array, destructuring assignment or a json value.
  5721. var lookupBlockType = function() {
  5722. var pn, pn1;
  5723. var i = -1;
  5724. var bracketStack = 0;
  5725. var ret = {};
  5726. if (checkPunctuators(state.tokens.curr, ["[", "{"]))
  5727. bracketStack += 1;
  5728. do {
  5729. pn = (i === -1) ? state.tokens.next : peek(i);
  5730. pn1 = peek(i + 1);
  5731. i = i + 1;
  5732. if (checkPunctuators(pn, ["[", "{"])) {
  5733. bracketStack += 1;
  5734. } else if (checkPunctuators(pn, ["]", "}"])) {
  5735. bracketStack -= 1;
  5736. }
  5737. if (pn.identifier && pn.value === "for" && bracketStack === 1) {
  5738. ret.isCompArray = true;
  5739. ret.notJson = true;
  5740. break;
  5741. }
  5742. if (checkPunctuators(pn, ["}", "]"]) && bracketStack === 0) {
  5743. if (pn1.value === "=") {
  5744. ret.isDestAssign = true;
  5745. ret.notJson = true;
  5746. break;
  5747. } else if (pn1.value === ".") {
  5748. ret.notJson = true;
  5749. break;
  5750. }
  5751. }
  5752. if (pn.value === ";") {
  5753. ret.isBlock = true;
  5754. ret.notJson = true;
  5755. }
  5756. } while (bracketStack > 0 && pn.id !== "(end)");
  5757. return ret;
  5758. };
  5759. function saveProperty(props, name, tkn, isClass, isStatic) {
  5760. var msg = ["key", "class method", "static class method"];
  5761. msg = msg[(isClass || false) + (isStatic || false)];
  5762. if (tkn.identifier) {
  5763. name = tkn.value;
  5764. }
  5765. if (props[name] && _.has(props, name)) {
  5766. warning("W075", state.tokens.next, msg, name);
  5767. } else {
  5768. props[name] = {};
  5769. }
  5770. props[name].basic = true;
  5771. props[name].basictkn = tkn;
  5772. }
  5773. /**
  5774. * @param {string} accessorType - Either "get" or "set"
  5775. * @param {object} props - a collection of all properties of the object to
  5776. * which the current accessor is being assigned
  5777. * @param {object} tkn - the identifier token representing the accessor name
  5778. * @param {boolean} isClass - whether the accessor is part of an ES6 Class
  5779. * definition
  5780. * @param {boolean} isStatic - whether the accessor is a static method
  5781. */
  5782. function saveAccessor(accessorType, props, name, tkn, isClass, isStatic) {
  5783. var flagName = accessorType === "get" ? "getterToken" : "setterToken";
  5784. var msg = "";
  5785. if (isClass) {
  5786. if (isStatic) {
  5787. msg += "static ";
  5788. }
  5789. msg += accessorType + "ter method";
  5790. } else {
  5791. msg = "key";
  5792. }
  5793. state.tokens.curr.accessorType = accessorType;
  5794. state.nameStack.set(tkn);
  5795. if (props[name] && _.has(props, name)) {
  5796. if (props[name].basic || props[name][flagName]) {
  5797. warning("W075", state.tokens.next, msg, name);
  5798. }
  5799. } else {
  5800. props[name] = {};
  5801. }
  5802. props[name][flagName] = tkn;
  5803. }
  5804. function computedPropertyName() {
  5805. advance("[");
  5806. if (!state.option.esnext) {
  5807. warning("W119", state.tokens.curr, "computed property names");
  5808. }
  5809. var value = expression(10);
  5810. advance("]");
  5811. return value;
  5812. }
  5813. // Test whether a given token is a punctuator matching one of the specified values
  5814. function checkPunctuators(token, values) {
  5815. return token.type === "(punctuator)" && _.contains(values, token.value);
  5816. }
  5817. // Check whether this function has been reached for a destructuring assign with undeclared values
  5818. function destructuringAssignOrJsonValue() {
  5819. // lookup for the assignment (esnext only)
  5820. // if it has semicolons, it is a block, so go parse it as a block
  5821. // or it's not a block, but there are assignments, check for undeclared variables
  5822. var block = lookupBlockType();
  5823. if (block.notJson) {
  5824. if (!state.inESNext() && block.isDestAssign) {
  5825. warning("W104", state.tokens.curr, "destructuring assignment");
  5826. }
  5827. statements();
  5828. // otherwise parse json value
  5829. } else {
  5830. state.option.laxbreak = true;
  5831. state.jsonMode = true;
  5832. jsonValue();
  5833. }
  5834. }
  5835. // array comprehension parsing function
  5836. // parses and defines the three states of the list comprehension in order
  5837. // to avoid defining global variables, but keeping them to the list comprehension scope
  5838. // only. The order of the states are as follows:
  5839. // * "use" which will be the returned iterative part of the list comprehension
  5840. // * "define" which will define the variables local to the list comprehension
  5841. // * "filter" which will help filter out values
  5842. var arrayComprehension = function() {
  5843. var CompArray = function() {
  5844. this.mode = "use";
  5845. this.variables = [];
  5846. };
  5847. var _carrays = [];
  5848. var _current;
  5849. function declare(v) {
  5850. var l = _current.variables.filter(function(elt) {
  5851. // if it has, change its undef state
  5852. if (elt.value === v) {
  5853. elt.undef = false;
  5854. return v;
  5855. }
  5856. }).length;
  5857. return l !== 0;
  5858. }
  5859. function use(v) {
  5860. var l = _current.variables.filter(function(elt) {
  5861. // and if it has been defined
  5862. if (elt.value === v && !elt.undef) {
  5863. if (elt.unused === true) {
  5864. elt.unused = false;
  5865. }
  5866. return v;
  5867. }
  5868. }).length;
  5869. // otherwise we warn about it
  5870. return (l === 0);
  5871. }
  5872. return { stack: function() {
  5873. _current = new CompArray();
  5874. _carrays.push(_current);
  5875. },
  5876. unstack: function() {
  5877. _current.variables.filter(function(v) {
  5878. if (v.unused)
  5879. warning("W098", v.token, v.raw_text || v.value);
  5880. if (v.undef)
  5881. isundef(v.state.funct, "W117", v.token, v.value);
  5882. });
  5883. _carrays.splice(-1, 1);
  5884. _current = _carrays[_carrays.length - 1];
  5885. },
  5886. setState: function(s) {
  5887. if (_.contains(["use", "define", "generate", "filter"], s))
  5888. _current.mode = s;
  5889. },
  5890. check: function(v) {
  5891. if (!_current) {
  5892. return;
  5893. }
  5894. // When we are in "use" state of the list comp, we enqueue that var
  5895. if (_current && _current.mode === "use") {
  5896. if (use(v)) {
  5897. _current.variables.push({
  5898. funct: state.funct,
  5899. token: state.tokens.curr,
  5900. value: v,
  5901. undef: true,
  5902. unused: false
  5903. });
  5904. }
  5905. return true;
  5906. // When we are in "define" state of the list comp,
  5907. } else if (_current && _current.mode === "define") {
  5908. // check if the variable has been used previously
  5909. if (!declare(v)) {
  5910. _current.variables.push({
  5911. funct: state.funct,
  5912. token: state.tokens.curr,
  5913. value: v,
  5914. undef: false,
  5915. unused: true
  5916. });
  5917. }
  5918. return true;
  5919. // When we are in the "generate" state of the list comp,
  5920. } else if (_current && _current.mode === "generate") {
  5921. isundef(state.funct, "W117", state.tokens.curr, v);
  5922. return true;
  5923. // When we are in "filter" state,
  5924. } else if (_current && _current.mode === "filter") {
  5925. // we check whether current variable has been declared
  5926. if (use(v)) {
  5927. // if not we warn about it
  5928. isundef(state.funct, "W117", state.tokens.curr, v);
  5929. }
  5930. return true;
  5931. }
  5932. return false;
  5933. }
  5934. };
  5935. };
  5936. // Parse JSON
  5937. function jsonValue() {
  5938. function jsonObject() {
  5939. var o = {}, t = state.tokens.next;
  5940. advance("{");
  5941. if (state.tokens.next.id !== "}") {
  5942. for (;;) {
  5943. if (state.tokens.next.id === "(end)") {
  5944. error("E026", state.tokens.next, t.line);
  5945. } else if (state.tokens.next.id === "}") {
  5946. warning("W094", state.tokens.curr);
  5947. break;
  5948. } else if (state.tokens.next.id === ",") {
  5949. error("E028", state.tokens.next);
  5950. } else if (state.tokens.next.id !== "(string)") {
  5951. warning("W095", state.tokens.next, state.tokens.next.value);
  5952. }
  5953. if (o[state.tokens.next.value] === true) {
  5954. warning("W075", state.tokens.next, "key", state.tokens.next.value);
  5955. } else if ((state.tokens.next.value === "__proto__" &&
  5956. !state.option.proto) || (state.tokens.next.value === "__iterator__" &&
  5957. !state.option.iterator)) {
  5958. warning("W096", state.tokens.next, state.tokens.next.value);
  5959. } else {
  5960. o[state.tokens.next.value] = true;
  5961. }
  5962. advance();
  5963. advance(":");
  5964. jsonValue();
  5965. if (state.tokens.next.id !== ",") {
  5966. break;
  5967. }
  5968. advance(",");
  5969. }
  5970. }
  5971. advance("}");
  5972. }
  5973. function jsonArray() {
  5974. var t = state.tokens.next;
  5975. advance("[");
  5976. if (state.tokens.next.id !== "]") {
  5977. for (;;) {
  5978. if (state.tokens.next.id === "(end)") {
  5979. error("E027", state.tokens.next, t.line);
  5980. } else if (state.tokens.next.id === "]") {
  5981. warning("W094", state.tokens.curr);
  5982. break;
  5983. } else if (state.tokens.next.id === ",") {
  5984. error("E028", state.tokens.next);
  5985. }
  5986. jsonValue();
  5987. if (state.tokens.next.id !== ",") {
  5988. break;
  5989. }
  5990. advance(",");
  5991. }
  5992. }
  5993. advance("]");
  5994. }
  5995. switch (state.tokens.next.id) {
  5996. case "{":
  5997. jsonObject();
  5998. break;
  5999. case "[":
  6000. jsonArray();
  6001. break;
  6002. case "true":
  6003. case "false":
  6004. case "null":
  6005. case "(number)":
  6006. case "(string)":
  6007. advance();
  6008. break;
  6009. case "-":
  6010. advance("-");
  6011. advance("(number)");
  6012. break;
  6013. default:
  6014. error("E003", state.tokens.next);
  6015. }
  6016. }
  6017. var warnUnused = function(name, tkn, type, unused_opt) {
  6018. var line = tkn.line;
  6019. var chr = tkn.from;
  6020. var raw_name = tkn.raw_text || name;
  6021. if (unused_opt === undefined) {
  6022. unused_opt = state.option.unused;
  6023. }
  6024. if (unused_opt === true) {
  6025. unused_opt = "last-param";
  6026. }
  6027. var warnable_types = {
  6028. "vars": ["var"],
  6029. "last-param": ["var", "param"],
  6030. "strict": ["var", "param", "last-param"]
  6031. };
  6032. if (unused_opt) {
  6033. if (warnable_types[unused_opt] && warnable_types[unused_opt].indexOf(type) !== -1) {
  6034. if (!tkn.exported) {
  6035. warningAt("W098", line, chr, raw_name);
  6036. }
  6037. }
  6038. }
  6039. unuseds.push({
  6040. name: name,
  6041. line: line,
  6042. character: chr
  6043. });
  6044. };
  6045. var blockScope = function() {
  6046. var _current = {};
  6047. var _variables = [_current];
  6048. function _checkBlockLabels() {
  6049. for (var t in _current) {
  6050. var label = _current[t],
  6051. labelType = label["(type)"];
  6052. if (labelType === "unused" || (labelType === "const" && label["(unused)"])) {
  6053. if (state.option.unused) {
  6054. var tkn = _current[t]["(token)"];
  6055. // Don't report exported labels as unused
  6056. if (tkn.exported) {
  6057. continue;
  6058. }
  6059. warnUnused(t, tkn, "var");
  6060. }
  6061. }
  6062. }
  6063. }
  6064. function _getLabel(l) {
  6065. for (var i = _variables.length - 1 ; i >= 0; --i) {
  6066. if (_.has(_variables[i], l) && !_variables[i][l]["(shadowed)"]) {
  6067. return _variables[i];
  6068. }
  6069. }
  6070. }
  6071. return {
  6072. stack: function() {
  6073. _current = {};
  6074. _variables.push(_current);
  6075. },
  6076. unstack: function() {
  6077. _checkBlockLabels();
  6078. _variables.splice(_variables.length - 1, 1);
  6079. _current = _.last(_variables);
  6080. },
  6081. getlabel: _getLabel,
  6082. labeltype: function(l) {
  6083. // returns a labels type or null if not present
  6084. var block = _getLabel(l);
  6085. if (block) {
  6086. return block[l]["(type)"];
  6087. }
  6088. return null;
  6089. },
  6090. shadow: function(name) {
  6091. for (var i = _variables.length - 1; i >= 0; i--) {
  6092. if (_.has(_variables[i], name)) {
  6093. _variables[i][name]["(shadowed)"] = true;
  6094. }
  6095. }
  6096. },
  6097. unshadow: function(name) {
  6098. for (var i = _variables.length - 1; i >= 0; i--) {
  6099. if (_.has(_variables[i], name)) {
  6100. _variables[i][name]["(shadowed)"] = false;
  6101. }
  6102. }
  6103. },
  6104. atTop: function() {
  6105. return _variables.length === 1;
  6106. },
  6107. setExported: function(id) {
  6108. if (state.funct["(blockscope)"].atTop()) {
  6109. var item = _current[id];
  6110. if (item && item["(token)"]) {
  6111. item["(token)"].exported = true;
  6112. }
  6113. }
  6114. },
  6115. current: {
  6116. labeltype: function(t) {
  6117. if (_current[t]) {
  6118. return _current[t]["(type)"];
  6119. }
  6120. return null;
  6121. },
  6122. has: function(t) {
  6123. return _.has(_current, t);
  6124. },
  6125. add: function(t, type, tok) {
  6126. _current[t] = { "(type)" : type, "(token)": tok, "(shadowed)": false, "(unused)": true };
  6127. }
  6128. }
  6129. };
  6130. };
  6131. var escapeRegex = function(str) {
  6132. return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
  6133. };
  6134. // The actual JSHINT function itself.
  6135. var itself = function(s, o, g) {
  6136. var i, k, x, reIgnoreStr, reIgnore;
  6137. var optionKeys;
  6138. var newOptionObj = {};
  6139. var newIgnoredObj = {};
  6140. o = _.clone(o);
  6141. state.reset();
  6142. if (o && o.scope) {
  6143. JSHINT.scope = o.scope;
  6144. } else {
  6145. JSHINT.errors = [];
  6146. JSHINT.undefs = [];
  6147. JSHINT.internals = [];
  6148. JSHINT.blacklist = {};
  6149. JSHINT.scope = "(main)";
  6150. }
  6151. predefined = Object.create(null);
  6152. combine(predefined, vars.ecmaIdentifiers[3]);
  6153. combine(predefined, vars.reservedVars);
  6154. combine(predefined, g || {});
  6155. declared = Object.create(null);
  6156. exported = Object.create(null);
  6157. function each(obj, cb) {
  6158. if (!obj)
  6159. return;
  6160. if (!Array.isArray(obj) && typeof obj === "object")
  6161. obj = Object.keys(obj);
  6162. obj.forEach(cb);
  6163. }
  6164. if (o) {
  6165. each(o.predef || null, function(item) {
  6166. var slice, prop;
  6167. if (item[0] === "-") {
  6168. slice = item.slice(1);
  6169. JSHINT.blacklist[slice] = slice;
  6170. // remove from predefined if there
  6171. delete predefined[slice];
  6172. } else {
  6173. prop = Object.getOwnPropertyDescriptor(o.predef, item);
  6174. predefined[item] = prop ? prop.value : false;
  6175. }
  6176. });
  6177. each(o.exported || null, function(item) {
  6178. exported[item] = true;
  6179. });
  6180. delete o.predef;
  6181. delete o.exported;
  6182. optionKeys = Object.keys(o);
  6183. for (x = 0; x < optionKeys.length; x++) {
  6184. if (/^-W\d{3}$/g.test(optionKeys[x])) {
  6185. newIgnoredObj[optionKeys[x].slice(1)] = true;
  6186. } else {
  6187. var optionKey = optionKeys[x];
  6188. newOptionObj[optionKey] = o[optionKey];
  6189. if (optionKey === "es5") {
  6190. if (o[optionKey]) {
  6191. warning("I003");
  6192. }
  6193. }
  6194. if (optionKeys[x] === "newcap" && o[optionKey] === false)
  6195. newOptionObj["(explicitNewcap)"] = true;
  6196. }
  6197. }
  6198. }
  6199. state.option = newOptionObj;
  6200. state.ignored = newIgnoredObj;
  6201. state.option.indent = state.option.indent || 4;
  6202. state.option.maxerr = state.option.maxerr || 50;
  6203. indent = 1;
  6204. global = Object.create(predefined);
  6205. scope = global;
  6206. state.funct = functor("(global)", null, scope, {
  6207. "(global)" : true,
  6208. "(blockscope)": blockScope(),
  6209. "(comparray)" : arrayComprehension(),
  6210. "(metrics)" : createMetrics(state.tokens.next)
  6211. });
  6212. functions = [state.funct];
  6213. urls = [];
  6214. stack = null;
  6215. member = {};
  6216. membersOnly = null;
  6217. implied = {};
  6218. inblock = false;
  6219. lookahead = [];
  6220. unuseds = [];
  6221. if (!isString(s) && !Array.isArray(s)) {
  6222. errorAt("E004", 0);
  6223. return false;
  6224. }
  6225. api = {
  6226. get isJSON() {
  6227. return state.jsonMode;
  6228. },
  6229. getOption: function(name) {
  6230. return state.option[name] || null;
  6231. },
  6232. getCache: function(name) {
  6233. return state.cache[name];
  6234. },
  6235. setCache: function(name, value) {
  6236. state.cache[name] = value;
  6237. },
  6238. warn: function(code, data) {
  6239. warningAt.apply(null, [ code, data.line, data.char ].concat(data.data));
  6240. },
  6241. on: function(names, listener) {
  6242. names.split(" ").forEach(function(name) {
  6243. emitter.on(name, listener);
  6244. }.bind(this));
  6245. }
  6246. };
  6247. emitter.removeAllListeners();
  6248. (extraModules || []).forEach(function(func) {
  6249. func(api);
  6250. });
  6251. state.tokens.prev = state.tokens.curr = state.tokens.next = state.syntax["(begin)"];
  6252. if (o && o.ignoreDelimiters) {
  6253. if (!Array.isArray(o.ignoreDelimiters)) {
  6254. o.ignoreDelimiters = [o.ignoreDelimiters];
  6255. }
  6256. o.ignoreDelimiters.forEach(function(delimiterPair) {
  6257. if (!delimiterPair.start || !delimiterPair.end)
  6258. return;
  6259. reIgnoreStr = escapeRegex(delimiterPair.start) +
  6260. "[\\s\\S]*?" +
  6261. escapeRegex(delimiterPair.end);
  6262. reIgnore = new RegExp(reIgnoreStr, "ig");
  6263. s = s.replace(reIgnore, function(match) {
  6264. return match.replace(/./g, " ");
  6265. });
  6266. });
  6267. }
  6268. lex = new Lexer(s);
  6269. lex.on("warning", function(ev) {
  6270. warningAt.apply(null, [ ev.code, ev.line, ev.character].concat(ev.data));
  6271. });
  6272. lex.on("error", function(ev) {
  6273. errorAt.apply(null, [ ev.code, ev.line, ev.character ].concat(ev.data));
  6274. });
  6275. lex.on("fatal", function(ev) {
  6276. quit("E041", ev.line, ev.from);
  6277. });
  6278. lex.on("Identifier", function(ev) {
  6279. emitter.emit("Identifier", ev);
  6280. });
  6281. lex.on("String", function(ev) {
  6282. emitter.emit("String", ev);
  6283. });
  6284. lex.on("Number", function(ev) {
  6285. emitter.emit("Number", ev);
  6286. });
  6287. lex.start();
  6288. // Check options
  6289. for (var name in o) {
  6290. if (_.has(o, name)) {
  6291. checkOption(name, state.tokens.curr);
  6292. }
  6293. }
  6294. assume();
  6295. // combine the passed globals after we've assumed all our options
  6296. combine(predefined, g || {});
  6297. //reset values
  6298. comma.first = true;
  6299. try {
  6300. advance();
  6301. switch (state.tokens.next.id) {
  6302. case "{":
  6303. case "[":
  6304. destructuringAssignOrJsonValue();
  6305. break;
  6306. default:
  6307. directives();
  6308. if (state.isStrict()) {
  6309. if (!state.option.globalstrict) {
  6310. if (!(state.option.module || state.option.node || state.option.phantom ||
  6311. state.option.browserify)) {
  6312. warning("W097", state.tokens.prev);
  6313. }
  6314. }
  6315. }
  6316. statements();
  6317. }
  6318. if (state.tokens.next.id !== "(end)") {
  6319. quit("E041", state.tokens.curr.line);
  6320. }
  6321. state.funct["(blockscope)"].unstack();
  6322. var markDefined = function(name, context) {
  6323. do {
  6324. if (typeof context[name] === "string") {
  6325. // JSHINT marks unused variables as 'unused' and
  6326. // unused function declaration as 'unction'. This
  6327. // code changes such instances back 'var' and
  6328. // 'closure' so that the code in JSHINT.data()
  6329. // doesn't think they're unused.
  6330. if (context[name] === "unused")
  6331. context[name] = "var";
  6332. else if (context[name] === "unction")
  6333. context[name] = "closure";
  6334. return true;
  6335. }
  6336. context = context["(context)"];
  6337. } while (context);
  6338. return false;
  6339. };
  6340. var clearImplied = function(name, line) {
  6341. if (!implied[name])
  6342. return;
  6343. var newImplied = [];
  6344. for (var i = 0; i < implied[name].length; i += 1) {
  6345. if (implied[name][i] !== line)
  6346. newImplied.push(implied[name][i]);
  6347. }
  6348. if (newImplied.length === 0)
  6349. delete implied[name];
  6350. else
  6351. implied[name] = newImplied;
  6352. };
  6353. var checkUnused = function(func, key) {
  6354. var type = func[key];
  6355. var tkn = func["(tokens)"][key];
  6356. if (key.charAt(0) === "(")
  6357. return;
  6358. if (type !== "unused" && type !== "unction")
  6359. return;
  6360. // Params are checked separately from other variables.
  6361. if (func["(params)"] && func["(params)"].indexOf(key) !== -1)
  6362. return;
  6363. // Variable is in global scope and defined as exported.
  6364. if (func["(global)"] && _.has(exported, key))
  6365. return;
  6366. warnUnused(key, tkn, "var");
  6367. };
  6368. // Check queued 'x is not defined' instances to see if they're still undefined.
  6369. for (i = 0; i < JSHINT.undefs.length; i += 1) {
  6370. k = JSHINT.undefs[i].slice(0);
  6371. if (markDefined(k[2].value, k[0]) || k[2].forgiveUndef) {
  6372. clearImplied(k[2].value, k[2].line);
  6373. } else if (state.option.undef) {
  6374. warning.apply(warning, k.slice(1));
  6375. }
  6376. }
  6377. functions.forEach(function(func) {
  6378. if (func["(unusedOption)"] === false) {
  6379. return;
  6380. }
  6381. for (var key in func) {
  6382. if (_.has(func, key)) {
  6383. checkUnused(func, key);
  6384. }
  6385. }
  6386. if (!func["(params)"])
  6387. return;
  6388. var params = func["(params)"].slice();
  6389. var param = params.pop();
  6390. var type, unused_opt;
  6391. while (param) {
  6392. type = func[param];
  6393. unused_opt = func["(unusedOption)"] || state.option.unused;
  6394. unused_opt = unused_opt === true ? "last-param" : unused_opt;
  6395. // 'undefined' is a special case for (function(window, undefined) { ... })();
  6396. // patterns.
  6397. if (param === "undefined")
  6398. return;
  6399. if (type === "unused" || type === "unction") {
  6400. warnUnused(param, func["(tokens)"][param], "param", func["(unusedOption)"]);
  6401. } else if (unused_opt === "last-param") {
  6402. return;
  6403. }
  6404. param = params.pop();
  6405. }
  6406. });
  6407. for (var key in declared) {
  6408. if (_.has(declared, key) && !_.has(global, key) && !_.has(exported, key)) {
  6409. warnUnused(key, declared[key], "var");
  6410. }
  6411. }
  6412. } catch (err) {
  6413. if (err && err.name === "JSHintError") {
  6414. var nt = state.tokens.next || {};
  6415. JSHINT.errors.push({
  6416. scope : "(main)",
  6417. raw : err.raw,
  6418. code : err.code,
  6419. reason : err.message,
  6420. line : err.line || nt.line,
  6421. character : err.character || nt.from
  6422. }, null);
  6423. } else {
  6424. throw err;
  6425. }
  6426. }
  6427. // Loop over the listed "internals", and check them as well.
  6428. if (JSHINT.scope === "(main)") {
  6429. o = o || {};
  6430. for (i = 0; i < JSHINT.internals.length; i += 1) {
  6431. k = JSHINT.internals[i];
  6432. o.scope = k.elem;
  6433. itself(k.value, o, g);
  6434. }
  6435. }
  6436. return JSHINT.errors.length === 0;
  6437. };
  6438. // Modules.
  6439. itself.addModule = function(func) {
  6440. extraModules.push(func);
  6441. };
  6442. itself.addModule(style.register);
  6443. // Data summary.
  6444. itself.data = function() {
  6445. var data = {
  6446. functions: [],
  6447. options: state.option
  6448. };
  6449. var implieds = [];
  6450. var members = [];
  6451. var fu, f, i, j, n, globals;
  6452. if (itself.errors.length) {
  6453. data.errors = itself.errors;
  6454. }
  6455. if (state.jsonMode) {
  6456. data.json = true;
  6457. }
  6458. for (n in implied) {
  6459. if (_.has(implied, n)) {
  6460. implieds.push({
  6461. name: n,
  6462. line: implied[n]
  6463. });
  6464. }
  6465. }
  6466. if (implieds.length > 0) {
  6467. data.implieds = implieds;
  6468. }
  6469. if (urls.length > 0) {
  6470. data.urls = urls;
  6471. }
  6472. globals = Object.keys(scope);
  6473. if (globals.length > 0) {
  6474. data.globals = globals;
  6475. }
  6476. for (i = 1; i < functions.length; i += 1) {
  6477. f = functions[i];
  6478. fu = {};
  6479. for (j = 0; j < functionicity.length; j += 1) {
  6480. fu[functionicity[j]] = [];
  6481. }
  6482. for (j = 0; j < functionicity.length; j += 1) {
  6483. if (fu[functionicity[j]].length === 0) {
  6484. delete fu[functionicity[j]];
  6485. }
  6486. }
  6487. fu.name = f["(name)"];
  6488. fu.param = f["(params)"];
  6489. fu.line = f["(line)"];
  6490. fu.character = f["(character)"];
  6491. fu.last = f["(last)"];
  6492. fu.lastcharacter = f["(lastcharacter)"];
  6493. fu.metrics = {
  6494. complexity: f["(metrics)"].ComplexityCount,
  6495. parameters: (f["(params)"] || []).length,
  6496. statements: f["(metrics)"].statementCount
  6497. };
  6498. data.functions.push(fu);
  6499. }
  6500. if (unuseds.length > 0) {
  6501. data.unused = unuseds;
  6502. }
  6503. members = [];
  6504. for (n in member) {
  6505. if (typeof member[n] === "number") {
  6506. data.member = member;
  6507. break;
  6508. }
  6509. }
  6510. return data;
  6511. };
  6512. itself.jshint = itself;
  6513. return itself;
  6514. }());
  6515. // Make JSHINT a Node module, if possible.
  6516. if (typeof exports === "object" && exports) {
  6517. exports.JSHINT = JSHINT;
  6518. }
  6519. },{"./lex.js":"/node_modules/jshint/src/lex.js","./messages.js":"/node_modules/jshint/src/messages.js","./options.js":"/node_modules/jshint/src/options.js","./reg.js":"/node_modules/jshint/src/reg.js","./state.js":"/node_modules/jshint/src/state.js","./style.js":"/node_modules/jshint/src/style.js","./vars.js":"/node_modules/jshint/src/vars.js","events":"/node_modules/browserify/node_modules/events/events.js","underscore":"/node_modules/jshint/node_modules/underscore/underscore.js"}],"/node_modules/jshint/src/lex.js":[function(_dereq_,module,exports){
  6520. /*
  6521. * Lexical analysis and token construction.
  6522. */
  6523. "use strict";
  6524. var _ = _dereq_("underscore");
  6525. var events = _dereq_("events");
  6526. var reg = _dereq_("./reg.js");
  6527. var state = _dereq_("./state.js").state;
  6528. var unicodeData = _dereq_("../data/ascii-identifier-data.js");
  6529. var asciiIdentifierStartTable = unicodeData.asciiIdentifierStartTable;
  6530. var asciiIdentifierPartTable = unicodeData.asciiIdentifierPartTable;
  6531. // Some of these token types are from JavaScript Parser API
  6532. // while others are specific to JSHint parser.
  6533. // JS Parser API: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  6534. var Token = {
  6535. Identifier: 1,
  6536. Punctuator: 2,
  6537. NumericLiteral: 3,
  6538. StringLiteral: 4,
  6539. Comment: 5,
  6540. Keyword: 6,
  6541. NullLiteral: 7,
  6542. BooleanLiteral: 8,
  6543. RegExp: 9,
  6544. TemplateHead: 10,
  6545. TemplateMiddle: 11,
  6546. TemplateTail: 12,
  6547. NoSubstTemplate: 13
  6548. };
  6549. var Context = {
  6550. Block: 1,
  6551. Template: 2
  6552. };
  6553. // Object that handles postponed lexing verifications that checks the parsed
  6554. // environment state.
  6555. function asyncTrigger() {
  6556. var _checks = [];
  6557. return {
  6558. push: function(fn) {
  6559. _checks.push(fn);
  6560. },
  6561. check: function() {
  6562. for (var check = 0; check < _checks.length; ++check) {
  6563. _checks[check]();
  6564. }
  6565. _checks.splice(0, _checks.length);
  6566. }
  6567. };
  6568. }
  6569. /*
  6570. * Lexer for JSHint.
  6571. *
  6572. * This object does a char-by-char scan of the provided source code
  6573. * and produces a sequence of tokens.
  6574. *
  6575. * var lex = new Lexer("var i = 0;");
  6576. * lex.start();
  6577. * lex.token(); // returns the next token
  6578. *
  6579. * You have to use the token() method to move the lexer forward
  6580. * but you don't have to use its return value to get tokens. In addition
  6581. * to token() method returning the next token, the Lexer object also
  6582. * emits events.
  6583. *
  6584. * lex.on("Identifier", function(data) {
  6585. * if (data.name.indexOf("_") >= 0) {
  6586. * // Produce a warning.
  6587. * }
  6588. * });
  6589. *
  6590. * Note that the token() method returns tokens in a JSLint-compatible
  6591. * format while the event emitter uses a slightly modified version of
  6592. * Mozilla's JavaScript Parser API. Eventually, we will move away from
  6593. * JSLint format.
  6594. */
  6595. function Lexer(source) {
  6596. var lines = source;
  6597. if (typeof lines === "string") {
  6598. lines = lines
  6599. .replace(/\r\n/g, "\n")
  6600. .replace(/\r/g, "\n")
  6601. .split("\n");
  6602. }
  6603. // If the first line is a shebang (#!), make it a blank and move on.
  6604. // Shebangs are used by Node scripts.
  6605. if (lines[0] && lines[0].substr(0, 2) === "#!") {
  6606. if (lines[0].indexOf("node") !== -1) {
  6607. state.option.node = true;
  6608. }
  6609. lines[0] = "";
  6610. }
  6611. this.emitter = new events.EventEmitter();
  6612. this.source = source;
  6613. this.setLines(lines);
  6614. this.prereg = true;
  6615. this.line = 0;
  6616. this.char = 1;
  6617. this.from = 1;
  6618. this.input = "";
  6619. this.inComment = false;
  6620. this.context = [];
  6621. this.templateStarts = [];
  6622. for (var i = 0; i < state.option.indent; i += 1) {
  6623. state.tab += " ";
  6624. }
  6625. }
  6626. Lexer.prototype = {
  6627. _lines: [],
  6628. inContext: function(ctxType) {
  6629. return this.context.length > 0 && this.context[this.context.length - 1].type === ctxType;
  6630. },
  6631. pushContext: function(ctxType) {
  6632. this.context.push({ type: ctxType });
  6633. },
  6634. popContext: function() {
  6635. return this.context.pop();
  6636. },
  6637. isContext: function(context) {
  6638. return this.context.length > 0 && this.context[this.context.length - 1] === context;
  6639. },
  6640. currentContext: function() {
  6641. return this.context.length > 0 && this.context[this.context.length - 1];
  6642. },
  6643. getLines: function() {
  6644. this._lines = state.lines;
  6645. return this._lines;
  6646. },
  6647. setLines: function(val) {
  6648. this._lines = val;
  6649. state.lines = this._lines;
  6650. },
  6651. /*
  6652. * Return the next i character without actually moving the
  6653. * char pointer.
  6654. */
  6655. peek: function(i) {
  6656. return this.input.charAt(i || 0);
  6657. },
  6658. /*
  6659. * Move the char pointer forward i times.
  6660. */
  6661. skip: function(i) {
  6662. i = i || 1;
  6663. this.char += i;
  6664. this.input = this.input.slice(i);
  6665. },
  6666. /*
  6667. * Subscribe to a token event. The API for this method is similar
  6668. * Underscore.js i.e. you can subscribe to multiple events with
  6669. * one call:
  6670. *
  6671. * lex.on("Identifier Number", function(data) {
  6672. * // ...
  6673. * });
  6674. */
  6675. on: function(names, listener) {
  6676. names.split(" ").forEach(function(name) {
  6677. this.emitter.on(name, listener);
  6678. }.bind(this));
  6679. },
  6680. /*
  6681. * Trigger a token event. All arguments will be passed to each
  6682. * listener.
  6683. */
  6684. trigger: function() {
  6685. this.emitter.emit.apply(this.emitter, Array.prototype.slice.call(arguments));
  6686. },
  6687. /*
  6688. * Postpone a token event. the checking condition is set as
  6689. * last parameter, and the trigger function is called in a
  6690. * stored callback. To be later called using the check() function
  6691. * by the parser. This avoids parser's peek() to give the lexer
  6692. * a false context.
  6693. */
  6694. triggerAsync: function(type, args, checks, fn) {
  6695. checks.push(function() {
  6696. if (fn()) {
  6697. this.trigger(type, args);
  6698. }
  6699. }.bind(this));
  6700. },
  6701. /*
  6702. * Extract a punctuator out of the next sequence of characters
  6703. * or return 'null' if its not possible.
  6704. *
  6705. * This method's implementation was heavily influenced by the
  6706. * scanPunctuator function in the Esprima parser's source code.
  6707. */
  6708. scanPunctuator: function() {
  6709. var ch1 = this.peek();
  6710. var ch2, ch3, ch4;
  6711. switch (ch1) {
  6712. // Most common single-character punctuators
  6713. case ".":
  6714. if ((/^[0-9]$/).test(this.peek(1))) {
  6715. return null;
  6716. }
  6717. if (this.peek(1) === "." && this.peek(2) === ".") {
  6718. return {
  6719. type: Token.Punctuator,
  6720. value: "..."
  6721. };
  6722. }
  6723. /* falls through */
  6724. case "(":
  6725. case ")":
  6726. case ";":
  6727. case ",":
  6728. case "[":
  6729. case "]":
  6730. case ":":
  6731. case "~":
  6732. case "?":
  6733. return {
  6734. type: Token.Punctuator,
  6735. value: ch1
  6736. };
  6737. // A block/object opener
  6738. case "{":
  6739. this.pushContext(Context.Block);
  6740. return {
  6741. type: Token.Punctuator,
  6742. value: ch1
  6743. };
  6744. // A block/object closer
  6745. case "}":
  6746. if (this.inContext(Context.Block)) {
  6747. this.popContext();
  6748. }
  6749. return {
  6750. type: Token.Punctuator,
  6751. value: ch1
  6752. };
  6753. // A pound sign (for Node shebangs)
  6754. case "#":
  6755. return {
  6756. type: Token.Punctuator,
  6757. value: ch1
  6758. };
  6759. // We're at the end of input
  6760. case "":
  6761. return null;
  6762. }
  6763. // Peek more characters
  6764. ch2 = this.peek(1);
  6765. ch3 = this.peek(2);
  6766. ch4 = this.peek(3);
  6767. // 4-character punctuator: >>>=
  6768. if (ch1 === ">" && ch2 === ">" && ch3 === ">" && ch4 === "=") {
  6769. return {
  6770. type: Token.Punctuator,
  6771. value: ">>>="
  6772. };
  6773. }
  6774. // 3-character punctuators: === !== >>> <<= >>=
  6775. if (ch1 === "=" && ch2 === "=" && ch3 === "=") {
  6776. return {
  6777. type: Token.Punctuator,
  6778. value: "==="
  6779. };
  6780. }
  6781. if (ch1 === "!" && ch2 === "=" && ch3 === "=") {
  6782. return {
  6783. type: Token.Punctuator,
  6784. value: "!=="
  6785. };
  6786. }
  6787. if (ch1 === ">" && ch2 === ">" && ch3 === ">") {
  6788. return {
  6789. type: Token.Punctuator,
  6790. value: ">>>"
  6791. };
  6792. }
  6793. if (ch1 === "<" && ch2 === "<" && ch3 === "=") {
  6794. return {
  6795. type: Token.Punctuator,
  6796. value: "<<="
  6797. };
  6798. }
  6799. if (ch1 === ">" && ch2 === ">" && ch3 === "=") {
  6800. return {
  6801. type: Token.Punctuator,
  6802. value: ">>="
  6803. };
  6804. }
  6805. // Fat arrow punctuator
  6806. if (ch1 === "=" && ch2 === ">") {
  6807. return {
  6808. type: Token.Punctuator,
  6809. value: ch1 + ch2
  6810. };
  6811. }
  6812. // 2-character punctuators: <= >= == != ++ -- << >> && ||
  6813. // += -= *= %= &= |= ^= (but not /=, see below)
  6814. if (ch1 === ch2 && ("+-<>&|".indexOf(ch1) >= 0)) {
  6815. return {
  6816. type: Token.Punctuator,
  6817. value: ch1 + ch2
  6818. };
  6819. }
  6820. if ("<>=!+-*%&|^".indexOf(ch1) >= 0) {
  6821. if (ch2 === "=") {
  6822. return {
  6823. type: Token.Punctuator,
  6824. value: ch1 + ch2
  6825. };
  6826. }
  6827. return {
  6828. type: Token.Punctuator,
  6829. value: ch1
  6830. };
  6831. }
  6832. // Special case: /=.
  6833. if (ch1 === "/") {
  6834. if (ch2 === "=") {
  6835. return {
  6836. type: Token.Punctuator,
  6837. value: "/="
  6838. };
  6839. }
  6840. return {
  6841. type: Token.Punctuator,
  6842. value: "/"
  6843. };
  6844. }
  6845. return null;
  6846. },
  6847. /*
  6848. * Extract a comment out of the next sequence of characters and/or
  6849. * lines or return 'null' if its not possible. Since comments can
  6850. * span across multiple lines this method has to move the char
  6851. * pointer.
  6852. *
  6853. * In addition to normal JavaScript comments (// and /*) this method
  6854. * also recognizes JSHint- and JSLint-specific comments such as
  6855. * /*jshint, /*jslint, /*globals and so on.
  6856. */
  6857. scanComments: function() {
  6858. var ch1 = this.peek();
  6859. var ch2 = this.peek(1);
  6860. var rest = this.input.substr(2);
  6861. var startLine = this.line;
  6862. var startChar = this.char;
  6863. // Create a comment token object and make sure it
  6864. // has all the data JSHint needs to work with special
  6865. // comments.
  6866. function commentToken(label, body, opt) {
  6867. var special = ["jshint", "jslint", "members", "member", "globals", "global", "exported"];
  6868. var isSpecial = false;
  6869. var value = label + body;
  6870. var commentType = "plain";
  6871. opt = opt || {};
  6872. if (opt.isMultiline) {
  6873. value += "*/";
  6874. }
  6875. body = body.replace(/\n/g, " ");
  6876. special.forEach(function(str) {
  6877. if (isSpecial) {
  6878. return;
  6879. }
  6880. // Don't recognize any special comments other than jshint for single-line
  6881. // comments. This introduced many problems with legit comments.
  6882. if (label === "//" && str !== "jshint") {
  6883. return;
  6884. }
  6885. if (body.charAt(str.length) === " " && body.substr(0, str.length) === str) {
  6886. isSpecial = true;
  6887. label = label + str;
  6888. body = body.substr(str.length);
  6889. }
  6890. if (!isSpecial && body.charAt(0) === " " && body.charAt(str.length + 1) === " " &&
  6891. body.substr(1, str.length) === str) {
  6892. isSpecial = true;
  6893. label = label + " " + str;
  6894. body = body.substr(str.length + 1);
  6895. }
  6896. if (!isSpecial) {
  6897. return;
  6898. }
  6899. switch (str) {
  6900. case "member":
  6901. commentType = "members";
  6902. break;
  6903. case "global":
  6904. commentType = "globals";
  6905. break;
  6906. default:
  6907. commentType = str;
  6908. }
  6909. });
  6910. return {
  6911. type: Token.Comment,
  6912. commentType: commentType,
  6913. value: value,
  6914. body: body,
  6915. isSpecial: isSpecial,
  6916. isMultiline: opt.isMultiline || false,
  6917. isMalformed: opt.isMalformed || false
  6918. };
  6919. }
  6920. // End of unbegun comment. Raise an error and skip that input.
  6921. if (ch1 === "*" && ch2 === "/") {
  6922. this.trigger("error", {
  6923. code: "E018",
  6924. line: startLine,
  6925. character: startChar
  6926. });
  6927. this.skip(2);
  6928. return null;
  6929. }
  6930. // Comments must start either with // or /*
  6931. if (ch1 !== "/" || (ch2 !== "*" && ch2 !== "/")) {
  6932. return null;
  6933. }
  6934. // One-line comment
  6935. if (ch2 === "/") {
  6936. this.skip(this.input.length); // Skip to the EOL.
  6937. return commentToken("//", rest);
  6938. }
  6939. var body = "";
  6940. /* Multi-line comment */
  6941. if (ch2 === "*") {
  6942. this.inComment = true;
  6943. this.skip(2);
  6944. while (this.peek() !== "*" || this.peek(1) !== "/") {
  6945. if (this.peek() === "") { // End of Line
  6946. body += "\n";
  6947. // If we hit EOF and our comment is still unclosed,
  6948. // trigger an error and end the comment implicitly.
  6949. if (!this.nextLine()) {
  6950. this.trigger("error", {
  6951. code: "E017",
  6952. line: startLine,
  6953. character: startChar
  6954. });
  6955. this.inComment = false;
  6956. return commentToken("/*", body, {
  6957. isMultiline: true,
  6958. isMalformed: true
  6959. });
  6960. }
  6961. } else {
  6962. body += this.peek();
  6963. this.skip();
  6964. }
  6965. }
  6966. this.skip(2);
  6967. this.inComment = false;
  6968. return commentToken("/*", body, { isMultiline: true });
  6969. }
  6970. },
  6971. /*
  6972. * Extract a keyword out of the next sequence of characters or
  6973. * return 'null' if its not possible.
  6974. */
  6975. scanKeyword: function() {
  6976. var result = /^[a-zA-Z_$][a-zA-Z0-9_$]*/.exec(this.input);
  6977. var keywords = [
  6978. "if", "in", "do", "var", "for", "new",
  6979. "try", "let", "this", "else", "case",
  6980. "void", "with", "enum", "while", "break",
  6981. "catch", "throw", "const", "yield", "class",
  6982. "super", "return", "typeof", "delete",
  6983. "switch", "export", "import", "default",
  6984. "finally", "extends", "function", "continue",
  6985. "debugger", "instanceof"
  6986. ];
  6987. if (result && keywords.indexOf(result[0]) >= 0) {
  6988. return {
  6989. type: Token.Keyword,
  6990. value: result[0]
  6991. };
  6992. }
  6993. return null;
  6994. },
  6995. /*
  6996. * Extract a JavaScript identifier out of the next sequence of
  6997. * characters or return 'null' if its not possible. In addition,
  6998. * to Identifier this method can also produce BooleanLiteral
  6999. * (true/false) and NullLiteral (null).
  7000. */
  7001. scanIdentifier: function() {
  7002. var id = "";
  7003. var index = 0;
  7004. var type, char;
  7005. function isNonAsciiIdentifierStart(code) {
  7006. return code > 256;
  7007. }
  7008. function isNonAsciiIdentifierPart(code) {
  7009. return code > 256;
  7010. }
  7011. function isHexDigit(str) {
  7012. return (/^[0-9a-fA-F]$/).test(str);
  7013. }
  7014. var readUnicodeEscapeSequence = function() {
  7015. /*jshint validthis:true */
  7016. index += 1;
  7017. if (this.peek(index) !== "u") {
  7018. return null;
  7019. }
  7020. var ch1 = this.peek(index + 1);
  7021. var ch2 = this.peek(index + 2);
  7022. var ch3 = this.peek(index + 3);
  7023. var ch4 = this.peek(index + 4);
  7024. var code;
  7025. if (isHexDigit(ch1) && isHexDigit(ch2) && isHexDigit(ch3) && isHexDigit(ch4)) {
  7026. code = parseInt(ch1 + ch2 + ch3 + ch4, 16);
  7027. if (asciiIdentifierPartTable[code] || isNonAsciiIdentifierPart(code)) {
  7028. index += 5;
  7029. return "\\u" + ch1 + ch2 + ch3 + ch4;
  7030. }
  7031. return null;
  7032. }
  7033. return null;
  7034. }.bind(this);
  7035. var getIdentifierStart = function() {
  7036. /*jshint validthis:true */
  7037. var chr = this.peek(index);
  7038. var code = chr.charCodeAt(0);
  7039. if (code === 92) {
  7040. return readUnicodeEscapeSequence();
  7041. }
  7042. if (code < 128) {
  7043. if (asciiIdentifierStartTable[code]) {
  7044. index += 1;
  7045. return chr;
  7046. }
  7047. return null;
  7048. }
  7049. if (isNonAsciiIdentifierStart(code)) {
  7050. index += 1;
  7051. return chr;
  7052. }
  7053. return null;
  7054. }.bind(this);
  7055. var getIdentifierPart = function() {
  7056. /*jshint validthis:true */
  7057. var chr = this.peek(index);
  7058. var code = chr.charCodeAt(0);
  7059. if (code === 92) {
  7060. return readUnicodeEscapeSequence();
  7061. }
  7062. if (code < 128) {
  7063. if (asciiIdentifierPartTable[code]) {
  7064. index += 1;
  7065. return chr;
  7066. }
  7067. return null;
  7068. }
  7069. if (isNonAsciiIdentifierPart(code)) {
  7070. index += 1;
  7071. return chr;
  7072. }
  7073. return null;
  7074. }.bind(this);
  7075. function removeEscapeSequences(id) {
  7076. return id.replace(/\\u([0-9a-fA-F]{4})/g, function(m0, codepoint) {
  7077. return String.fromCharCode(parseInt(codepoint, 16));
  7078. });
  7079. }
  7080. char = getIdentifierStart();
  7081. if (char === null) {
  7082. return null;
  7083. }
  7084. id = char;
  7085. for (;;) {
  7086. char = getIdentifierPart();
  7087. if (char === null) {
  7088. break;
  7089. }
  7090. id += char;
  7091. }
  7092. switch (id) {
  7093. case "true":
  7094. case "false":
  7095. type = Token.BooleanLiteral;
  7096. break;
  7097. case "null":
  7098. type = Token.NullLiteral;
  7099. break;
  7100. default:
  7101. type = Token.Identifier;
  7102. }
  7103. return {
  7104. type: type,
  7105. value: removeEscapeSequences(id),
  7106. text: id,
  7107. tokenLength: id.length
  7108. };
  7109. },
  7110. /*
  7111. * Extract a numeric literal out of the next sequence of
  7112. * characters or return 'null' if its not possible. This method
  7113. * supports all numeric literals described in section 7.8.3
  7114. * of the EcmaScript 5 specification.
  7115. *
  7116. * This method's implementation was heavily influenced by the
  7117. * scanNumericLiteral function in the Esprima parser's source code.
  7118. */
  7119. scanNumericLiteral: function() {
  7120. var index = 0;
  7121. var value = "";
  7122. var length = this.input.length;
  7123. var char = this.peek(index);
  7124. var bad;
  7125. var isAllowedDigit = isDecimalDigit;
  7126. var base = 10;
  7127. var isLegacy = false;
  7128. function isDecimalDigit(str) {
  7129. return (/^[0-9]$/).test(str);
  7130. }
  7131. function isOctalDigit(str) {
  7132. return (/^[0-7]$/).test(str);
  7133. }
  7134. function isBinaryDigit(str) {
  7135. return (/^[01]$/).test(str);
  7136. }
  7137. function isHexDigit(str) {
  7138. return (/^[0-9a-fA-F]$/).test(str);
  7139. }
  7140. function isIdentifierStart(ch) {
  7141. return (ch === "$") || (ch === "_") || (ch === "\\") ||
  7142. (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z");
  7143. }
  7144. // Numbers must start either with a decimal digit or a point.
  7145. if (char !== "." && !isDecimalDigit(char)) {
  7146. return null;
  7147. }
  7148. if (char !== ".") {
  7149. value = this.peek(index);
  7150. index += 1;
  7151. char = this.peek(index);
  7152. if (value === "0") {
  7153. // Base-16 numbers.
  7154. if (char === "x" || char === "X") {
  7155. isAllowedDigit = isHexDigit;
  7156. base = 16;
  7157. index += 1;
  7158. value += char;
  7159. }
  7160. // Base-8 numbers.
  7161. if (char === "o" || char === "O") {
  7162. isAllowedDigit = isOctalDigit;
  7163. base = 8;
  7164. if (!state.option.esnext) {
  7165. this.trigger("warning", {
  7166. code: "W119",
  7167. line: this.line,
  7168. character: this.char,
  7169. data: [ "Octal integer literal" ]
  7170. });
  7171. }
  7172. index += 1;
  7173. value += char;
  7174. }
  7175. // Base-2 numbers.
  7176. if (char === "b" || char === "B") {
  7177. isAllowedDigit = isBinaryDigit;
  7178. base = 2;
  7179. if (!state.option.esnext) {
  7180. this.trigger("warning", {
  7181. code: "W119",
  7182. line: this.line,
  7183. character: this.char,
  7184. data: [ "Binary integer literal" ]
  7185. });
  7186. }
  7187. index += 1;
  7188. value += char;
  7189. }
  7190. // Legacy base-8 numbers.
  7191. if (isOctalDigit(char)) {
  7192. isAllowedDigit = isOctalDigit;
  7193. base = 8;
  7194. isLegacy = true;
  7195. bad = false;
  7196. index += 1;
  7197. value += char;
  7198. }
  7199. // Decimal numbers that start with '0' such as '09' are illegal
  7200. // but we still parse them and return as malformed.
  7201. if (!isOctalDigit(char) && isDecimalDigit(char)) {
  7202. index += 1;
  7203. value += char;
  7204. }
  7205. }
  7206. while (index < length) {
  7207. char = this.peek(index);
  7208. if (isLegacy && isDecimalDigit(char)) {
  7209. // Numbers like '019' (note the 9) are not valid octals
  7210. // but we still parse them and mark as malformed.
  7211. bad = true;
  7212. } else if (!isAllowedDigit(char)) {
  7213. break;
  7214. }
  7215. value += char;
  7216. index += 1;
  7217. }
  7218. if (isAllowedDigit !== isDecimalDigit) {
  7219. if (!isLegacy && value.length <= 2) { // 0x
  7220. return {
  7221. type: Token.NumericLiteral,
  7222. value: value,
  7223. isMalformed: true
  7224. };
  7225. }
  7226. if (index < length) {
  7227. char = this.peek(index);
  7228. if (isIdentifierStart(char)) {
  7229. return null;
  7230. }
  7231. }
  7232. return {
  7233. type: Token.NumericLiteral,
  7234. value: value,
  7235. base: base,
  7236. isLegacy: isLegacy,
  7237. isMalformed: false
  7238. };
  7239. }
  7240. }
  7241. // Decimal digits.
  7242. if (char === ".") {
  7243. value += char;
  7244. index += 1;
  7245. while (index < length) {
  7246. char = this.peek(index);
  7247. if (!isDecimalDigit(char)) {
  7248. break;
  7249. }
  7250. value += char;
  7251. index += 1;
  7252. }
  7253. }
  7254. // Exponent part.
  7255. if (char === "e" || char === "E") {
  7256. value += char;
  7257. index += 1;
  7258. char = this.peek(index);
  7259. if (char === "+" || char === "-") {
  7260. value += this.peek(index);
  7261. index += 1;
  7262. }
  7263. char = this.peek(index);
  7264. if (isDecimalDigit(char)) {
  7265. value += char;
  7266. index += 1;
  7267. while (index < length) {
  7268. char = this.peek(index);
  7269. if (!isDecimalDigit(char)) {
  7270. break;
  7271. }
  7272. value += char;
  7273. index += 1;
  7274. }
  7275. } else {
  7276. return null;
  7277. }
  7278. }
  7279. if (index < length) {
  7280. char = this.peek(index);
  7281. if (isIdentifierStart(char)) {
  7282. return null;
  7283. }
  7284. }
  7285. return {
  7286. type: Token.NumericLiteral,
  7287. value: value,
  7288. base: base,
  7289. isMalformed: !isFinite(value)
  7290. };
  7291. },
  7292. // Assumes previously parsed character was \ (=== '\\') and was not skipped.
  7293. scanEscapeSequence: function(checks) {
  7294. var allowNewLine = false;
  7295. var jump = 1;
  7296. this.skip();
  7297. var char = this.peek();
  7298. switch (char) {
  7299. case "'":
  7300. this.triggerAsync("warning", {
  7301. code: "W114",
  7302. line: this.line,
  7303. character: this.char,
  7304. data: [ "\\'" ]
  7305. }, checks, function() {return state.jsonMode; });
  7306. break;
  7307. case "b":
  7308. char = "\\b";
  7309. break;
  7310. case "f":
  7311. char = "\\f";
  7312. break;
  7313. case "n":
  7314. char = "\\n";
  7315. break;
  7316. case "r":
  7317. char = "\\r";
  7318. break;
  7319. case "t":
  7320. char = "\\t";
  7321. break;
  7322. case "0":
  7323. char = "\\0";
  7324. // Octal literals fail in strict mode.
  7325. // Check if the number is between 00 and 07.
  7326. var n = parseInt(this.peek(1), 10);
  7327. this.triggerAsync("warning", {
  7328. code: "W115",
  7329. line: this.line,
  7330. character: this.char
  7331. }, checks,
  7332. function() { return n >= 0 && n <= 7 && state.isStrict(); });
  7333. break;
  7334. case "u":
  7335. var hexCode = this.input.substr(1, 4);
  7336. var code = parseInt(hexCode, 16);
  7337. if (isNaN(code)) {
  7338. this.trigger("warning", {
  7339. code: "W052",
  7340. line: this.line,
  7341. character: this.char,
  7342. data: [ "u" + hexCode ]
  7343. });
  7344. }
  7345. char = String.fromCharCode(code);
  7346. jump = 5;
  7347. break;
  7348. case "v":
  7349. this.triggerAsync("warning", {
  7350. code: "W114",
  7351. line: this.line,
  7352. character: this.char,
  7353. data: [ "\\v" ]
  7354. }, checks, function() { return state.jsonMode; });
  7355. char = "\v";
  7356. break;
  7357. case "x":
  7358. var x = parseInt(this.input.substr(1, 2), 16);
  7359. this.triggerAsync("warning", {
  7360. code: "W114",
  7361. line: this.line,
  7362. character: this.char,
  7363. data: [ "\\x-" ]
  7364. }, checks, function() { return state.jsonMode; });
  7365. char = String.fromCharCode(x);
  7366. jump = 3;
  7367. break;
  7368. case "\\":
  7369. char = "\\\\";
  7370. break;
  7371. case "\"":
  7372. char = "\\\"";
  7373. break;
  7374. case "/":
  7375. break;
  7376. case "":
  7377. allowNewLine = true;
  7378. char = "";
  7379. break;
  7380. }
  7381. return { char: char, jump: jump, allowNewLine: allowNewLine };
  7382. },
  7383. /*
  7384. * Extract a template literal out of the next sequence of characters
  7385. * and/or lines or return 'null' if its not possible. Since template
  7386. * literals can span across multiple lines, this method has to move
  7387. * the char pointer.
  7388. */
  7389. scanTemplateLiteral: function(checks) {
  7390. var tokenType;
  7391. var value = "";
  7392. var ch;
  7393. var startLine = this.line;
  7394. var startChar = this.char;
  7395. var depth = this.templateStarts.length;
  7396. if (!state.option.esnext) {
  7397. // Only lex template strings in ESNext mode.
  7398. return null;
  7399. } else if (this.peek() === "`") {
  7400. // Template must start with a backtick.
  7401. tokenType = Token.TemplateHead;
  7402. this.templateStarts.push({ line: this.line, char: this.char });
  7403. depth = this.templateStarts.length;
  7404. this.skip(1);
  7405. this.pushContext(Context.Template);
  7406. } else if (this.inContext(Context.Template) && this.peek() === "}") {
  7407. // If we're in a template context, and we have a '}', lex a TemplateMiddle.
  7408. tokenType = Token.TemplateMiddle;
  7409. } else {
  7410. // Go lex something else.
  7411. return null;
  7412. }
  7413. while (this.peek() !== "`") {
  7414. while ((ch = this.peek()) === "") {
  7415. value += "\n";
  7416. if (!this.nextLine()) {
  7417. // Unclosed template literal --- point to the starting "`"
  7418. var startPos = this.templateStarts.pop();
  7419. this.trigger("error", {
  7420. code: "E052",
  7421. line: startPos.line,
  7422. character: startPos.char
  7423. });
  7424. return {
  7425. type: tokenType,
  7426. value: value,
  7427. startLine: startLine,
  7428. startChar: startChar,
  7429. isUnclosed: true,
  7430. depth: depth,
  7431. context: this.popContext()
  7432. };
  7433. }
  7434. }
  7435. if (ch === '$' && this.peek(1) === '{') {
  7436. value += '${';
  7437. this.skip(2);
  7438. return {
  7439. type: tokenType,
  7440. value: value,
  7441. startLine: startLine,
  7442. startChar: startChar,
  7443. isUnclosed: false,
  7444. depth: depth,
  7445. context: this.currentContext()
  7446. };
  7447. } else if (ch === '\\') {
  7448. var escape = this.scanEscapeSequence(checks);
  7449. value += escape.char;
  7450. this.skip(escape.jump);
  7451. } else if (ch !== '`') {
  7452. // Otherwise, append the value and continue.
  7453. value += ch;
  7454. this.skip(1);
  7455. }
  7456. }
  7457. // Final value is either NoSubstTemplate or TemplateTail
  7458. tokenType = tokenType === Token.TemplateHead ? Token.NoSubstTemplate : Token.TemplateTail;
  7459. this.skip(1);
  7460. this.templateStarts.pop();
  7461. return {
  7462. type: tokenType,
  7463. value: value,
  7464. startLine: startLine,
  7465. startChar: startChar,
  7466. isUnclosed: false,
  7467. depth: depth,
  7468. context: this.popContext()
  7469. };
  7470. },
  7471. /*
  7472. * Extract a string out of the next sequence of characters and/or
  7473. * lines or return 'null' if its not possible. Since strings can
  7474. * span across multiple lines this method has to move the char
  7475. * pointer.
  7476. *
  7477. * This method recognizes pseudo-multiline JavaScript strings:
  7478. *
  7479. * var str = "hello\
  7480. * world";
  7481. */
  7482. scanStringLiteral: function(checks) {
  7483. /*jshint loopfunc:true */
  7484. var quote = this.peek();
  7485. // String must start with a quote.
  7486. if (quote !== "\"" && quote !== "'") {
  7487. return null;
  7488. }
  7489. // In JSON strings must always use double quotes.
  7490. this.triggerAsync("warning", {
  7491. code: "W108",
  7492. line: this.line,
  7493. character: this.char // +1?
  7494. }, checks, function() { return state.jsonMode && quote !== "\""; });
  7495. var value = "";
  7496. var startLine = this.line;
  7497. var startChar = this.char;
  7498. var allowNewLine = false;
  7499. this.skip();
  7500. while (this.peek() !== quote) {
  7501. if (this.peek() === "") { // End Of Line
  7502. // If an EOL is not preceded by a backslash, show a warning
  7503. // and proceed like it was a legit multi-line string where
  7504. // author simply forgot to escape the newline symbol.
  7505. //
  7506. // Another approach is to implicitly close a string on EOL
  7507. // but it generates too many false positives.
  7508. if (!allowNewLine) {
  7509. this.trigger("warning", {
  7510. code: "W112",
  7511. line: this.line,
  7512. character: this.char
  7513. });
  7514. } else {
  7515. allowNewLine = false;
  7516. // Otherwise show a warning if multistr option was not set.
  7517. // For JSON, show warning no matter what.
  7518. this.triggerAsync("warning", {
  7519. code: "W043",
  7520. line: this.line,
  7521. character: this.char
  7522. }, checks, function() { return !state.option.multistr; });
  7523. this.triggerAsync("warning", {
  7524. code: "W042",
  7525. line: this.line,
  7526. character: this.char
  7527. }, checks, function() { return state.jsonMode && state.option.multistr; });
  7528. }
  7529. // If we get an EOF inside of an unclosed string, show an
  7530. // error and implicitly close it at the EOF point.
  7531. if (!this.nextLine()) {
  7532. this.trigger("error", {
  7533. code: "E029",
  7534. line: startLine,
  7535. character: startChar
  7536. });
  7537. return {
  7538. type: Token.StringLiteral,
  7539. value: value,
  7540. startLine: startLine,
  7541. startChar: startChar,
  7542. isUnclosed: true,
  7543. quote: quote
  7544. };
  7545. }
  7546. } else { // Any character other than End Of Line
  7547. allowNewLine = false;
  7548. var char = this.peek();
  7549. var jump = 1; // A length of a jump, after we're done
  7550. // parsing this character.
  7551. if (char < " ") {
  7552. // Warn about a control character in a string.
  7553. this.trigger("warning", {
  7554. code: "W113",
  7555. line: this.line,
  7556. character: this.char,
  7557. data: [ "<non-printable>" ]
  7558. });
  7559. }
  7560. // Special treatment for some escaped characters.
  7561. if (char === "\\") {
  7562. var parsed = this.scanEscapeSequence(checks);
  7563. char = parsed.char;
  7564. jump = parsed.jump;
  7565. allowNewLine = parsed.allowNewLine;
  7566. }
  7567. value += char;
  7568. this.skip(jump);
  7569. }
  7570. }
  7571. this.skip();
  7572. return {
  7573. type: Token.StringLiteral,
  7574. value: value,
  7575. startLine: startLine,
  7576. startChar: startChar,
  7577. isUnclosed: false,
  7578. quote: quote
  7579. };
  7580. },
  7581. /*
  7582. * Extract a regular expression out of the next sequence of
  7583. * characters and/or lines or return 'null' if its not possible.
  7584. *
  7585. * This method is platform dependent: it accepts almost any
  7586. * regular expression values but then tries to compile and run
  7587. * them using system's RegExp object. This means that there are
  7588. * rare edge cases where one JavaScript engine complains about
  7589. * your regular expression while others don't.
  7590. */
  7591. scanRegExp: function() {
  7592. var index = 0;
  7593. var length = this.input.length;
  7594. var char = this.peek();
  7595. var value = char;
  7596. var body = "";
  7597. var flags = [];
  7598. var malformed = false;
  7599. var isCharSet = false;
  7600. var terminated;
  7601. var scanUnexpectedChars = function() {
  7602. // Unexpected control character
  7603. if (char < " ") {
  7604. malformed = true;
  7605. this.trigger("warning", {
  7606. code: "W048",
  7607. line: this.line,
  7608. character: this.char
  7609. });
  7610. }
  7611. // Unexpected escaped character
  7612. if (char === "<") {
  7613. malformed = true;
  7614. this.trigger("warning", {
  7615. code: "W049",
  7616. line: this.line,
  7617. character: this.char,
  7618. data: [ char ]
  7619. });
  7620. }
  7621. }.bind(this);
  7622. // Regular expressions must start with '/'
  7623. if (!this.prereg || char !== "/") {
  7624. return null;
  7625. }
  7626. index += 1;
  7627. terminated = false;
  7628. // Try to get everything in between slashes. A couple of
  7629. // cases aside (see scanUnexpectedChars) we don't really
  7630. // care whether the resulting expression is valid or not.
  7631. // We will check that later using the RegExp object.
  7632. while (index < length) {
  7633. char = this.peek(index);
  7634. value += char;
  7635. body += char;
  7636. if (isCharSet) {
  7637. if (char === "]") {
  7638. if (this.peek(index - 1) !== "\\" || this.peek(index - 2) === "\\") {
  7639. isCharSet = false;
  7640. }
  7641. }
  7642. if (char === "\\") {
  7643. index += 1;
  7644. char = this.peek(index);
  7645. body += char;
  7646. value += char;
  7647. scanUnexpectedChars();
  7648. }
  7649. index += 1;
  7650. continue;
  7651. }
  7652. if (char === "\\") {
  7653. index += 1;
  7654. char = this.peek(index);
  7655. body += char;
  7656. value += char;
  7657. scanUnexpectedChars();
  7658. if (char === "/") {
  7659. index += 1;
  7660. continue;
  7661. }
  7662. if (char === "[") {
  7663. index += 1;
  7664. continue;
  7665. }
  7666. }
  7667. if (char === "[") {
  7668. isCharSet = true;
  7669. index += 1;
  7670. continue;
  7671. }
  7672. if (char === "/") {
  7673. body = body.substr(0, body.length - 1);
  7674. terminated = true;
  7675. index += 1;
  7676. break;
  7677. }
  7678. index += 1;
  7679. }
  7680. // A regular expression that was never closed is an
  7681. // error from which we cannot recover.
  7682. if (!terminated) {
  7683. this.trigger("error", {
  7684. code: "E015",
  7685. line: this.line,
  7686. character: this.from
  7687. });
  7688. return void this.trigger("fatal", {
  7689. line: this.line,
  7690. from: this.from
  7691. });
  7692. }
  7693. // Parse flags (if any).
  7694. while (index < length) {
  7695. char = this.peek(index);
  7696. if (!/[gim]/.test(char)) {
  7697. break;
  7698. }
  7699. flags.push(char);
  7700. value += char;
  7701. index += 1;
  7702. }
  7703. // Check regular expression for correctness.
  7704. try {
  7705. new RegExp(body, flags.join(""));
  7706. } catch (err) {
  7707. malformed = true;
  7708. this.trigger("error", {
  7709. code: "E016",
  7710. line: this.line,
  7711. character: this.char,
  7712. data: [ err.message ] // Platform dependent!
  7713. });
  7714. }
  7715. return {
  7716. type: Token.RegExp,
  7717. value: value,
  7718. flags: flags,
  7719. isMalformed: malformed
  7720. };
  7721. },
  7722. /*
  7723. * Scan for any occurrence of non-breaking spaces. Non-breaking spaces
  7724. * can be mistakenly typed on OS X with option-space. Non UTF-8 web
  7725. * pages with non-breaking pages produce syntax errors.
  7726. */
  7727. scanNonBreakingSpaces: function() {
  7728. return state.option.nonbsp ?
  7729. this.input.search(/(\u00A0)/) : -1;
  7730. },
  7731. /*
  7732. * Scan for characters that get silently deleted by one or more browsers.
  7733. */
  7734. scanUnsafeChars: function() {
  7735. return this.input.search(reg.unsafeChars);
  7736. },
  7737. /*
  7738. * Produce the next raw token or return 'null' if no tokens can be matched.
  7739. * This method skips over all space characters.
  7740. */
  7741. next: function(checks) {
  7742. this.from = this.char;
  7743. // Move to the next non-space character.
  7744. var start;
  7745. if (/\s/.test(this.peek())) {
  7746. start = this.char;
  7747. while (/\s/.test(this.peek())) {
  7748. this.from += 1;
  7749. this.skip();
  7750. }
  7751. }
  7752. // Methods that work with multi-line structures and move the
  7753. // character pointer.
  7754. var match = this.scanComments() ||
  7755. this.scanStringLiteral(checks) ||
  7756. this.scanTemplateLiteral(checks);
  7757. if (match) {
  7758. return match;
  7759. }
  7760. // Methods that don't move the character pointer.
  7761. match =
  7762. this.scanRegExp() ||
  7763. this.scanPunctuator() ||
  7764. this.scanKeyword() ||
  7765. this.scanIdentifier() ||
  7766. this.scanNumericLiteral();
  7767. if (match) {
  7768. this.skip(match.tokenLength || match.value.length);
  7769. return match;
  7770. }
  7771. // No token could be matched, give up.
  7772. return null;
  7773. },
  7774. /*
  7775. * Switch to the next line and reset all char pointers. Once
  7776. * switched, this method also checks for other minor warnings.
  7777. */
  7778. nextLine: function() {
  7779. var char;
  7780. if (this.line >= this.getLines().length) {
  7781. return false;
  7782. }
  7783. this.input = this.getLines()[this.line];
  7784. this.line += 1;
  7785. this.char = 1;
  7786. this.from = 1;
  7787. var inputTrimmed = this.input.trim();
  7788. var startsWith = function() {
  7789. return _.some(arguments, function(prefix) {
  7790. return inputTrimmed.indexOf(prefix) === 0;
  7791. });
  7792. };
  7793. var endsWith = function() {
  7794. return _.some(arguments, function(suffix) {
  7795. return inputTrimmed.indexOf(suffix, inputTrimmed.length - suffix.length) !== -1;
  7796. });
  7797. };
  7798. // If we are ignoring linter errors, replace the input with empty string
  7799. // if it doesn't already at least start or end a multi-line comment
  7800. if (state.ignoreLinterErrors === true) {
  7801. if (!startsWith("/*", "//") && !(this.inComment && endsWith("*/"))) {
  7802. this.input = "";
  7803. }
  7804. }
  7805. char = this.scanNonBreakingSpaces();
  7806. if (char >= 0) {
  7807. this.trigger("warning", { code: "W125", line: this.line, character: char + 1 });
  7808. }
  7809. this.input = this.input.replace(/\t/g, state.tab);
  7810. char = this.scanUnsafeChars();
  7811. if (char >= 0) {
  7812. this.trigger("warning", { code: "W100", line: this.line, character: char });
  7813. }
  7814. // If there is a limit on line length, warn when lines get too
  7815. // long.
  7816. if (state.option.maxlen && state.option.maxlen < this.input.length) {
  7817. var inComment = this.inComment ||
  7818. startsWith.call(inputTrimmed, "//") ||
  7819. startsWith.call(inputTrimmed, "/*");
  7820. var shouldTriggerError = !inComment || !reg.maxlenException.test(inputTrimmed);
  7821. if (shouldTriggerError) {
  7822. this.trigger("warning", { code: "W101", line: this.line, character: this.input.length });
  7823. }
  7824. }
  7825. return true;
  7826. },
  7827. /*
  7828. * This is simply a synonym for nextLine() method with a friendlier
  7829. * public name.
  7830. */
  7831. start: function() {
  7832. this.nextLine();
  7833. },
  7834. /*
  7835. * Produce the next token. This function is called by advance() to get
  7836. * the next token. It returns a token in a JSLint-compatible format.
  7837. */
  7838. token: function() {
  7839. /*jshint loopfunc:true */
  7840. var checks = asyncTrigger();
  7841. var token;
  7842. function isReserved(token, isProperty) {
  7843. if (!token.reserved) {
  7844. return false;
  7845. }
  7846. var meta = token.meta;
  7847. if (meta && meta.isFutureReservedWord && state.inES5()) {
  7848. // ES3 FutureReservedWord in an ES5 environment.
  7849. if (!meta.es5) {
  7850. return false;
  7851. }
  7852. // Some ES5 FutureReservedWord identifiers are active only
  7853. // within a strict mode environment.
  7854. if (meta.strictOnly) {
  7855. if (!state.option.strict && !state.isStrict()) {
  7856. return false;
  7857. }
  7858. }
  7859. if (isProperty) {
  7860. return false;
  7861. }
  7862. }
  7863. return true;
  7864. }
  7865. // Produce a token object.
  7866. var create = function(type, value, isProperty, token) {
  7867. /*jshint validthis:true */
  7868. var obj;
  7869. if (type !== "(endline)" && type !== "(end)") {
  7870. this.prereg = false;
  7871. }
  7872. if (type === "(punctuator)") {
  7873. switch (value) {
  7874. case ".":
  7875. case ")":
  7876. case "~":
  7877. case "#":
  7878. case "]":
  7879. case "++":
  7880. case "--":
  7881. this.prereg = false;
  7882. break;
  7883. default:
  7884. this.prereg = true;
  7885. }
  7886. obj = Object.create(state.syntax[value] || state.syntax["(error)"]);
  7887. }
  7888. if (type === "(identifier)") {
  7889. if (value === "return" || value === "case" || value === "typeof") {
  7890. this.prereg = true;
  7891. }
  7892. if (_.has(state.syntax, value)) {
  7893. obj = Object.create(state.syntax[value] || state.syntax["(error)"]);
  7894. // If this can't be a reserved keyword, reset the object.
  7895. if (!isReserved(obj, isProperty && type === "(identifier)")) {
  7896. obj = null;
  7897. }
  7898. }
  7899. }
  7900. if (!obj) {
  7901. obj = Object.create(state.syntax[type]);
  7902. }
  7903. obj.identifier = (type === "(identifier)");
  7904. obj.type = obj.type || type;
  7905. obj.value = value;
  7906. obj.line = this.line;
  7907. obj.character = this.char;
  7908. obj.from = this.from;
  7909. if (obj.identifier && token) obj.raw_text = token.text || token.value;
  7910. if (token && token.startLine && token.startLine !== this.line) {
  7911. obj.startLine = token.startLine;
  7912. }
  7913. if (token && token.context) {
  7914. // Context of current token
  7915. obj.context = token.context;
  7916. }
  7917. if (token && token.depth) {
  7918. // Nested template depth
  7919. obj.depth = token.depth;
  7920. }
  7921. if (token && token.isUnclosed) {
  7922. // Mark token as unclosed string / template literal
  7923. obj.isUnclosed = token.isUnclosed;
  7924. }
  7925. if (isProperty && obj.identifier) {
  7926. obj.isProperty = isProperty;
  7927. }
  7928. obj.check = checks.check;
  7929. return obj;
  7930. }.bind(this);
  7931. for (;;) {
  7932. if (!this.input.length) {
  7933. if (this.nextLine()) {
  7934. return create("(endline)", "");
  7935. }
  7936. if (this.exhausted) {
  7937. return null;
  7938. }
  7939. this.exhausted = true;
  7940. return create("(end)", "");
  7941. }
  7942. token = this.next(checks);
  7943. if (!token) {
  7944. if (this.input.length) {
  7945. // Unexpected character.
  7946. this.trigger("error", {
  7947. code: "E024",
  7948. line: this.line,
  7949. character: this.char,
  7950. data: [ this.peek() ]
  7951. });
  7952. this.input = "";
  7953. }
  7954. continue;
  7955. }
  7956. switch (token.type) {
  7957. case Token.StringLiteral:
  7958. this.triggerAsync("String", {
  7959. line: this.line,
  7960. char: this.char,
  7961. from: this.from,
  7962. startLine: token.startLine,
  7963. startChar: token.startChar,
  7964. value: token.value,
  7965. quote: token.quote
  7966. }, checks, function() { return true; });
  7967. return create("(string)", token.value, null, token);
  7968. case Token.TemplateHead:
  7969. this.trigger("TemplateHead", {
  7970. line: this.line,
  7971. char: this.char,
  7972. from: this.from,
  7973. startLine: token.startLine,
  7974. startChar: token.startChar,
  7975. value: token.value
  7976. });
  7977. return create("(template)", token.value, null, token);
  7978. case Token.TemplateMiddle:
  7979. this.trigger("TemplateMiddle", {
  7980. line: this.line,
  7981. char: this.char,
  7982. from: this.from,
  7983. startLine: token.startLine,
  7984. startChar: token.startChar,
  7985. value: token.value
  7986. });
  7987. return create("(template middle)", token.value, null, token);
  7988. case Token.TemplateTail:
  7989. this.trigger("TemplateTail", {
  7990. line: this.line,
  7991. char: this.char,
  7992. from: this.from,
  7993. startLine: token.startLine,
  7994. startChar: token.startChar,
  7995. value: token.value
  7996. });
  7997. return create("(template tail)", token.value, null, token);
  7998. case Token.NoSubstTemplate:
  7999. this.trigger("NoSubstTemplate", {
  8000. line: this.line,
  8001. char: this.char,
  8002. from: this.from,
  8003. startLine: token.startLine,
  8004. startChar: token.startChar,
  8005. value: token.value
  8006. });
  8007. return create("(no subst template)", token.value, null, token);
  8008. case Token.Identifier:
  8009. this.trigger("Identifier", {
  8010. line: this.line,
  8011. char: this.char,
  8012. from: this.form,
  8013. name: token.value,
  8014. raw_name: token.text,
  8015. isProperty: state.tokens.curr.id === "."
  8016. });
  8017. /* falls through */
  8018. case Token.Keyword:
  8019. case Token.NullLiteral:
  8020. case Token.BooleanLiteral:
  8021. return create("(identifier)", token.value, state.tokens.curr.id === ".", token);
  8022. case Token.NumericLiteral:
  8023. if (token.isMalformed) {
  8024. this.trigger("warning", {
  8025. code: "W045",
  8026. line: this.line,
  8027. character: this.char,
  8028. data: [ token.value ]
  8029. });
  8030. }
  8031. this.triggerAsync("warning", {
  8032. code: "W114",
  8033. line: this.line,
  8034. character: this.char,
  8035. data: [ "0x-" ]
  8036. }, checks, function() { return token.base === 16 && state.jsonMode; });
  8037. this.triggerAsync("warning", {
  8038. code: "W115",
  8039. line: this.line,
  8040. character: this.char
  8041. }, checks, function() {
  8042. return state.isStrict() && token.base === 8 && token.isLegacy;
  8043. });
  8044. this.trigger("Number", {
  8045. line: this.line,
  8046. char: this.char,
  8047. from: this.from,
  8048. value: token.value,
  8049. base: token.base,
  8050. isMalformed: token.malformed
  8051. });
  8052. return create("(number)", token.value);
  8053. case Token.RegExp:
  8054. return create("(regexp)", token.value);
  8055. case Token.Comment:
  8056. state.tokens.curr.comment = true;
  8057. if (token.isSpecial) {
  8058. return {
  8059. id: '(comment)',
  8060. value: token.value,
  8061. body: token.body,
  8062. type: token.commentType,
  8063. isSpecial: token.isSpecial,
  8064. line: this.line,
  8065. character: this.char,
  8066. from: this.from
  8067. };
  8068. }
  8069. break;
  8070. case "":
  8071. break;
  8072. default:
  8073. return create("(punctuator)", token.value);
  8074. }
  8075. }
  8076. }
  8077. };
  8078. exports.Lexer = Lexer;
  8079. exports.Context = Context;
  8080. },{"../data/ascii-identifier-data.js":"/node_modules/jshint/data/ascii-identifier-data.js","./reg.js":"/node_modules/jshint/src/reg.js","./state.js":"/node_modules/jshint/src/state.js","events":"/node_modules/browserify/node_modules/events/events.js","underscore":"/node_modules/jshint/node_modules/underscore/underscore.js"}],"/node_modules/jshint/src/messages.js":[function(_dereq_,module,exports){
  8081. "use strict";
  8082. var _ = _dereq_("underscore");
  8083. var errors = {
  8084. // JSHint options
  8085. E001: "Bad option: '{a}'.",
  8086. E002: "Bad option value.",
  8087. // JSHint input
  8088. E003: "Expected a JSON value.",
  8089. E004: "Input is neither a string nor an array of strings.",
  8090. E005: "Input is empty.",
  8091. E006: "Unexpected early end of program.",
  8092. // Strict mode
  8093. E007: "Missing \"use strict\" statement.",
  8094. E008: "Strict violation.",
  8095. E009: "Option 'validthis' can't be used in a global scope.",
  8096. E010: "'with' is not allowed in strict mode.",
  8097. // Constants
  8098. E011: "const '{a}' has already been declared.",
  8099. E012: "const '{a}' is initialized to 'undefined'.",
  8100. E013: "Attempting to override '{a}' which is a constant.",
  8101. // Regular expressions
  8102. E014: "A regular expression literal can be confused with '/='.",
  8103. E015: "Unclosed regular expression.",
  8104. E016: "Invalid regular expression.",
  8105. // Tokens
  8106. E017: "Unclosed comment.",
  8107. E018: "Unbegun comment.",
  8108. E019: "Unmatched '{a}'.",
  8109. E020: "Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.",
  8110. E021: "Expected '{a}' and instead saw '{b}'.",
  8111. E022: "Line breaking error '{a}'.",
  8112. E023: "Missing '{a}'.",
  8113. E024: "Unexpected '{a}'.",
  8114. E025: "Missing ':' on a case clause.",
  8115. E026: "Missing '}' to match '{' from line {a}.",
  8116. E027: "Missing ']' to match '[' from line {a}.",
  8117. E028: "Illegal comma.",
  8118. E029: "Unclosed string.",
  8119. // Everything else
  8120. E030: "Expected an identifier and instead saw '{a}'.",
  8121. E031: "Bad assignment.", // FIXME: Rephrase
  8122. E032: "Expected a small integer or 'false' and instead saw '{a}'.",
  8123. E033: "Expected an operator and instead saw '{a}'.",
  8124. E034: "get/set are ES5 features.",
  8125. E035: "Missing property name.",
  8126. E036: "Expected to see a statement and instead saw a block.",
  8127. E037: null,
  8128. E038: null,
  8129. E039: "Function declarations are not invocable. Wrap the whole function invocation in parens.",
  8130. E040: "Each value should have its own case label.",
  8131. E041: "Unrecoverable syntax error.",
  8132. E042: "Stopping.",
  8133. E043: "Too many errors.",
  8134. E044: null,
  8135. E045: "Invalid for each loop.",
  8136. E046: "A yield statement shall be within a generator function (with syntax: `function*`)",
  8137. E047: null, // Vacant
  8138. E048: "{a} declaration not directly within block.",
  8139. E049: "A {a} cannot be named '{b}'.",
  8140. E050: "Mozilla requires the yield expression to be parenthesized here.",
  8141. E051: "Regular parameters cannot come after default parameters.",
  8142. E052: "Unclosed template literal.",
  8143. E053: "Export declaration must be in global scope.",
  8144. E054: "Class properties must be methods. Expected '(' but instead saw '{a}'.",
  8145. E055: "The '{a}' option cannot be set after any executable code."
  8146. };
  8147. var warnings = {
  8148. W001: "'hasOwnProperty' is a really bad name.",
  8149. W002: "Value of '{a}' may be overwritten in IE 8 and earlier.",
  8150. W003: "'{a}' was used before it was defined.",
  8151. W004: "'{a}' is already defined.",
  8152. W005: "A dot following a number can be confused with a decimal point.",
  8153. W006: "Confusing minuses.",
  8154. W007: "Confusing plusses.",
  8155. W008: "A leading decimal point can be confused with a dot: '{a}'.",
  8156. W009: "The array literal notation [] is preferable.",
  8157. W010: "The object literal notation {} is preferable.",
  8158. W011: null,
  8159. W012: null,
  8160. W013: null,
  8161. W014: "Bad line breaking before '{a}'.",
  8162. W015: null,
  8163. W016: "Unexpected use of '{a}'.",
  8164. W017: "Bad operand.",
  8165. W018: "Confusing use of '{a}'.",
  8166. W019: "Use the isNaN function to compare with NaN.",
  8167. W020: "Read only.",
  8168. W021: "'{a}' is a function.",
  8169. W022: "Do not assign to the exception parameter.",
  8170. W023: "Expected an identifier in an assignment and instead saw a function invocation.",
  8171. W024: "Expected an identifier and instead saw '{a}' (a reserved word).",
  8172. W025: "Missing name in function declaration.",
  8173. W026: "Inner functions should be listed at the top of the outer function.",
  8174. W027: "Unreachable '{a}' after '{b}'.",
  8175. W028: "Label '{a}' on {b} statement.",
  8176. W030: "Expected an assignment or function call and instead saw an expression.",
  8177. W031: "Do not use 'new' for side effects.",
  8178. W032: "Unnecessary semicolon.",
  8179. W033: "Missing semicolon.",
  8180. W034: "Unnecessary directive \"{a}\".",
  8181. W035: "Empty block.",
  8182. W036: "Unexpected /*member '{a}'.",
  8183. W037: "'{a}' is a statement label.",
  8184. W038: "'{a}' used out of scope.",
  8185. W039: "'{a}' is not allowed.",
  8186. W040: "Possible strict violation.",
  8187. W041: "Use '{a}' to compare with '{b}'.",
  8188. W042: "Avoid EOL escaping.",
  8189. W043: "Bad escaping of EOL. Use option multistr if needed.",
  8190. W044: "Bad or unnecessary escaping.", /* TODO(caitp): remove W044 */
  8191. W045: "Bad number '{a}'.",
  8192. W046: "Don't use extra leading zeros '{a}'.",
  8193. W047: "A trailing decimal point can be confused with a dot: '{a}'.",
  8194. W048: "Unexpected control character in regular expression.",
  8195. W049: "Unexpected escaped character '{a}' in regular expression.",
  8196. W050: "JavaScript URL.",
  8197. W051: "Variables should not be deleted.",
  8198. W052: "Unexpected '{a}'.",
  8199. W053: "Do not use {a} as a constructor.",
  8200. W054: "The Function constructor is a form of eval.",
  8201. W055: "A constructor name should start with an uppercase letter.",
  8202. W056: "Bad constructor.",
  8203. W057: "Weird construction. Is 'new' necessary?",
  8204. W058: "Missing '()' invoking a constructor.",
  8205. W059: "Avoid arguments.{a}.",
  8206. W060: "document.write can be a form of eval.",
  8207. W061: "eval can be harmful.",
  8208. W062: "Wrap an immediate function invocation in parens " +
  8209. "to assist the reader in understanding that the expression " +
  8210. "is the result of a function, and not the function itself.",
  8211. W063: "Math is not a function.",
  8212. W064: "Missing 'new' prefix when invoking a constructor.",
  8213. W065: "Missing radix parameter.",
  8214. W066: "Implied eval. Consider passing a function instead of a string.",
  8215. W067: "Bad invocation.",
  8216. W068: "Wrapping non-IIFE function literals in parens is unnecessary.",
  8217. W069: "['{a}'] is better written in dot notation.",
  8218. W070: "Extra comma. (it breaks older versions of IE)",
  8219. W071: "This function has too many statements. ({a})",
  8220. W072: "This function has too many parameters. ({a})",
  8221. W073: "Blocks are nested too deeply. ({a})",
  8222. W074: "This function's cyclomatic complexity is too high. ({a})",
  8223. W075: "Duplicate {a} '{b}'.",
  8224. W076: "Unexpected parameter '{a}' in get {b} function.",
  8225. W077: "Expected a single parameter in set {a} function.",
  8226. W078: "Setter is defined without getter.",
  8227. W079: "Redefinition of '{a}'.",
  8228. W080: "It's not necessary to initialize '{a}' to 'undefined'.",
  8229. W081: null,
  8230. W082: "Function declarations should not be placed in blocks. " +
  8231. "Use a function expression or move the statement to the top of " +
  8232. "the outer function.",
  8233. W083: "Don't make functions within a loop.",
  8234. W084: "Assignment in conditional expression",
  8235. W085: "Don't use 'with'.",
  8236. W086: "Expected a 'break' statement before '{a}'.",
  8237. W087: "Forgotten 'debugger' statement?",
  8238. W088: "Creating global 'for' variable. Should be 'for (var {a} ...'.",
  8239. W089: "The body of a for in should be wrapped in an if statement to filter " +
  8240. "unwanted properties from the prototype.",
  8241. W090: "'{a}' is not a statement label.",
  8242. W091: "'{a}' is out of scope.",
  8243. W093: "Did you mean to return a conditional instead of an assignment?",
  8244. W094: "Unexpected comma.",
  8245. W095: "Expected a string and instead saw {a}.",
  8246. W096: "The '{a}' key may produce unexpected results.",
  8247. W097: "Use the function form of \"use strict\".",
  8248. W098: "'{a}' is defined but never used.",
  8249. W099: null,
  8250. W100: "This character may get silently deleted by one or more browsers.",
  8251. W101: "Line is too long.",
  8252. W102: null,
  8253. W103: "The '{a}' property is deprecated.",
  8254. W104: "'{a}' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).",
  8255. W105: "Unexpected {a} in '{b}'.",
  8256. W106: "Identifier '{a}' is not in camel case.",
  8257. W107: "Script URL.",
  8258. W108: "Strings must use doublequote.",
  8259. W109: "Strings must use singlequote.",
  8260. W110: "Mixed double and single quotes.",
  8261. W112: "Unclosed string.",
  8262. W113: "Control character in string: {a}.",
  8263. W114: "Avoid {a}.",
  8264. W115: "Octal literals are not allowed in strict mode.",
  8265. W116: "Expected '{a}' and instead saw '{b}'.",
  8266. W117: "'{a}' is not defined.",
  8267. W118: "'{a}' is only available in Mozilla JavaScript extensions (use moz option).",
  8268. W119: "'{a}' is only available in ES6 (use esnext option).",
  8269. W120: "You might be leaking a variable ({a}) here.",
  8270. W121: "Extending prototype of native object: '{a}'.",
  8271. W122: "Invalid typeof value '{a}'",
  8272. W123: "'{a}' is already defined in outer scope.",
  8273. W124: "A generator function shall contain a yield statement.",
  8274. W125: "This line contains non-breaking spaces: http://jshint.com/doc/options/#nonbsp",
  8275. W126: "Unnecessary grouping operator.",
  8276. W127: "Unexpected use of a comma operator.",
  8277. W128: "Empty array elements require elision=true.",
  8278. W129: "'{a}' is defined in a future version of JavaScript. Use a " +
  8279. "different variable name to avoid migration issues.",
  8280. W130: "Invalid element after rest element.",
  8281. W131: "Invalid parameter after rest parameter.",
  8282. W132: "`var` declarations are forbidden. Use `let` or `const` instead.",
  8283. W133: "Invalid for-{a} loop left-hand-side: {b}.",
  8284. W134: "The '{a}' option is only available when linting ECMAScript {b} code."
  8285. };
  8286. var info = {
  8287. I001: "Comma warnings can be turned off with 'laxcomma'.",
  8288. I002: null,
  8289. I003: "ES5 option is now set per default"
  8290. };
  8291. exports.errors = {};
  8292. exports.warnings = {};
  8293. exports.info = {};
  8294. _.each(errors, function(desc, code) {
  8295. exports.errors[code] = { code: code, desc: desc };
  8296. });
  8297. _.each(warnings, function(desc, code) {
  8298. exports.warnings[code] = { code: code, desc: desc };
  8299. });
  8300. _.each(info, function(desc, code) {
  8301. exports.info[code] = { code: code, desc: desc };
  8302. });
  8303. },{"underscore":"/node_modules/jshint/node_modules/underscore/underscore.js"}],"/node_modules/jshint/src/name-stack.js":[function(_dereq_,module,exports){
  8304. "use strict";
  8305. function NameStack() {
  8306. this._stack = [];
  8307. }
  8308. Object.defineProperty(NameStack.prototype, "length", {
  8309. get: function() {
  8310. return this._stack.length;
  8311. }
  8312. });
  8313. /**
  8314. * Create a new entry in the stack. Useful for tracking names across
  8315. * expressions.
  8316. */
  8317. NameStack.prototype.push = function() {
  8318. this._stack.push(null);
  8319. };
  8320. /**
  8321. * Discard the most recently-created name on the stack.
  8322. */
  8323. NameStack.prototype.pop = function() {
  8324. this._stack.pop();
  8325. };
  8326. /**
  8327. * Update the most recent name on the top of the stack.
  8328. *
  8329. * @param {object} token The token to consider as the source for the most
  8330. * recent name.
  8331. */
  8332. NameStack.prototype.set = function(token) {
  8333. this._stack[this.length - 1] = token;
  8334. };
  8335. /**
  8336. * Generate a string representation of the most recent name.
  8337. *
  8338. * @returns {string}
  8339. */
  8340. NameStack.prototype.infer = function() {
  8341. var nameToken = this._stack[this.length - 1];
  8342. var prefix = "";
  8343. var type;
  8344. // During expected operation, the topmost entry on the stack will only
  8345. // reflect the current function's name when the function is declared without
  8346. // the `function` keyword (i.e. for in-line accessor methods). In other
  8347. // cases, the `function` expression itself will introduce an empty entry on
  8348. // the top of the stack, and this should be ignored.
  8349. if (!nameToken || nameToken.type === "class") {
  8350. nameToken = this._stack[this.length - 2];
  8351. }
  8352. if (!nameToken) {
  8353. return "(empty)";
  8354. }
  8355. type = nameToken.type;
  8356. if (type !== "(string)" && type !== "(number)" && type !== "(identifier)" && type !== "default") {
  8357. return "(expression)";
  8358. }
  8359. if (nameToken.accessorType) {
  8360. prefix = nameToken.accessorType + " ";
  8361. }
  8362. return prefix + nameToken.value;
  8363. };
  8364. module.exports = NameStack;
  8365. },{}],"/node_modules/jshint/src/options.js":[function(_dereq_,module,exports){
  8366. "use strict";
  8367. // These are the JSHint boolean options.
  8368. exports.bool = {
  8369. enforcing: {
  8370. /**
  8371. * This option prohibits the use of bitwise operators such as `^` (XOR),
  8372. * `|` (OR) and others. Bitwise operators are very rare in JavaScript
  8373. * programs and quite often `&` is simply a mistyped `&&`.
  8374. */
  8375. bitwise : true,
  8376. /**
  8377. *
  8378. * This options prohibits overwriting prototypes of native objects such as
  8379. * `Array`, `Date` and so on.
  8380. *
  8381. * // jshint freeze:true
  8382. * Array.prototype.count = function (value) { return 4; };
  8383. * // -> Warning: Extending prototype of native object: 'Array'.
  8384. */
  8385. freeze : true,
  8386. /**
  8387. * This option allows you to force all variable names to use either
  8388. * camelCase style or UPPER_CASE with underscores.
  8389. *
  8390. * @deprecated JSHint is limiting its scope to issues of code correctness.
  8391. * If you would like to enforce rules relating to code style,
  8392. * check out [the JSCS
  8393. * project](https://github.com/jscs-dev/node-jscs).
  8394. */
  8395. camelcase : true,
  8396. /**
  8397. * This option requires you to always put curly braces around blocks in
  8398. * loops and conditionals. JavaScript allows you to omit curly braces when
  8399. * the block consists of only one statement, for example:
  8400. *
  8401. * while (day)
  8402. * shuffle();
  8403. *
  8404. * However, in some circumstances, it can lead to bugs (you'd think that
  8405. * `sleep()` is a part of the loop while in reality it is not):
  8406. *
  8407. * while (day)
  8408. * shuffle();
  8409. * sleep();
  8410. */
  8411. curly : true,
  8412. /**
  8413. * This options prohibits the use of `==` and `!=` in favor of `===` and
  8414. * `!==`. The former try to coerce values before comparing them which can
  8415. * lead to some unexpected results. The latter don't do any coercion so
  8416. * they are generally safer. If you would like to learn more about type
  8417. * coercion in JavaScript, we recommend [Truth, Equality and
  8418. * JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/)
  8419. * by Angus Croll.
  8420. */
  8421. eqeqeq : true,
  8422. /**
  8423. * This option enables warnings about the use of identifiers which are
  8424. * defined in future versions of JavaScript. Although overwriting them has
  8425. * no effect in contexts where they are not implemented, this practice can
  8426. * cause issues when migrating codebases to newer versions of the language.
  8427. */
  8428. futurehostile: true,
  8429. /**
  8430. * This option suppresses warnings about invalid `typeof` operator values.
  8431. * This operator has only [a limited set of possible return
  8432. * values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof).
  8433. * By default, JSHint warns when you compare its result with an invalid
  8434. * value which often can be a typo.
  8435. *
  8436. * // 'fuction' instead of 'function'
  8437. * if (typeof a == "fuction") { // Invalid typeof value 'fuction'
  8438. * // ...
  8439. * }
  8440. *
  8441. * Do not use this option unless you're absolutely sure you don't want
  8442. * these checks.
  8443. */
  8444. notypeof : true,
  8445. /**
  8446. * This option tells JSHint that your code needs to adhere to ECMAScript 3
  8447. * specification. Use this option if you need your program to be executable
  8448. * in older browsers—such as Internet Explorer 6/7/8/9—and other legacy
  8449. * JavaScript environments.
  8450. */
  8451. es3 : true,
  8452. /**
  8453. * This option enables syntax first defined in [the ECMAScript 5.1
  8454. * specification](http://es5.github.io/). This includes allowing reserved
  8455. * keywords as object properties.
  8456. */
  8457. es5 : true,
  8458. /**
  8459. * This option requires all `for in` loops to filter object's items. The
  8460. * for in statement allows for looping through the names of all of the
  8461. * properties of an object including those inherited through the prototype
  8462. * chain. This behavior can lead to unexpected items in your object so it
  8463. * is generally safer to always filter inherited properties out as shown in
  8464. * the example:
  8465. *
  8466. * for (key in obj) {
  8467. * if (obj.hasOwnProperty(key)) {
  8468. * // We are sure that obj[key] belongs to the object and was not inherited.
  8469. * }
  8470. * }
  8471. *
  8472. * For more in-depth understanding of `for in` loops in JavaScript, read
  8473. * [Exploring JavaScript for-in
  8474. * loops](http://javascriptweblog.wordpress.com/2011/01/04/exploring-javascript-for-in-loops/)
  8475. * by Angus Croll.
  8476. */
  8477. forin : true,
  8478. /**
  8479. * This option suppresses warnings about declaring variables inside of
  8480. * control
  8481. * structures while accessing them later from the outside. Even though
  8482. * JavaScript has only two real scopes—global and function—such practice
  8483. * leads to confusion among people new to the language and hard-to-debug
  8484. * bugs. This is why, by default, JSHint warns about variables that are
  8485. * used outside of their intended scope.
  8486. *
  8487. * function test() {
  8488. * if (true) {
  8489. * var x = 0;
  8490. * }
  8491. *
  8492. * x += 1; // Default: 'x' used out of scope.
  8493. * // No warning when funcscope:true
  8494. * }
  8495. */
  8496. funcscope : true,
  8497. /**
  8498. * This option prohibits the use of immediate function invocations without
  8499. * wrapping them in parentheses. Wrapping parentheses assists readers of
  8500. * your code in understanding that the expression is the result of a
  8501. * function, and not the function itself.
  8502. *
  8503. * @deprecated JSHint is limiting its scope to issues of code correctness.
  8504. * If you would like to enforce rules relating to code style,
  8505. * check out [the JSCS
  8506. * project](https://github.com/jscs-dev/node-jscs).
  8507. */
  8508. immed : true,
  8509. /**
  8510. * This option suppresses warnings about the `__iterator__` property. This
  8511. * property is not supported by all browsers so use it carefully.
  8512. */
  8513. iterator : true,
  8514. /**
  8515. * This option requires you to capitalize names of constructor functions.
  8516. * Capitalizing functions that are intended to be used with `new` operator
  8517. * is just a convention that helps programmers to visually distinguish
  8518. * constructor functions from other types of functions to help spot
  8519. * mistakes when using `this`.
  8520. *
  8521. * Not doing so won't break your code in any browsers or environments but
  8522. * it will be a bit harder to figure out—by reading the code—if the
  8523. * function was supposed to be used with or without new. And this is
  8524. * important because when the function that was intended to be used with
  8525. * `new` is used without it, `this` will point to the global object instead
  8526. * of a new object.
  8527. *
  8528. * @deprecated JSHint is limiting its scope to issues of code correctness.
  8529. * If you would like to enforce rules relating to code style,
  8530. * check out [the JSCS
  8531. * project](https://github.com/jscs-dev/node-jscs).
  8532. */
  8533. newcap : true,
  8534. /**
  8535. * This option prohibits the use of `arguments.caller` and
  8536. * `arguments.callee`. Both `.caller` and `.callee` make quite a few
  8537. * optimizations impossible so they were deprecated in future versions of
  8538. * JavaScript. In fact, ECMAScript 5 forbids the use of `arguments.callee`
  8539. * in strict mode.
  8540. */
  8541. noarg : true,
  8542. /**
  8543. * This option prohibits the use of the comma operator. When misused, the
  8544. * comma operator can obscure the value of a statement and promote
  8545. * incorrect code.
  8546. */
  8547. nocomma : true,
  8548. /**
  8549. * This option warns when you have an empty block in your code. JSLint was
  8550. * originally warning for all empty blocks and we simply made it optional.
  8551. * There were no studies reporting that empty blocks in JavaScript break
  8552. * your code in any way.
  8553. *
  8554. * @deprecated JSHint is limiting its scope to issues of code correctness.
  8555. * If you would like to enforce rules relating to code style,
  8556. * check out [the JSCS
  8557. * project](https://github.com/jscs-dev/node-jscs).
  8558. */
  8559. noempty : true,
  8560. /**
  8561. * This option warns about "non-breaking whitespace" characters. These
  8562. * characters can be entered with option-space on Mac computers and have a
  8563. * potential of breaking non-UTF8 web pages.
  8564. */
  8565. nonbsp : true,
  8566. /**
  8567. * This option prohibits the use of constructor functions for side-effects.
  8568. * Some people like to call constructor functions without assigning its
  8569. * result to any variable:
  8570. *
  8571. * new MyConstructor();
  8572. *
  8573. * There is no advantage in this approach over simply calling
  8574. * `MyConstructor` since the object that the operator `new` creates isn't
  8575. * used anywhere so you should generally avoid constructors like this one.
  8576. */
  8577. nonew : true,
  8578. /**
  8579. * This option prohibits the use of explicitly undeclared variables. This
  8580. * option is very useful for spotting leaking and mistyped variables.
  8581. *
  8582. * // jshint undef:true
  8583. *
  8584. * function test() {
  8585. * var myVar = 'Hello, World';
  8586. * console.log(myvar); // Oops, typoed here. JSHint with undef will complain
  8587. * }
  8588. *
  8589. * If your variable is defined in another file, you can use the `global`
  8590. * directive to tell JSHint about it.
  8591. */
  8592. undef : true,
  8593. /**
  8594. * This option prohibits the use of the grouping operator when it is not
  8595. * strictly required. Such usage commonly reflects a misunderstanding of
  8596. * unary operators, for example:
  8597. *
  8598. * // jshint singleGroups: true
  8599. *
  8600. * delete(obj.attr); // Warning: Unnecessary grouping operator.
  8601. */
  8602. singleGroups: false,
  8603. /**
  8604. * This option requires all functions to run in ECMAScript 5's strict mode.
  8605. * [Strict mode](https://developer.mozilla.org/en/JavaScript/Strict_mode)
  8606. * is a way to opt in to a restricted variant of JavaScript. Strict mode
  8607. * eliminates some JavaScript pitfalls that didn't cause errors by changing
  8608. * them to produce errors. It also fixes mistakes that made it difficult
  8609. * for the JavaScript engines to perform certain optimizations.
  8610. *
  8611. * *Note:* This option enables strict mode for function scope only. It
  8612. * *prohibits* the global scoped strict mode because it might break
  8613. * third-party widgets on your page. If you really want to use global
  8614. * strict mode, see the *globalstrict* option.
  8615. */
  8616. strict : true,
  8617. /**
  8618. * When set to true, the use of VariableStatements are forbidden.
  8619. * For example:
  8620. *
  8621. * // jshint varstmt: true
  8622. *
  8623. * var a; // Warning: `var` declarations are forbidden. Use `let` or `const` instead.
  8624. */
  8625. varstmt: false,
  8626. /**
  8627. * This option is a short hand for the most strict JSHint configuration as
  8628. * available in JSHint version 2.6.3. It enables all enforcing options and
  8629. * disables all relaxing options that were defined in that release.
  8630. *
  8631. * @deprecated The option cannot be maintained without automatically opting
  8632. * users in to new features. This can lead to unexpected
  8633. * warnings/errors in when upgrading between minor versions of
  8634. * JSHint.
  8635. */
  8636. enforceall : false
  8637. },
  8638. relaxing: {
  8639. /**
  8640. * This option suppresses warnings about missing semicolons. There is a lot
  8641. * of FUD about semicolon spread by quite a few people in the community.
  8642. * The common myths are that semicolons are required all the time (they are
  8643. * not) and that they are unreliable. JavaScript has rules about semicolons
  8644. * which are followed by *all* browsers so it is up to you to decide
  8645. * whether you should or should not use semicolons in your code.
  8646. *
  8647. * For more information about semicolons in JavaScript read [An Open Letter
  8648. * to JavaScript Leaders Regarding
  8649. * Semicolons](http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding)
  8650. * by Isaac Schlueter and [JavaScript Semicolon
  8651. * Insertion](http://inimino.org/~inimino/blog/javascript_semicolons).
  8652. */
  8653. asi : true,
  8654. /**
  8655. * This option suppresses warnings about multi-line strings. Multi-line
  8656. * strings can be dangerous in JavaScript because all hell breaks loose if
  8657. * you accidentally put a whitespace in between the escape character (`\`)
  8658. * and a new line.
  8659. *
  8660. * Note that even though this option allows correct multi-line strings, it
  8661. * still warns about multi-line strings without escape characters or with
  8662. * anything in between the escape character and a whitespace.
  8663. *
  8664. * // jshint multistr:true
  8665. *
  8666. * var text = "Hello\
  8667. * World"; // All good.
  8668. *
  8669. * text = "Hello
  8670. * World"; // Warning, no escape character.
  8671. *
  8672. * text = "Hello\
  8673. * World"; // Warning, there is a space after \
  8674. *
  8675. * @deprecated JSHint is limiting its scope to issues of code correctness.
  8676. * If you would like to enforce rules relating to code style,
  8677. * check out [the JSCS
  8678. * project](https://github.com/jscs-dev/node-jscs).
  8679. */
  8680. multistr : true,
  8681. /**
  8682. * This option suppresses warnings about the `debugger` statements in your
  8683. * code.
  8684. */
  8685. debug : true,
  8686. /**
  8687. * This option suppresses warnings about the use of assignments in cases
  8688. * where comparisons are expected. More often than not, code like `if (a =
  8689. * 10) {}` is a typo. However, it can be useful in cases like this one:
  8690. *
  8691. * for (var i = 0, person; person = people[i]; i++) {}
  8692. *
  8693. * You can silence this error on a per-use basis by surrounding the assignment
  8694. * with parenthesis, such as:
  8695. *
  8696. * for (var i = 0, person; (person = people[i]); i++) {}
  8697. */
  8698. boss : true,
  8699. /**
  8700. * This option suppresses warnings about the use of `eval`. The use of
  8701. * `eval` is discouraged because it can make your code vulnerable to
  8702. * various injection attacks and it makes it hard for JavaScript
  8703. * interpreter to do certain optimizations.
  8704. */
  8705. evil : true,
  8706. /**
  8707. * This option suppresses warnings about the use of global strict mode.
  8708. * Global strict mode can break third-party widgets so it is not
  8709. * recommended.
  8710. *
  8711. * For more info about strict mode see the `strict` option.
  8712. */
  8713. globalstrict: true,
  8714. /**
  8715. * This option prohibits the use of unary increment and decrement
  8716. * operators. Some people think that `++` and `--` reduces the quality of
  8717. * their coding styles and there are programming languages—such as
  8718. * Python—that go completely without these operators.
  8719. */
  8720. plusplus : true,
  8721. /**
  8722. * This option suppresses warnings about the `__proto__` property.
  8723. */
  8724. proto : true,
  8725. /**
  8726. * This option suppresses warnings about the use of script-targeted
  8727. * URLs—such as `javascript:...`.
  8728. */
  8729. scripturl : true,
  8730. /**
  8731. * This option suppresses warnings about using `[]` notation when it can be
  8732. * expressed in dot notation: `person['name']` vs. `person.name`.
  8733. *
  8734. * @deprecated JSHint is limiting its scope to issues of code correctness.
  8735. * If you would like to enforce rules relating to code style,
  8736. * check out [the JSCS
  8737. * project](https://github.com/jscs-dev/node-jscs).
  8738. */
  8739. sub : true,
  8740. /**
  8741. * This option suppresses warnings about "weird" constructions like
  8742. * `new function () { ... }` and `new Object;`. Such constructions are
  8743. * sometimes used to produce singletons in JavaScript:
  8744. *
  8745. * var singleton = new function() {
  8746. * var privateVar;
  8747. *
  8748. * this.publicMethod = function () {}
  8749. * this.publicMethod2 = function () {}
  8750. * };
  8751. */
  8752. supernew : true,
  8753. /**
  8754. * This option suppresses most of the warnings about possibly unsafe line
  8755. * breakings in your code. It doesn't suppress warnings about comma-first
  8756. * coding style. To suppress those you have to use `laxcomma` (see below).
  8757. *
  8758. * @deprecated JSHint is limiting its scope to issues of code correctness.
  8759. * If you would like to enforce rules relating to code style,
  8760. * check out [the JSCS
  8761. * project](https://github.com/jscs-dev/node-jscs).
  8762. */
  8763. laxbreak : true,
  8764. /**
  8765. * This option suppresses warnings about comma-first coding style:
  8766. *
  8767. * var obj = {
  8768. * name: 'Anton'
  8769. * , handle: 'valueof'
  8770. * , role: 'SW Engineer'
  8771. * };
  8772. *
  8773. * @deprecated JSHint is limiting its scope to issues of code correctness.
  8774. * If you would like to enforce rules relating to code style,
  8775. * check out [the JSCS
  8776. * project](https://github.com/jscs-dev/node-jscs).
  8777. */
  8778. laxcomma : true,
  8779. /**
  8780. * This option suppresses warnings about possible strict violations when
  8781. * the code is running in strict mode and you use `this` in a
  8782. * non-constructor function. You should use this option—in a function scope
  8783. * only—when you are positive that your use of `this` is valid in the
  8784. * strict mode (for example, if you call your function using
  8785. * `Function.call`).
  8786. *
  8787. * **Note:** This option can be used only inside of a function scope.
  8788. * JSHint will fail with an error if you will try to set this option
  8789. * globally.
  8790. */
  8791. validthis : true,
  8792. /**
  8793. * This option suppresses warnings about the use of the `with` statement.
  8794. * The semantics of the `with` statement can cause confusion among
  8795. * developers and accidental definition of global variables.
  8796. *
  8797. * More info:
  8798. *
  8799. * * [with Statement Considered
  8800. * Harmful](http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/)
  8801. */
  8802. withstmt : true,
  8803. /**
  8804. * This options tells JSHint that your code uses Mozilla JavaScript
  8805. * extensions. Unless you develop specifically for the Firefox web browser
  8806. * you don't need this option.
  8807. *
  8808. * More info:
  8809. *
  8810. * * [New in JavaScript
  8811. * 1.7](https://developer.mozilla.org/en-US/docs/JavaScript/New_in_JavaScript/1.7)
  8812. */
  8813. moz : true,
  8814. /**
  8815. * This option suppresses warnings about generator functions with no
  8816. * `yield` statement in them.
  8817. */
  8818. noyield : true,
  8819. /**
  8820. * This option suppresses warnings about `== null` comparisons. Such
  8821. * comparisons are often useful when you want to check if a variable is
  8822. * `null` or `undefined`.
  8823. */
  8824. eqnull : true,
  8825. /**
  8826. * This option suppresses warnings about missing semicolons, but only when
  8827. * the semicolon is omitted for the last statement in a one-line block:
  8828. *
  8829. * var name = (function() { return 'Anton' }());
  8830. *
  8831. * This is a very niche use case that is useful only when you use automatic
  8832. * JavaScript code generators.
  8833. */
  8834. lastsemic : true,
  8835. /**
  8836. * This option suppresses warnings about functions inside of loops.
  8837. * Defining functions inside of loops can lead to bugs such as this one:
  8838. *
  8839. * var nums = [];
  8840. *
  8841. * for (var i = 0; i < 10; i++) {
  8842. * nums[i] = function (j) {
  8843. * return i + j;
  8844. * };
  8845. * }
  8846. *
  8847. * nums[0](2); // Prints 12 instead of 2
  8848. *
  8849. * To fix the code above you need to copy the value of `i`:
  8850. *
  8851. * var nums = [];
  8852. *
  8853. * for (var i = 0; i < 10; i++) {
  8854. * (function (i) {
  8855. * nums[i] = function (j) {
  8856. * return i + j;
  8857. * };
  8858. * }(i));
  8859. * }
  8860. */
  8861. loopfunc : true,
  8862. /**
  8863. * This option suppresses warnings about the use of expressions where
  8864. * normally you would expect to see assignments or function calls. Most of
  8865. * the time, such code is a typo. However, it is not forbidden by the spec
  8866. * and that's why this warning is optional.
  8867. */
  8868. expr : true,
  8869. /**
  8870. * This option tells JSHint that your code uses ECMAScript 6 specific
  8871. * syntax. Note that these features are not finalized yet and not all
  8872. * browsers implement them.
  8873. *
  8874. * More info:
  8875. *
  8876. * * [Draft Specification for ES.next (ECMA-262 Ed.
  8877. * 6)](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts)
  8878. */
  8879. esnext : true,
  8880. /**
  8881. * This option tells JSHint that your code uses ES3 array elision elements,
  8882. * or empty elements (for example, `[1, , , 4, , , 7]`).
  8883. */
  8884. elision : true,
  8885. },
  8886. // Third party globals
  8887. environments: {
  8888. /**
  8889. * This option defines globals exposed by the
  8890. * [MooTools](http://mootools.net/) JavaScript framework.
  8891. */
  8892. mootools : true,
  8893. /**
  8894. * This option defines globals exposed by
  8895. * [CouchDB](http://couchdb.apache.org/). CouchDB is a document-oriented
  8896. * database that can be queried and indexed in a MapReduce fashion using
  8897. * JavaScript.
  8898. */
  8899. couch : true,
  8900. /**
  8901. * This option defines globals exposed by [the Jasmine unit testing
  8902. * framework](https://jasmine.github.io/).
  8903. */
  8904. jasmine : true,
  8905. /**
  8906. * This option defines globals exposed by the [jQuery](http://jquery.com/)
  8907. * JavaScript library.
  8908. */
  8909. jquery : true,
  8910. /**
  8911. * This option defines globals available when your code is running inside
  8912. * of the Node runtime environment. [Node.js](http://nodejs.org/) is a
  8913. * server-side JavaScript environment that uses an asynchronous
  8914. * event-driven model. This option also skips some warnings that make sense
  8915. * in the browser environments but don't make sense in Node such as
  8916. * file-level `use strict` pragmas and `console.log` statements.
  8917. */
  8918. node : true,
  8919. /**
  8920. * This option defines globals exposed by [the QUnit unit testing
  8921. * framework](http://qunitjs.com/).
  8922. */
  8923. qunit : true,
  8924. /**
  8925. * This option defines globals available when your code is running inside
  8926. * of the Rhino runtime environment. [Rhino](http://www.mozilla.org/rhino/)
  8927. * is an open-source implementation of JavaScript written entirely in Java.
  8928. */
  8929. rhino : true,
  8930. /**
  8931. * This option defines globals exposed by [the ShellJS
  8932. * library](http://documentup.com/arturadib/shelljs).
  8933. */
  8934. shelljs : true,
  8935. /**
  8936. * This option defines globals exposed by the
  8937. * [Prototype](http://www.prototypejs.org/) JavaScript framework.
  8938. */
  8939. prototypejs : true,
  8940. /**
  8941. * This option defines globals exposed by the [YUI](http://yuilibrary.com/)
  8942. * JavaScript framework.
  8943. */
  8944. yui : true,
  8945. /**
  8946. * This option defines globals exposed by the "BDD" and "TDD" UIs of the
  8947. * [Mocha unit testing framework](http://mochajs.org/).
  8948. */
  8949. mocha : true,
  8950. /**
  8951. * This option informs JSHint that the input code describes an ECMAScript 6
  8952. * module. All module code is interpreted as strict mode code.
  8953. */
  8954. module : true,
  8955. /**
  8956. * This option defines globals available when your code is running as a
  8957. * script for the [Windows Script
  8958. * Host](http://en.wikipedia.org/wiki/Windows_Script_Host).
  8959. */
  8960. wsh : true,
  8961. /**
  8962. * This option defines globals available when your code is running inside
  8963. * of a Web Worker. [Web
  8964. * Workers](https://developer.mozilla.org/en/Using_web_workers) provide a
  8965. * simple means for web content to run scripts in background threads.
  8966. */
  8967. worker : true,
  8968. /**
  8969. * This option defines non-standard but widely adopted globals such as
  8970. * `escape` and `unescape`.
  8971. */
  8972. nonstandard : true,
  8973. /**
  8974. * This option defines globals exposed by modern browsers: all the way from
  8975. * good old `document` and `navigator` to the HTML5 `FileReader` and other
  8976. * new developments in the browser world.
  8977. *
  8978. * **Note:** This option doesn't expose variables like `alert` or
  8979. * `console`. See option `devel` for more information.
  8980. */
  8981. browser : true,
  8982. /**
  8983. * This option defines globals available when using [the Browserify
  8984. * tool](http://browserify.org/) to build a project.
  8985. */
  8986. browserify : true,
  8987. /**
  8988. * This option defines globals that are usually used for logging poor-man's
  8989. * debugging: `console`, `alert`, etc. It is usually a good idea to not
  8990. * ship them in production because, for example, `console.log` breaks in
  8991. * legacy versions of Internet Explorer.
  8992. */
  8993. devel : true,
  8994. /**
  8995. * This option defines globals exposed by the [Dojo
  8996. * Toolkit](http://dojotoolkit.org/).
  8997. */
  8998. dojo : true,
  8999. /**
  9000. * This option defines globals for typed array constructors.
  9001. *
  9002. * More info:
  9003. *
  9004. * * [JavaScript typed
  9005. * arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays)
  9006. */
  9007. typed : true,
  9008. /**
  9009. * This option defines globals available when your core is running inside
  9010. * of the PhantomJS runtime environment. [PhantomJS](http://phantomjs.org/)
  9011. * is a headless WebKit scriptable with a JavaScript API. It has fast and
  9012. * native support for various web standards: DOM handling, CSS selector,
  9013. * JSON, Canvas, and SVG.
  9014. */
  9015. phantom : true
  9016. },
  9017. // Obsolete options
  9018. obsolete: {
  9019. onecase : true, // if one case switch statements should be allowed
  9020. regexp : true, // if the . should not be allowed in regexp literals
  9021. regexdash : true // if unescaped first/last dash (-) inside brackets
  9022. // should be tolerated
  9023. }
  9024. };
  9025. // These are the JSHint options that can take any value
  9026. // (we use this object to detect invalid options)
  9027. exports.val = {
  9028. /**
  9029. * This option lets you set the maximum length of a line.
  9030. *
  9031. * @deprecated JSHint is limiting its scope to issues of code correctness. If
  9032. * you would like to enforce rules relating to code style, check
  9033. * out [the JSCS project](https://github.com/jscs-dev/node-jscs).
  9034. */
  9035. maxlen : false,
  9036. /**
  9037. * This option sets a specific tab width for your code.
  9038. *
  9039. * @deprecated JSHint is limiting its scope to issues of code correctness. If
  9040. * you would like to enforce rules relating to code style, check
  9041. * out [the JSCS project](https://github.com/jscs-dev/node-jscs).
  9042. */
  9043. indent : false,
  9044. /**
  9045. * This options allows you to set the maximum amount of warnings JSHint will
  9046. * produce before giving up. Default is 50.
  9047. */
  9048. maxerr : false,
  9049. predef : false, // predef is deprecated and being replaced by globals
  9050. /**
  9051. * This option can be used to specify a white list of global variables that
  9052. * are not formally defined in the source code. This is most useful when
  9053. * combined with the `undef` option in order to suppress warnings for
  9054. * project-specific global variables.
  9055. *
  9056. * Setting an entry to `true` enables reading and writing to that variable.
  9057. * Setting it to `false` will trigger JSHint to consider that variable
  9058. * read-only.
  9059. *
  9060. * See also the "environment" options: a set of options to be used as short
  9061. * hand for enabling global variables defined in common JavaScript
  9062. * environments.
  9063. */
  9064. globals : false,
  9065. /**
  9066. * This option enforces the consistency of quotation marks used throughout
  9067. * your code. It accepts three values: `true` if you don't want to enforce
  9068. * one particular style but want some consistency, `"single"` if you want to
  9069. * allow only single quotes and `"double"` if you want to allow only double
  9070. * quotes.
  9071. *
  9072. * @deprecated JSHint is limiting its scope to issues of code correctness. If
  9073. * you would like to enforce rules relating to code style, check
  9074. * out [the JSCS project](https://github.com/jscs-dev/node-jscs).
  9075. */
  9076. quotmark : false,
  9077. scope : false,
  9078. /**
  9079. * This option lets you set the max number of statements allowed per function:
  9080. *
  9081. * // jshint maxstatements:4
  9082. *
  9083. * function main() {
  9084. * var i = 0;
  9085. * var j = 0;
  9086. *
  9087. * // Function declarations count as one statement. Their bodies
  9088. * // don't get taken into account for the outer function.
  9089. * function inner() {
  9090. * var i2 = 1;
  9091. * var j2 = 1;
  9092. *
  9093. * return i2 + j2;
  9094. * }
  9095. *
  9096. * j = i + j;
  9097. * return j; // JSHint: Too many statements per function. (5)
  9098. * }
  9099. */
  9100. maxstatements: false,
  9101. /**
  9102. * This option lets you control how nested do you want your blocks to be:
  9103. *
  9104. * // jshint maxdepth:2
  9105. *
  9106. * function main(meaning) {
  9107. * var day = true;
  9108. *
  9109. * if (meaning === 42) {
  9110. * while (day) {
  9111. * shuffle();
  9112. *
  9113. * if (tired) { // JSHint: Blocks are nested too deeply (3).
  9114. * sleep();
  9115. * }
  9116. * }
  9117. * }
  9118. * }
  9119. */
  9120. maxdepth : false,
  9121. /**
  9122. * This option lets you set the max number of formal parameters allowed per
  9123. * function:
  9124. *
  9125. * // jshint maxparams:3
  9126. *
  9127. * function login(request, onSuccess) {
  9128. * // ...
  9129. * }
  9130. *
  9131. * // JSHint: Too many parameters per function (4).
  9132. * function logout(request, isManual, whereAmI, onSuccess) {
  9133. * // ...
  9134. * }
  9135. */
  9136. maxparams : false,
  9137. /**
  9138. * This option lets you control cyclomatic complexity throughout your code.
  9139. * Cyclomatic complexity measures the number of linearly independent paths
  9140. * through a program's source code. Read more about [cyclomatic complexity on
  9141. * Wikipedia](http://en.wikipedia.org/wiki/Cyclomatic_complexity).
  9142. */
  9143. maxcomplexity: false,
  9144. /**
  9145. * This option suppresses warnings about variable shadowing i.e. declaring a
  9146. * variable that had been already declared somewhere in the outer scope.
  9147. *
  9148. * - "inner" - check for variables defined in the same scope only
  9149. * - "outer" - check for variables defined in outer scopes as well
  9150. * - false - same as inner
  9151. * - true - allow variable shadowing
  9152. */
  9153. shadow : false,
  9154. /**
  9155. * This option warns when you define and never use your variables. It is very
  9156. * useful for general code cleanup, especially when used in addition to
  9157. * `undef`.
  9158. *
  9159. * // jshint unused:true
  9160. *
  9161. * function test(a, b) {
  9162. * var c, d = 2;
  9163. *
  9164. * return a + d;
  9165. * }
  9166. *
  9167. * test(1, 2);
  9168. *
  9169. * // Line 3: 'b' was defined but never used.
  9170. * // Line 4: 'c' was defined but never used.
  9171. *
  9172. * In addition to that, this option will warn you about unused global
  9173. * variables declared via the `global` directive.
  9174. *
  9175. * This can be set to `vars` to only check for variables, not function
  9176. * parameters, or `strict` to check all variables and parameters. The
  9177. * default (true) behavior is to allow unused parameters that are followed by
  9178. * a used parameter.
  9179. */
  9180. unused : true,
  9181. /**
  9182. * This option prohibits the use of a variable before it was defined.
  9183. * JavaScript has function scope only and, in addition to that, all variables
  9184. * are always moved—or hoisted— to the top of the function. This behavior can
  9185. * lead to some very nasty bugs and that's why it is safer to always use
  9186. * variable only after they have been explicitly defined.
  9187. *
  9188. * Setting this option to "nofunc" will allow function declarations to be
  9189. * ignored.
  9190. *
  9191. * For more in-depth understanding of scoping and hoisting in JavaScript,
  9192. * read [JavaScript Scoping and
  9193. * Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting)
  9194. * by Ben Cherry.
  9195. */
  9196. latedef : false,
  9197. ignore : false, // start/end ignoring lines of code, bypassing the lexer
  9198. // start - start ignoring lines, including the current line
  9199. // end - stop ignoring lines, starting on the next line
  9200. // line - ignore warnings / errors for just a single line
  9201. // (this option does not bypass the lexer)
  9202. ignoreDelimiters: false // array of start/end delimiters used to ignore
  9203. // certain chunks from code
  9204. };
  9205. // These are JSHint boolean options which are shared with JSLint
  9206. // where the definition in JSHint is opposite JSLint
  9207. exports.inverted = {
  9208. bitwise : true,
  9209. forin : true,
  9210. newcap : true,
  9211. plusplus: true,
  9212. regexp : true,
  9213. undef : true,
  9214. // Inverted and renamed, use JSHint name here
  9215. eqeqeq : true,
  9216. strict : true
  9217. };
  9218. exports.validNames = Object.keys(exports.val)
  9219. .concat(Object.keys(exports.bool.relaxing))
  9220. .concat(Object.keys(exports.bool.enforcing))
  9221. .concat(Object.keys(exports.bool.obsolete))
  9222. .concat(Object.keys(exports.bool.environments));
  9223. // These are JSHint boolean options which are shared with JSLint
  9224. // where the name has been changed but the effect is unchanged
  9225. exports.renamed = {
  9226. eqeq : "eqeqeq",
  9227. windows: "wsh",
  9228. sloppy : "strict"
  9229. };
  9230. exports.removed = {
  9231. nomen: true,
  9232. onevar: true,
  9233. passfail: true,
  9234. white: true,
  9235. gcl: true,
  9236. smarttabs: true,
  9237. trailing: true
  9238. };
  9239. // Add options here which should not be automatically enforced by
  9240. // `enforceall`.
  9241. exports.noenforceall = {
  9242. varstmt: true,
  9243. strict: true
  9244. };
  9245. },{}],"/node_modules/jshint/src/reg.js":[function(_dereq_,module,exports){
  9246. /*
  9247. * Regular expressions. Some of these are stupidly long.
  9248. */
  9249. /*jshint maxlen:1000 */
  9250. "use strict";
  9251. // Unsafe comment or string (ax)
  9252. exports.unsafeString =
  9253. /@cc|<\/?|script|\]\s*\]|<\s*!|&lt/i;
  9254. // Unsafe characters that are silently deleted by one or more browsers (cx)
  9255. exports.unsafeChars =
  9256. /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
  9257. // Characters in strings that need escaping (nx and nxg)
  9258. exports.needEsc =
  9259. /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
  9260. exports.needEscGlobal =
  9261. /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  9262. // Star slash (lx)
  9263. exports.starSlash = /\*\//;
  9264. // Identifier (ix)
  9265. exports.identifier = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/;
  9266. // JavaScript URL (jx)
  9267. exports.javascriptURL = /^(?:javascript|jscript|ecmascript|vbscript|livescript)\s*:/i;
  9268. // Catches /* falls through */ comments (ft)
  9269. exports.fallsThrough = /^\s*\/\*\s*falls?\sthrough\s*\*\/\s*$/;
  9270. // very conservative rule (eg: only one space between the start of the comment and the first character)
  9271. // to relax the maxlen option
  9272. exports.maxlenException = /^(?:(?:\/\/|\/\*|\*) ?)?[^ ]+$/;
  9273. },{}],"/node_modules/jshint/src/state.js":[function(_dereq_,module,exports){
  9274. "use strict";
  9275. var NameStack = _dereq_("./name-stack.js");
  9276. var state = {
  9277. syntax: {},
  9278. /**
  9279. * Determine if the code currently being linted is strict mode code.
  9280. *
  9281. * @returns {boolean}
  9282. */
  9283. isStrict: function() {
  9284. return this.directive["use strict"] || this.inClassBody ||
  9285. this.option.module;
  9286. },
  9287. // Assumption: chronologically ES3 < ES5 < ES6/ESNext < Moz
  9288. inMoz: function() {
  9289. return this.option.moz;
  9290. },
  9291. /**
  9292. * @param {object} options
  9293. * @param {boolean} options.strict - When `true`, only consider ESNext when
  9294. * in "esnext" code and *not* in "moz".
  9295. */
  9296. inESNext: function() {
  9297. return this.option.moz || this.option.esnext;
  9298. },
  9299. inES5: function() {
  9300. return !this.option.es3;
  9301. },
  9302. inES3: function() {
  9303. return this.option.es3;
  9304. },
  9305. reset: function() {
  9306. this.tokens = {
  9307. prev: null,
  9308. next: null,
  9309. curr: null
  9310. };
  9311. this.option = {};
  9312. this.funct = null;
  9313. this.ignored = {};
  9314. this.directive = {};
  9315. this.jsonMode = false;
  9316. this.jsonWarnings = [];
  9317. this.lines = [];
  9318. this.tab = "";
  9319. this.cache = {}; // Node.JS doesn't have Map. Sniff.
  9320. this.ignoredLines = {};
  9321. this.forinifcheckneeded = false;
  9322. this.nameStack = new NameStack();
  9323. this.inClassBody = false;
  9324. // Blank out non-multi-line-commented lines when ignoring linter errors
  9325. this.ignoreLinterErrors = false;
  9326. }
  9327. };
  9328. exports.state = state;
  9329. },{"./name-stack.js":"/node_modules/jshint/src/name-stack.js"}],"/node_modules/jshint/src/style.js":[function(_dereq_,module,exports){
  9330. "use strict";
  9331. exports.register = function(linter) {
  9332. // Check for properties named __proto__. This special property was
  9333. // deprecated and then re-introduced for ES6.
  9334. linter.on("Identifier", function style_scanProto(data) {
  9335. if (linter.getOption("proto")) {
  9336. return;
  9337. }
  9338. if (data.name === "__proto__") {
  9339. linter.warn("W103", {
  9340. line: data.line,
  9341. char: data.char,
  9342. data: [ data.name ]
  9343. });
  9344. }
  9345. });
  9346. // Check for properties named __iterator__. This is a special property
  9347. // available only in browsers with JavaScript 1.7 implementation.
  9348. linter.on("Identifier", function style_scanIterator(data) {
  9349. if (linter.getOption("iterator")) {
  9350. return;
  9351. }
  9352. if (data.name === "__iterator__") {
  9353. linter.warn("W104", {
  9354. line: data.line,
  9355. char: data.char,
  9356. data: [ data.name ]
  9357. });
  9358. }
  9359. });
  9360. // Check that all identifiers are using camelCase notation.
  9361. // Exceptions: names like MY_VAR and _myVar.
  9362. linter.on("Identifier", function style_scanCamelCase(data) {
  9363. if (!linter.getOption("camelcase")) {
  9364. return;
  9365. }
  9366. if (data.name.replace(/^_+|_+$/g, "").indexOf("_") > -1 && !data.name.match(/^[A-Z0-9_]*$/)) {
  9367. linter.warn("W106", {
  9368. line: data.line,
  9369. char: data.from,
  9370. data: [ data.name ]
  9371. });
  9372. }
  9373. });
  9374. // Enforce consistency in style of quoting.
  9375. linter.on("String", function style_scanQuotes(data) {
  9376. var quotmark = linter.getOption("quotmark");
  9377. var code;
  9378. if (!quotmark) {
  9379. return;
  9380. }
  9381. // If quotmark is set to 'single' warn about all double-quotes.
  9382. if (quotmark === "single" && data.quote !== "'") {
  9383. code = "W109";
  9384. }
  9385. // If quotmark is set to 'double' warn about all single-quotes.
  9386. if (quotmark === "double" && data.quote !== "\"") {
  9387. code = "W108";
  9388. }
  9389. // If quotmark is set to true, remember the first quotation style
  9390. // and then warn about all others.
  9391. if (quotmark === true) {
  9392. if (!linter.getCache("quotmark")) {
  9393. linter.setCache("quotmark", data.quote);
  9394. }
  9395. if (linter.getCache("quotmark") !== data.quote) {
  9396. code = "W110";
  9397. }
  9398. }
  9399. if (code) {
  9400. linter.warn(code, {
  9401. line: data.line,
  9402. char: data.char,
  9403. });
  9404. }
  9405. });
  9406. linter.on("Number", function style_scanNumbers(data) {
  9407. if (data.value.charAt(0) === ".") {
  9408. // Warn about a leading decimal point.
  9409. linter.warn("W008", {
  9410. line: data.line,
  9411. char: data.char,
  9412. data: [ data.value ]
  9413. });
  9414. }
  9415. if (data.value.substr(data.value.length - 1) === ".") {
  9416. // Warn about a trailing decimal point.
  9417. linter.warn("W047", {
  9418. line: data.line,
  9419. char: data.char,
  9420. data: [ data.value ]
  9421. });
  9422. }
  9423. if (/^00+/.test(data.value)) {
  9424. // Multiple leading zeroes.
  9425. linter.warn("W046", {
  9426. line: data.line,
  9427. char: data.char,
  9428. data: [ data.value ]
  9429. });
  9430. }
  9431. });
  9432. // Warn about script URLs.
  9433. linter.on("String", function style_scanJavaScriptURLs(data) {
  9434. var re = /^(?:javascript|jscript|ecmascript|vbscript|livescript)\s*:/i;
  9435. if (linter.getOption("scripturl")) {
  9436. return;
  9437. }
  9438. if (re.test(data.value)) {
  9439. linter.warn("W107", {
  9440. line: data.line,
  9441. char: data.char
  9442. });
  9443. }
  9444. });
  9445. };
  9446. },{}],"/node_modules/jshint/src/vars.js":[function(_dereq_,module,exports){
  9447. // jshint -W001
  9448. "use strict";
  9449. // Identifiers provided by the ECMAScript standard.
  9450. exports.reservedVars = {
  9451. arguments : false,
  9452. NaN : false
  9453. };
  9454. exports.ecmaIdentifiers = {
  9455. 3: {
  9456. Array : false,
  9457. Boolean : false,
  9458. Date : false,
  9459. decodeURI : false,
  9460. decodeURIComponent : false,
  9461. encodeURI : false,
  9462. encodeURIComponent : false,
  9463. Error : false,
  9464. "eval" : false,
  9465. EvalError : false,
  9466. Function : false,
  9467. hasOwnProperty : false,
  9468. isFinite : false,
  9469. isNaN : false,
  9470. Math : false,
  9471. Number : false,
  9472. Object : false,
  9473. parseInt : false,
  9474. parseFloat : false,
  9475. RangeError : false,
  9476. ReferenceError : false,
  9477. RegExp : false,
  9478. String : false,
  9479. SyntaxError : false,
  9480. TypeError : false,
  9481. URIError : false
  9482. },
  9483. 5: {
  9484. JSON : false
  9485. },
  9486. 6: {
  9487. Map : false,
  9488. Promise : false,
  9489. Proxy : false,
  9490. Reflect : false,
  9491. Set : false,
  9492. Symbol : false,
  9493. WeakMap : false,
  9494. WeakSet : false
  9495. }
  9496. };
  9497. // Global variables commonly provided by a web browser environment.
  9498. exports.browser = {
  9499. Audio : false,
  9500. Blob : false,
  9501. addEventListener : false,
  9502. applicationCache : false,
  9503. atob : false,
  9504. blur : false,
  9505. btoa : false,
  9506. cancelAnimationFrame : false,
  9507. CanvasGradient : false,
  9508. CanvasPattern : false,
  9509. CanvasRenderingContext2D: false,
  9510. CSS : false,
  9511. clearInterval : false,
  9512. clearTimeout : false,
  9513. close : false,
  9514. closed : false,
  9515. Comment : false,
  9516. CustomEvent : false,
  9517. DOMParser : false,
  9518. defaultStatus : false,
  9519. Document : false,
  9520. document : false,
  9521. DocumentFragment : false,
  9522. Element : false,
  9523. ElementTimeControl : false,
  9524. Event : false,
  9525. event : false,
  9526. fetch : false,
  9527. FileReader : false,
  9528. FormData : false,
  9529. focus : false,
  9530. frames : false,
  9531. getComputedStyle : false,
  9532. HTMLElement : false,
  9533. HTMLAnchorElement : false,
  9534. HTMLBaseElement : false,
  9535. HTMLBlockquoteElement: false,
  9536. HTMLBodyElement : false,
  9537. HTMLBRElement : false,
  9538. HTMLButtonElement : false,
  9539. HTMLCanvasElement : false,
  9540. HTMLCollection : false,
  9541. HTMLDirectoryElement : false,
  9542. HTMLDivElement : false,
  9543. HTMLDListElement : false,
  9544. HTMLFieldSetElement : false,
  9545. HTMLFontElement : false,
  9546. HTMLFormElement : false,
  9547. HTMLFrameElement : false,
  9548. HTMLFrameSetElement : false,
  9549. HTMLHeadElement : false,
  9550. HTMLHeadingElement : false,
  9551. HTMLHRElement : false,
  9552. HTMLHtmlElement : false,
  9553. HTMLIFrameElement : false,
  9554. HTMLImageElement : false,
  9555. HTMLInputElement : false,
  9556. HTMLIsIndexElement : false,
  9557. HTMLLabelElement : false,
  9558. HTMLLayerElement : false,
  9559. HTMLLegendElement : false,
  9560. HTMLLIElement : false,
  9561. HTMLLinkElement : false,
  9562. HTMLMapElement : false,
  9563. HTMLMenuElement : false,
  9564. HTMLMetaElement : false,
  9565. HTMLModElement : false,
  9566. HTMLObjectElement : false,
  9567. HTMLOListElement : false,
  9568. HTMLOptGroupElement : false,
  9569. HTMLOptionElement : false,
  9570. HTMLParagraphElement : false,
  9571. HTMLParamElement : false,
  9572. HTMLPreElement : false,
  9573. HTMLQuoteElement : false,
  9574. HTMLScriptElement : false,
  9575. HTMLSelectElement : false,
  9576. HTMLStyleElement : false,
  9577. HTMLTableCaptionElement: false,
  9578. HTMLTableCellElement : false,
  9579. HTMLTableColElement : false,
  9580. HTMLTableElement : false,
  9581. HTMLTableRowElement : false,
  9582. HTMLTableSectionElement: false,
  9583. HTMLTemplateElement : false,
  9584. HTMLTextAreaElement : false,
  9585. HTMLTitleElement : false,
  9586. HTMLUListElement : false,
  9587. HTMLVideoElement : false,
  9588. history : false,
  9589. Image : false,
  9590. Intl : false,
  9591. length : false,
  9592. localStorage : false,
  9593. location : false,
  9594. matchMedia : false,
  9595. MessageChannel : false,
  9596. MessageEvent : false,
  9597. MessagePort : false,
  9598. MouseEvent : false,
  9599. moveBy : false,
  9600. moveTo : false,
  9601. MutationObserver : false,
  9602. name : false,
  9603. Node : false,
  9604. NodeFilter : false,
  9605. NodeList : false,
  9606. Notification : false,
  9607. navigator : false,
  9608. onbeforeunload : true,
  9609. onblur : true,
  9610. onerror : true,
  9611. onfocus : true,
  9612. onload : true,
  9613. onresize : true,
  9614. onunload : true,
  9615. open : false,
  9616. openDatabase : false,
  9617. opener : false,
  9618. Option : false,
  9619. parent : false,
  9620. performance : false,
  9621. print : false,
  9622. Range : false,
  9623. requestAnimationFrame : false,
  9624. removeEventListener : false,
  9625. resizeBy : false,
  9626. resizeTo : false,
  9627. screen : false,
  9628. scroll : false,
  9629. scrollBy : false,
  9630. scrollTo : false,
  9631. sessionStorage : false,
  9632. setInterval : false,
  9633. setTimeout : false,
  9634. SharedWorker : false,
  9635. status : false,
  9636. SVGAElement : false,
  9637. SVGAltGlyphDefElement: false,
  9638. SVGAltGlyphElement : false,
  9639. SVGAltGlyphItemElement: false,
  9640. SVGAngle : false,
  9641. SVGAnimateColorElement: false,
  9642. SVGAnimateElement : false,
  9643. SVGAnimateMotionElement: false,
  9644. SVGAnimateTransformElement: false,
  9645. SVGAnimatedAngle : false,
  9646. SVGAnimatedBoolean : false,
  9647. SVGAnimatedEnumeration: false,
  9648. SVGAnimatedInteger : false,
  9649. SVGAnimatedLength : false,
  9650. SVGAnimatedLengthList: false,
  9651. SVGAnimatedNumber : false,
  9652. SVGAnimatedNumberList: false,
  9653. SVGAnimatedPathData : false,
  9654. SVGAnimatedPoints : false,
  9655. SVGAnimatedPreserveAspectRatio: false,
  9656. SVGAnimatedRect : false,
  9657. SVGAnimatedString : false,
  9658. SVGAnimatedTransformList: false,
  9659. SVGAnimationElement : false,
  9660. SVGCSSRule : false,
  9661. SVGCircleElement : false,
  9662. SVGClipPathElement : false,
  9663. SVGColor : false,
  9664. SVGColorProfileElement: false,
  9665. SVGColorProfileRule : false,
  9666. SVGComponentTransferFunctionElement: false,
  9667. SVGCursorElement : false,
  9668. SVGDefsElement : false,
  9669. SVGDescElement : false,
  9670. SVGDocument : false,
  9671. SVGElement : false,
  9672. SVGElementInstance : false,
  9673. SVGElementInstanceList: false,
  9674. SVGEllipseElement : false,
  9675. SVGExternalResourcesRequired: false,
  9676. SVGFEBlendElement : false,
  9677. SVGFEColorMatrixElement: false,
  9678. SVGFEComponentTransferElement: false,
  9679. SVGFECompositeElement: false,
  9680. SVGFEConvolveMatrixElement: false,
  9681. SVGFEDiffuseLightingElement: false,
  9682. SVGFEDisplacementMapElement: false,
  9683. SVGFEDistantLightElement: false,
  9684. SVGFEFloodElement : false,
  9685. SVGFEFuncAElement : false,
  9686. SVGFEFuncBElement : false,
  9687. SVGFEFuncGElement : false,
  9688. SVGFEFuncRElement : false,
  9689. SVGFEGaussianBlurElement: false,
  9690. SVGFEImageElement : false,
  9691. SVGFEMergeElement : false,
  9692. SVGFEMergeNodeElement: false,
  9693. SVGFEMorphologyElement: false,
  9694. SVGFEOffsetElement : false,
  9695. SVGFEPointLightElement: false,
  9696. SVGFESpecularLightingElement: false,
  9697. SVGFESpotLightElement: false,
  9698. SVGFETileElement : false,
  9699. SVGFETurbulenceElement: false,
  9700. SVGFilterElement : false,
  9701. SVGFilterPrimitiveStandardAttributes: false,
  9702. SVGFitToViewBox : false,
  9703. SVGFontElement : false,
  9704. SVGFontFaceElement : false,
  9705. SVGFontFaceFormatElement: false,
  9706. SVGFontFaceNameElement: false,
  9707. SVGFontFaceSrcElement: false,
  9708. SVGFontFaceUriElement: false,
  9709. SVGForeignObjectElement: false,
  9710. SVGGElement : false,
  9711. SVGGlyphElement : false,
  9712. SVGGlyphRefElement : false,
  9713. SVGGradientElement : false,
  9714. SVGHKernElement : false,
  9715. SVGICCColor : false,
  9716. SVGImageElement : false,
  9717. SVGLangSpace : false,
  9718. SVGLength : false,
  9719. SVGLengthList : false,
  9720. SVGLineElement : false,
  9721. SVGLinearGradientElement: false,
  9722. SVGLocatable : false,
  9723. SVGMPathElement : false,
  9724. SVGMarkerElement : false,
  9725. SVGMaskElement : false,
  9726. SVGMatrix : false,
  9727. SVGMetadataElement : false,
  9728. SVGMissingGlyphElement: false,
  9729. SVGNumber : false,
  9730. SVGNumberList : false,
  9731. SVGPaint : false,
  9732. SVGPathElement : false,
  9733. SVGPathSeg : false,
  9734. SVGPathSegArcAbs : false,
  9735. SVGPathSegArcRel : false,
  9736. SVGPathSegClosePath : false,
  9737. SVGPathSegCurvetoCubicAbs: false,
  9738. SVGPathSegCurvetoCubicRel: false,
  9739. SVGPathSegCurvetoCubicSmoothAbs: false,
  9740. SVGPathSegCurvetoCubicSmoothRel: false,
  9741. SVGPathSegCurvetoQuadraticAbs: false,
  9742. SVGPathSegCurvetoQuadraticRel: false,
  9743. SVGPathSegCurvetoQuadraticSmoothAbs: false,
  9744. SVGPathSegCurvetoQuadraticSmoothRel: false,
  9745. SVGPathSegLinetoAbs : false,
  9746. SVGPathSegLinetoHorizontalAbs: false,
  9747. SVGPathSegLinetoHorizontalRel: false,
  9748. SVGPathSegLinetoRel : false,
  9749. SVGPathSegLinetoVerticalAbs: false,
  9750. SVGPathSegLinetoVerticalRel: false,
  9751. SVGPathSegList : false,
  9752. SVGPathSegMovetoAbs : false,
  9753. SVGPathSegMovetoRel : false,
  9754. SVGPatternElement : false,
  9755. SVGPoint : false,
  9756. SVGPointList : false,
  9757. SVGPolygonElement : false,
  9758. SVGPolylineElement : false,
  9759. SVGPreserveAspectRatio: false,
  9760. SVGRadialGradientElement: false,
  9761. SVGRect : false,
  9762. SVGRectElement : false,
  9763. SVGRenderingIntent : false,
  9764. SVGSVGElement : false,
  9765. SVGScriptElement : false,
  9766. SVGSetElement : false,
  9767. SVGStopElement : false,
  9768. SVGStringList : false,
  9769. SVGStylable : false,
  9770. SVGStyleElement : false,
  9771. SVGSwitchElement : false,
  9772. SVGSymbolElement : false,
  9773. SVGTRefElement : false,
  9774. SVGTSpanElement : false,
  9775. SVGTests : false,
  9776. SVGTextContentElement: false,
  9777. SVGTextElement : false,
  9778. SVGTextPathElement : false,
  9779. SVGTextPositioningElement: false,
  9780. SVGTitleElement : false,
  9781. SVGTransform : false,
  9782. SVGTransformList : false,
  9783. SVGTransformable : false,
  9784. SVGURIReference : false,
  9785. SVGUnitTypes : false,
  9786. SVGUseElement : false,
  9787. SVGVKernElement : false,
  9788. SVGViewElement : false,
  9789. SVGViewSpec : false,
  9790. SVGZoomAndPan : false,
  9791. Text : false,
  9792. TextDecoder : false,
  9793. TextEncoder : false,
  9794. TimeEvent : false,
  9795. top : false,
  9796. URL : false,
  9797. WebGLActiveInfo : false,
  9798. WebGLBuffer : false,
  9799. WebGLContextEvent : false,
  9800. WebGLFramebuffer : false,
  9801. WebGLProgram : false,
  9802. WebGLRenderbuffer : false,
  9803. WebGLRenderingContext: false,
  9804. WebGLShader : false,
  9805. WebGLShaderPrecisionFormat: false,
  9806. WebGLTexture : false,
  9807. WebGLUniformLocation : false,
  9808. WebSocket : false,
  9809. window : false,
  9810. Worker : false,
  9811. XDomainRequest : false,
  9812. XMLHttpRequest : false,
  9813. XMLSerializer : false,
  9814. XPathEvaluator : false,
  9815. XPathException : false,
  9816. XPathExpression : false,
  9817. XPathNamespace : false,
  9818. XPathNSResolver : false,
  9819. XPathResult : false
  9820. };
  9821. exports.devel = {
  9822. alert : false,
  9823. confirm: false,
  9824. console: false,
  9825. Debug : false,
  9826. opera : false,
  9827. prompt : false
  9828. };
  9829. exports.worker = {
  9830. importScripts : true,
  9831. postMessage : true,
  9832. self : true,
  9833. FileReaderSync : true
  9834. };
  9835. // Widely adopted global names that are not part of ECMAScript standard
  9836. exports.nonstandard = {
  9837. escape : false,
  9838. unescape: false
  9839. };
  9840. // Globals provided by popular JavaScript environments.
  9841. exports.couch = {
  9842. "require" : false,
  9843. respond : false,
  9844. getRow : false,
  9845. emit : false,
  9846. send : false,
  9847. start : false,
  9848. sum : false,
  9849. log : false,
  9850. exports : false,
  9851. module : false,
  9852. provides : false
  9853. };
  9854. exports.node = {
  9855. __filename : false,
  9856. __dirname : false,
  9857. GLOBAL : false,
  9858. global : false,
  9859. module : false,
  9860. require : false,
  9861. // These globals are writeable because Node allows the following
  9862. // usage pattern: var Buffer = require("buffer").Buffer;
  9863. Buffer : true,
  9864. console : true,
  9865. exports : true,
  9866. process : true,
  9867. setTimeout : true,
  9868. clearTimeout : true,
  9869. setInterval : true,
  9870. clearInterval : true,
  9871. setImmediate : true, // v0.9.1+
  9872. clearImmediate: true // v0.9.1+
  9873. };
  9874. exports.browserify = {
  9875. __filename : false,
  9876. __dirname : false,
  9877. global : false,
  9878. module : false,
  9879. require : false,
  9880. Buffer : true,
  9881. exports : true,
  9882. process : true
  9883. };
  9884. exports.phantom = {
  9885. phantom : true,
  9886. require : true,
  9887. WebPage : true,
  9888. console : true, // in examples, but undocumented
  9889. exports : true // v1.7+
  9890. };
  9891. exports.qunit = {
  9892. asyncTest : false,
  9893. deepEqual : false,
  9894. equal : false,
  9895. expect : false,
  9896. module : false,
  9897. notDeepEqual : false,
  9898. notEqual : false,
  9899. notPropEqual : false,
  9900. notStrictEqual : false,
  9901. ok : false,
  9902. propEqual : false,
  9903. QUnit : false,
  9904. raises : false,
  9905. start : false,
  9906. stop : false,
  9907. strictEqual : false,
  9908. test : false,
  9909. "throws" : false
  9910. };
  9911. exports.rhino = {
  9912. defineClass : false,
  9913. deserialize : false,
  9914. gc : false,
  9915. help : false,
  9916. importClass : false,
  9917. importPackage: false,
  9918. "java" : false,
  9919. load : false,
  9920. loadClass : false,
  9921. Packages : false,
  9922. print : false,
  9923. quit : false,
  9924. readFile : false,
  9925. readUrl : false,
  9926. runCommand : false,
  9927. seal : false,
  9928. serialize : false,
  9929. spawn : false,
  9930. sync : false,
  9931. toint32 : false,
  9932. version : false
  9933. };
  9934. exports.shelljs = {
  9935. target : false,
  9936. echo : false,
  9937. exit : false,
  9938. cd : false,
  9939. pwd : false,
  9940. ls : false,
  9941. find : false,
  9942. cp : false,
  9943. rm : false,
  9944. mv : false,
  9945. mkdir : false,
  9946. test : false,
  9947. cat : false,
  9948. sed : false,
  9949. grep : false,
  9950. which : false,
  9951. dirs : false,
  9952. pushd : false,
  9953. popd : false,
  9954. env : false,
  9955. exec : false,
  9956. chmod : false,
  9957. config : false,
  9958. error : false,
  9959. tempdir : false
  9960. };
  9961. exports.typed = {
  9962. ArrayBuffer : false,
  9963. ArrayBufferView : false,
  9964. DataView : false,
  9965. Float32Array : false,
  9966. Float64Array : false,
  9967. Int16Array : false,
  9968. Int32Array : false,
  9969. Int8Array : false,
  9970. Uint16Array : false,
  9971. Uint32Array : false,
  9972. Uint8Array : false,
  9973. Uint8ClampedArray : false
  9974. };
  9975. exports.wsh = {
  9976. ActiveXObject : true,
  9977. Enumerator : true,
  9978. GetObject : true,
  9979. ScriptEngine : true,
  9980. ScriptEngineBuildVersion : true,
  9981. ScriptEngineMajorVersion : true,
  9982. ScriptEngineMinorVersion : true,
  9983. VBArray : true,
  9984. WSH : true,
  9985. WScript : true,
  9986. XDomainRequest : true
  9987. };
  9988. // Globals provided by popular JavaScript libraries.
  9989. exports.dojo = {
  9990. dojo : false,
  9991. dijit : false,
  9992. dojox : false,
  9993. define : false,
  9994. "require": false
  9995. };
  9996. exports.jquery = {
  9997. "$" : false,
  9998. jQuery : false
  9999. };
  10000. exports.mootools = {
  10001. "$" : false,
  10002. "$$" : false,
  10003. Asset : false,
  10004. Browser : false,
  10005. Chain : false,
  10006. Class : false,
  10007. Color : false,
  10008. Cookie : false,
  10009. Core : false,
  10010. Document : false,
  10011. DomReady : false,
  10012. DOMEvent : false,
  10013. DOMReady : false,
  10014. Drag : false,
  10015. Element : false,
  10016. Elements : false,
  10017. Event : false,
  10018. Events : false,
  10019. Fx : false,
  10020. Group : false,
  10021. Hash : false,
  10022. HtmlTable : false,
  10023. IFrame : false,
  10024. IframeShim : false,
  10025. InputValidator: false,
  10026. instanceOf : false,
  10027. Keyboard : false,
  10028. Locale : false,
  10029. Mask : false,
  10030. MooTools : false,
  10031. Native : false,
  10032. Options : false,
  10033. OverText : false,
  10034. Request : false,
  10035. Scroller : false,
  10036. Slick : false,
  10037. Slider : false,
  10038. Sortables : false,
  10039. Spinner : false,
  10040. Swiff : false,
  10041. Tips : false,
  10042. Type : false,
  10043. typeOf : false,
  10044. URI : false,
  10045. Window : false
  10046. };
  10047. exports.prototypejs = {
  10048. "$" : false,
  10049. "$$" : false,
  10050. "$A" : false,
  10051. "$F" : false,
  10052. "$H" : false,
  10053. "$R" : false,
  10054. "$break" : false,
  10055. "$continue" : false,
  10056. "$w" : false,
  10057. Abstract : false,
  10058. Ajax : false,
  10059. Class : false,
  10060. Enumerable : false,
  10061. Element : false,
  10062. Event : false,
  10063. Field : false,
  10064. Form : false,
  10065. Hash : false,
  10066. Insertion : false,
  10067. ObjectRange : false,
  10068. PeriodicalExecuter: false,
  10069. Position : false,
  10070. Prototype : false,
  10071. Selector : false,
  10072. Template : false,
  10073. Toggle : false,
  10074. Try : false,
  10075. Autocompleter : false,
  10076. Builder : false,
  10077. Control : false,
  10078. Draggable : false,
  10079. Draggables : false,
  10080. Droppables : false,
  10081. Effect : false,
  10082. Sortable : false,
  10083. SortableObserver : false,
  10084. Sound : false,
  10085. Scriptaculous : false
  10086. };
  10087. exports.yui = {
  10088. YUI : false,
  10089. Y : false,
  10090. YUI_config: false
  10091. };
  10092. exports.mocha = {
  10093. // Global (for config etc.)
  10094. mocha : false,
  10095. // BDD
  10096. describe : false,
  10097. xdescribe : false,
  10098. it : false,
  10099. xit : false,
  10100. context : false,
  10101. xcontext : false,
  10102. before : false,
  10103. after : false,
  10104. beforeEach : false,
  10105. afterEach : false,
  10106. // TDD
  10107. suite : false,
  10108. test : false,
  10109. setup : false,
  10110. teardown : false,
  10111. suiteSetup : false,
  10112. suiteTeardown : false
  10113. };
  10114. exports.jasmine = {
  10115. jasmine : false,
  10116. describe : false,
  10117. xdescribe : false,
  10118. it : false,
  10119. xit : false,
  10120. beforeEach : false,
  10121. afterEach : false,
  10122. setFixtures : false,
  10123. loadFixtures: false,
  10124. spyOn : false,
  10125. expect : false,
  10126. // Jasmine 1.3
  10127. runs : false,
  10128. waitsFor : false,
  10129. waits : false,
  10130. // Jasmine 2.1
  10131. beforeAll : false,
  10132. afterAll : false,
  10133. fail : false,
  10134. fdescribe : false,
  10135. fit : false
  10136. };
  10137. },{}]},{},["/node_modules/jshint/src/jshint.js"]);
  10138. });