Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

worker-javascript.js 278KB

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