jshint.js 167 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835
  1. /*!
  2. * JSHint, by JSHint Community.
  3. *
  4. * This file (and this file only) is licensed under the same slightly modified
  5. * MIT license that JSLint is. It stops evil-doers everywhere.
  6. *
  7. * JSHint is a derivative work of JSLint:
  8. *
  9. * Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining
  12. * a copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom
  16. * the Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included
  19. * in all copies or substantial portions of the Software.
  20. *
  21. * The Software shall be used for Good, not Evil.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. * DEALINGS IN THE SOFTWARE.
  30. *
  31. */
  32. /*
  33. JSHINT is a global function. It takes two parameters.
  34. var myResult = JSHINT(source, option);
  35. The first parameter is either a string or an array of strings. If it is a
  36. string, it will be split on '\n' or '\r'. If it is an array of strings, it
  37. is assumed that each string represents one line. The source can be a
  38. JavaScript text or a JSON text.
  39. The second parameter is an optional object of options which control the
  40. operation of JSHINT. Most of the options are booleans: They are all
  41. optional and have a default value of false. One of the options, predef,
  42. can be an array of names, which will be used to declare global variables,
  43. or an object whose keys are used as global names, with a boolean value
  44. that determines if they are assignable.
  45. If it checks out, JSHINT returns true. Otherwise, it returns false.
  46. If false, you can inspect JSHINT.errors to find out the problems.
  47. JSHINT.errors is an array of objects containing these members:
  48. {
  49. line : The line (relative to 1) at which the lint was found
  50. character : The character (relative to 1) at which the lint was found
  51. reason : The problem
  52. evidence : The text line in which the problem occurred
  53. raw : The raw message before the details were inserted
  54. a : The first detail
  55. b : The second detail
  56. c : The third detail
  57. d : The fourth detail
  58. }
  59. If a fatal error was found, a null will be the last element of the
  60. JSHINT.errors array.
  61. You can request a data structure which contains JSHint's results.
  62. var myData = JSHINT.data();
  63. It returns a structure with this form:
  64. {
  65. errors: [
  66. {
  67. line: NUMBER,
  68. character: NUMBER,
  69. reason: STRING,
  70. evidence: STRING
  71. }
  72. ],
  73. functions: [
  74. name: STRING,
  75. line: NUMBER,
  76. character: NUMBER,
  77. last: NUMBER,
  78. lastcharacter: NUMBER,
  79. param: [
  80. STRING
  81. ],
  82. closure: [
  83. STRING
  84. ],
  85. var: [
  86. STRING
  87. ],
  88. exception: [
  89. STRING
  90. ],
  91. outer: [
  92. STRING
  93. ],
  94. unused: [
  95. STRING
  96. ],
  97. global: [
  98. STRING
  99. ],
  100. label: [
  101. STRING
  102. ]
  103. ],
  104. globals: [
  105. STRING
  106. ],
  107. member: {
  108. STRING: NUMBER
  109. },
  110. unused: [
  111. {
  112. name: STRING,
  113. line: NUMBER
  114. }
  115. ],
  116. implieds: [
  117. {
  118. name: STRING,
  119. line: NUMBER
  120. }
  121. ],
  122. urls: [
  123. STRING
  124. ],
  125. json: BOOLEAN
  126. }
  127. Empty arrays will not be included.
  128. */
  129. /*jshint
  130. evil: true, nomen: false, onevar: false, regexp: false, strict: true, boss: true,
  131. undef: true, maxlen: 100, indent: 4, quotmark: double, unused: true
  132. */
  133. /*members "\b", "\t", "\n", "\f", "\r", "!=", "!==", "\"", "%", "(begin)",
  134. "(breakage)", "(character)", "(context)", "(error)", "(explicitNewcap)", "(global)",
  135. "(identifier)", "(last)", "(lastcharacter)", "(line)", "(loopage)", "(metrics)",
  136. "(name)", "(onevar)", "(params)", "(scope)", "(statement)", "(verb)", "(tokens)", "(catch)",
  137. "*", "+", "++", "-", "--", "\/", "<", "<=", "==",
  138. "===", ">", ">=", $, $$, $A, $F, $H, $R, $break, $continue, $w, Abstract, Ajax,
  139. __filename, __dirname, ActiveXObject, Array, ArrayBuffer, ArrayBufferView, Audio,
  140. Autocompleter, Asset, Boolean, Builder, Buffer, Browser, Blob, COM, CScript, Canvas,
  141. CustomAnimation, Class, Control, ComplexityCount, Chain, Color, Cookie, Core, DataView, Date,
  142. Debug, Draggable, Draggables, Droppables, Document, DomReady, DOMEvent, DOMReady, DOMParser,
  143. Drag, E, Enumerator, Enumerable, Element, Elements, Error, Effect, EvalError, Event,
  144. Events, FadeAnimation, Field, Flash, Float32Array, Float64Array, Form,
  145. FormField, Frame, FormData, Function, Fx, GetObject, Group, Hash, HotKey,
  146. HTMLElement, HTMLAnchorElement, HTMLBaseElement, HTMLBlockquoteElement,
  147. HTMLBodyElement, HTMLBRElement, HTMLButtonElement, HTMLCanvasElement, HTMLDirectoryElement,
  148. HTMLDivElement, HTMLDListElement, HTMLFieldSetElement,
  149. HTMLFontElement, HTMLFormElement, HTMLFrameElement, HTMLFrameSetElement,
  150. HTMLHeadElement, HTMLHeadingElement, HTMLHRElement, HTMLHtmlElement,
  151. HTMLIFrameElement, HTMLImageElement, HTMLInputElement, HTMLIsIndexElement,
  152. HTMLLabelElement, HTMLLayerElement, HTMLLegendElement, HTMLLIElement,
  153. HTMLLinkElement, HTMLMapElement, HTMLMenuElement, HTMLMetaElement,
  154. HTMLModElement, HTMLObjectElement, HTMLOListElement, HTMLOptGroupElement,
  155. HTMLOptionElement, HTMLParagraphElement, HTMLParamElement, HTMLPreElement,
  156. HTMLQuoteElement, HTMLScriptElement, HTMLSelectElement, HTMLStyleElement,
  157. HtmlTable, HTMLTableCaptionElement, HTMLTableCellElement, HTMLTableColElement,
  158. HTMLTableElement, HTMLTableRowElement, HTMLTableSectionElement,
  159. HTMLTextAreaElement, HTMLTitleElement, HTMLUListElement, HTMLVideoElement,
  160. Iframe, IframeShim, Image, importScripts, Int16Array, Int32Array, Int8Array,
  161. Insertion, InputValidator, JSON, Keyboard, Locale, LN10, LN2, LOG10E, LOG2E,
  162. MAX_VALUE, MIN_VALUE, Map, Mask, Math, MenuItem, MessageChannel, MessageEvent, MessagePort,
  163. MoveAnimation, MooTools, MutationObserver, NaN, Native, NEGATIVE_INFINITY, Node, NodeFilter,
  164. Number, Object, ObjectRange,
  165. Option, Options, OverText, PI, POSITIVE_INFINITY, PeriodicalExecuter, Point, Position, Prototype,
  166. RangeError, Rectangle, ReferenceError, RegExp, ResizeAnimation, Request, RotateAnimation, Set,
  167. SQRT1_2, SQRT2, ScrollBar, ScriptEngine, ScriptEngineBuildVersion,
  168. ScriptEngineMajorVersion, ScriptEngineMinorVersion, Scriptaculous, Scroller,
  169. Slick, Slider, Selector, SharedWorker, String, Style, SyntaxError, Sortable, Sortables,
  170. SortableObserver, Sound, Spinner, System, Swiff, Text, TextArea, Template,
  171. Timer, Tips, Type, TypeError, Toggle, Try, "use strict", unescape, URI, URIError, URL,
  172. VBArray, WeakMap, WSH, WScript, XDomainRequest, Web, Window, XMLDOM, XMLHttpRequest, XMLSerializer,
  173. XPathEvaluator, XPathException, XPathExpression, XPathNamespace, XPathNSResolver, XPathResult,
  174. "\\", a, abs, addEventListener, address, alert, apply, applicationCache, arguments, arity,
  175. asi, atob, b, basic, basicToken, bitwise, blacklist, block, blur, boolOptions, boss,
  176. browser, btoa, c, call, callee, caller, camelcase, cases, charAt, charCodeAt, character,
  177. clearInterval, clearTimeout, close, closed, closure, comment, complexityCount, condition,
  178. confirm, console, constructor, content, couch, create, css, curly, d, data, datalist, dd, debug,
  179. decodeURI, decodeURIComponent, defaultStatus, defineClass, deserialize, devel, document,
  180. dojo, dijit, dojox, define, else, emit, encodeURI, encodeURIComponent, elem,
  181. eqeq, eqeqeq, eqnull, errors, es5, escape, esnext, eval, event, evidence, evil,
  182. ex, exception, exec, exps, expr, exports, FileReader, first, floor, focus, forEach,
  183. forin, fragment, frames, from, fromCharCode, fud, funcscope, funct, function, functions,
  184. g, gc, getComputedStyle, getRow, getter, getterToken, GLOBAL, global, globals, globalstrict,
  185. hasOwnProperty, help, history, i, id, identifier, immed, implieds, importPackage, include,
  186. indent, indexOf, init, ins, internals, instanceOf, isAlpha, isApplicationRunning, isArray,
  187. isDigit, isFinite, isNaN, iterator, java, join, jshint,
  188. JSHINT, json, jquery, jQuery, keys, label, labelled, last, lastcharacter, lastsemic, laxbreak,
  189. laxcomma, latedef, lbp, led, left, length, line, load, loadClass, localStorage, location,
  190. log, loopfunc, m, match, max, maxcomplexity, maxdepth, maxerr, maxlen, maxstatements, maxparams,
  191. member, message, meta, module, moveBy, moveTo, mootools, multistr, name, navigator, new, newcap,
  192. nestedBlockDepth, noarg, node, noempty, nomen, nonew, nonstandard, nud, onbeforeunload, onblur,
  193. onerror, onevar, onecase, onfocus, onload, onresize, onunload, open, openDatabase, openURL,
  194. opener, opera, options, outer, param, parent, parseFloat, parseInt, passfail, plusplus,
  195. postMessage, pop, predef, print, process, prompt, proto, prototype, prototypejs, provides, push,
  196. quit, quotmark, range, raw, reach, reason, regexp, readFile, readUrl, regexdash,
  197. removeEventListener, replace, report, require, reserved, resizeBy, resizeTo, resolvePath,
  198. resumeUpdates, respond, rhino, right, runCommand, scroll, scope, screen, scripturl, scrollBy,
  199. scrollTo, scrollbar, search, seal, self, send, serialize, sessionStorage, setInterval, setTimeout,
  200. setter, setterToken, shift, slice, smarttabs, sort, spawn, split, statement, statementCount, stack,
  201. status, start, strict, sub, substr, supernew, shadow, supplant, sum, sync, test, toLowerCase,
  202. toString, toUpperCase, toint32, token, tokens, top, trailing, type, typeOf, Uint16Array,
  203. Uint32Array, Uint8Array, undef, undefs, unused, urls, validthis, value, valueOf, var, vars,
  204. version, verifyMaxParametersPerFunction, verifyMaxStatementsPerFunction,
  205. verifyMaxComplexityPerFunction, verifyMaxNestedBlockDepthPerFunction, WebSocket, withstmt, white,
  206. window, windows, Worker, worker, wsh, yui, YUI, Y, YUI_config*/
  207. /*global exports: false */
  208. // We build the application inside a function so that we produce only a single
  209. // global variable. That function will be invoked immediately, and its return
  210. // value is the JSHINT function itself.
  211. var JSHINT = (function () {
  212. "use strict";
  213. var anonname, // The guessed name for anonymous functions.
  214. // These are operators that should not be used with the ! operator.
  215. bang = {
  216. "<" : true,
  217. "<=" : true,
  218. "==" : true,
  219. "===": true,
  220. "!==": true,
  221. "!=" : true,
  222. ">" : true,
  223. ">=" : true,
  224. "+" : true,
  225. "-" : true,
  226. "*" : true,
  227. "/" : true,
  228. "%" : true
  229. },
  230. // These are the JSHint boolean options.
  231. boolOptions = {
  232. asi : true, // if automatic semicolon insertion should be tolerated
  233. bitwise : true, // if bitwise operators should not be allowed
  234. boss : true, // if advanced usage of assignments should be allowed
  235. browser : true, // if the standard browser globals should be predefined
  236. camelcase : true, // if identifiers should be required in camel case
  237. couch : true, // if CouchDB globals should be predefined
  238. curly : true, // if curly braces around all blocks should be required
  239. debug : true, // if debugger statements should be allowed
  240. devel : true, // if logging globals should be predefined (console,
  241. // alert, etc.)
  242. dojo : true, // if Dojo Toolkit globals should be predefined
  243. eqeqeq : true, // if === should be required
  244. eqnull : true, // if == null comparisons should be tolerated
  245. es5 : true, // if ES5 syntax should be allowed
  246. esnext : true, // if es.next specific syntax should be allowed
  247. evil : true, // if eval should be allowed
  248. expr : true, // if ExpressionStatement should be allowed as Programs
  249. forin : true, // if for in statements must filter
  250. funcscope : true, // if only function scope should be used for scope tests
  251. globalstrict: true, // if global "use strict"; should be allowed (also
  252. // enables 'strict')
  253. immed : true, // if immediate invocations must be wrapped in parens
  254. iterator : true, // if the `__iterator__` property should be allowed
  255. jquery : true, // if jQuery globals should be predefined
  256. lastsemic : true, // if semicolons may be ommitted for the trailing
  257. // statements inside of a one-line blocks.
  258. latedef : true, // if the use before definition should not be tolerated
  259. laxbreak : true, // if line breaks should not be checked
  260. laxcomma : true, // if line breaks should not be checked around commas
  261. loopfunc : true, // if functions should be allowed to be defined within
  262. // loops
  263. mootools : true, // if MooTools globals should be predefined
  264. multistr : true, // allow multiline strings
  265. newcap : true, // if constructor names must be capitalized
  266. noarg : true, // if arguments.caller and arguments.callee should be
  267. // disallowed
  268. node : true, // if the Node.js environment globals should be
  269. // predefined
  270. noempty : true, // if empty blocks should be disallowed
  271. nonew : true, // if using `new` for side-effects should be disallowed
  272. nonstandard : true, // if non-standard (but widely adopted) globals should
  273. // be predefined
  274. nomen : true, // if names should be checked
  275. onevar : true, // if only one var statement per function should be
  276. // allowed
  277. onecase : true, // if one case switch statements should be allowed
  278. passfail : true, // if the scan should stop on first error
  279. plusplus : true, // if increment/decrement should not be allowed
  280. proto : true, // if the `__proto__` property should be allowed
  281. prototypejs : true, // if Prototype and Scriptaculous globals should be
  282. // predefined
  283. regexdash : true, // if unescaped first/last dash (-) inside brackets
  284. // should be tolerated
  285. regexp : true, // if the . should not be allowed in regexp literals
  286. rhino : true, // if the Rhino environment globals should be predefined
  287. undef : true, // if variables should be declared before used
  288. unused : true, // if variables should be always used
  289. scripturl : true, // if script-targeted URLs should be tolerated
  290. shadow : true, // if variable shadowing should be tolerated
  291. smarttabs : true, // if smarttabs should be tolerated
  292. // (http://www.emacswiki.org/emacs/SmartTabs)
  293. strict : true, // require the "use strict"; pragma
  294. sub : true, // if all forms of subscript notation are tolerated
  295. supernew : true, // if `new function () { ... };` and `new Object;`
  296. // should be tolerated
  297. trailing : true, // if trailing whitespace rules apply
  298. validthis : true, // if 'this' inside a non-constructor function is valid.
  299. // This is a function scoped option only.
  300. withstmt : true, // if with statements should be allowed
  301. white : true, // if strict whitespace rules apply
  302. worker : true, // if Web Worker script symbols should be allowed
  303. wsh : true, // if the Windows Scripting Host environment globals
  304. // should be predefined
  305. yui : true // YUI variables should be predefined
  306. },
  307. // These are the JSHint options that can take any value
  308. // (we use this object to detect invalid options)
  309. valOptions = {
  310. maxlen : false,
  311. indent : false,
  312. maxerr : false,
  313. predef : false,
  314. quotmark : false, //'single'|'double'|true
  315. scope : false,
  316. maxstatements: false, // {int} max statements per function
  317. maxdepth : false, // {int} max nested block depth per function
  318. maxparams : false, // {int} max params per function
  319. maxcomplexity: false // {int} max cyclomatic complexity per function
  320. },
  321. // These are JSHint boolean options which are shared with JSLint
  322. // where the definition in JSHint is opposite JSLint
  323. invertedOptions = {
  324. bitwise : true,
  325. forin : true,
  326. newcap : true,
  327. nomen : true,
  328. plusplus : true,
  329. regexp : true,
  330. undef : true,
  331. white : true,
  332. // Inverted and renamed, use JSHint name here
  333. eqeqeq : true,
  334. onevar : true
  335. },
  336. // These are JSHint boolean options which are shared with JSLint
  337. // where the name has been changed but the effect is unchanged
  338. renamedOptions = {
  339. eqeq : "eqeqeq",
  340. vars : "onevar",
  341. windows : "wsh"
  342. },
  343. // browser contains a set of global names which are commonly provided by a
  344. // web browser environment.
  345. browser = {
  346. ArrayBuffer : false,
  347. ArrayBufferView : false,
  348. Audio : false,
  349. Blob : false,
  350. addEventListener : false,
  351. applicationCache : false,
  352. atob : false,
  353. blur : false,
  354. btoa : false,
  355. clearInterval : false,
  356. clearTimeout : false,
  357. close : false,
  358. closed : false,
  359. DataView : false,
  360. DOMParser : false,
  361. defaultStatus : false,
  362. document : false,
  363. event : false,
  364. FileReader : false,
  365. Float32Array : false,
  366. Float64Array : false,
  367. FormData : false,
  368. focus : false,
  369. frames : false,
  370. getComputedStyle : false,
  371. HTMLElement : false,
  372. HTMLAnchorElement : false,
  373. HTMLBaseElement : false,
  374. HTMLBlockquoteElement : false,
  375. HTMLBodyElement : false,
  376. HTMLBRElement : false,
  377. HTMLButtonElement : false,
  378. HTMLCanvasElement : false,
  379. HTMLDirectoryElement : false,
  380. HTMLDivElement : false,
  381. HTMLDListElement : false,
  382. HTMLFieldSetElement : false,
  383. HTMLFontElement : false,
  384. HTMLFormElement : false,
  385. HTMLFrameElement : false,
  386. HTMLFrameSetElement : false,
  387. HTMLHeadElement : false,
  388. HTMLHeadingElement : false,
  389. HTMLHRElement : false,
  390. HTMLHtmlElement : false,
  391. HTMLIFrameElement : false,
  392. HTMLImageElement : false,
  393. HTMLInputElement : false,
  394. HTMLIsIndexElement : false,
  395. HTMLLabelElement : false,
  396. HTMLLayerElement : false,
  397. HTMLLegendElement : false,
  398. HTMLLIElement : false,
  399. HTMLLinkElement : false,
  400. HTMLMapElement : false,
  401. HTMLMenuElement : false,
  402. HTMLMetaElement : false,
  403. HTMLModElement : false,
  404. HTMLObjectElement : false,
  405. HTMLOListElement : false,
  406. HTMLOptGroupElement : false,
  407. HTMLOptionElement : false,
  408. HTMLParagraphElement : false,
  409. HTMLParamElement : false,
  410. HTMLPreElement : false,
  411. HTMLQuoteElement : false,
  412. HTMLScriptElement : false,
  413. HTMLSelectElement : false,
  414. HTMLStyleElement : false,
  415. HTMLTableCaptionElement : false,
  416. HTMLTableCellElement : false,
  417. HTMLTableColElement : false,
  418. HTMLTableElement : false,
  419. HTMLTableRowElement : false,
  420. HTMLTableSectionElement : false,
  421. HTMLTextAreaElement : false,
  422. HTMLTitleElement : false,
  423. HTMLUListElement : false,
  424. HTMLVideoElement : false,
  425. history : false,
  426. Int16Array : false,
  427. Int32Array : false,
  428. Int8Array : false,
  429. Image : false,
  430. length : false,
  431. localStorage : false,
  432. location : false,
  433. MessageChannel : false,
  434. MessageEvent : false,
  435. MessagePort : false,
  436. moveBy : false,
  437. moveTo : false,
  438. MutationObserver : false,
  439. name : false,
  440. Node : false,
  441. NodeFilter : false,
  442. navigator : false,
  443. onbeforeunload : true,
  444. onblur : true,
  445. onerror : true,
  446. onfocus : true,
  447. onload : true,
  448. onresize : true,
  449. onunload : true,
  450. open : false,
  451. openDatabase : false,
  452. opener : false,
  453. Option : false,
  454. parent : false,
  455. print : false,
  456. removeEventListener : false,
  457. resizeBy : false,
  458. resizeTo : false,
  459. screen : false,
  460. scroll : false,
  461. scrollBy : false,
  462. scrollTo : false,
  463. sessionStorage : false,
  464. setInterval : false,
  465. setTimeout : false,
  466. SharedWorker : false,
  467. status : false,
  468. top : false,
  469. Uint16Array : false,
  470. Uint32Array : false,
  471. Uint8Array : false,
  472. WebSocket : false,
  473. window : false,
  474. Worker : false,
  475. XMLHttpRequest : false,
  476. XMLSerializer : false,
  477. XPathEvaluator : false,
  478. XPathException : false,
  479. XPathExpression : false,
  480. XPathNamespace : false,
  481. XPathNSResolver : false,
  482. XPathResult : false
  483. },
  484. couch = {
  485. "require" : false,
  486. respond : false,
  487. getRow : false,
  488. emit : false,
  489. send : false,
  490. start : false,
  491. sum : false,
  492. log : false,
  493. exports : false,
  494. module : false,
  495. provides : false
  496. },
  497. declared, // Globals that were declared using /*global ... */ syntax.
  498. devel = {
  499. alert : false,
  500. confirm : false,
  501. console : false,
  502. Debug : false,
  503. opera : false,
  504. prompt : false
  505. },
  506. dojo = {
  507. dojo : false,
  508. dijit : false,
  509. dojox : false,
  510. define : false,
  511. "require" : false
  512. },
  513. funct, // The current function
  514. functionicity = [
  515. "closure", "exception", "global", "label",
  516. "outer", "unused", "var"
  517. ],
  518. functions, // All of the functions
  519. global, // The global scope
  520. implied, // Implied globals
  521. inblock,
  522. indent,
  523. jsonmode,
  524. jquery = {
  525. "$" : false,
  526. jQuery : false
  527. },
  528. lines,
  529. lookahead,
  530. member,
  531. membersOnly,
  532. mootools = {
  533. "$" : false,
  534. "$$" : false,
  535. Asset : false,
  536. Browser : false,
  537. Chain : false,
  538. Class : false,
  539. Color : false,
  540. Cookie : false,
  541. Core : false,
  542. Document : false,
  543. DomReady : false,
  544. DOMEvent : false,
  545. DOMReady : false,
  546. Drag : false,
  547. Element : false,
  548. Elements : false,
  549. Event : false,
  550. Events : false,
  551. Fx : false,
  552. Group : false,
  553. Hash : false,
  554. HtmlTable : false,
  555. Iframe : false,
  556. IframeShim : false,
  557. InputValidator : false,
  558. instanceOf : false,
  559. Keyboard : false,
  560. Locale : false,
  561. Mask : false,
  562. MooTools : false,
  563. Native : false,
  564. Options : false,
  565. OverText : false,
  566. Request : false,
  567. Scroller : false,
  568. Slick : false,
  569. Slider : false,
  570. Sortables : false,
  571. Spinner : false,
  572. Swiff : false,
  573. Tips : false,
  574. Type : false,
  575. typeOf : false,
  576. URI : false,
  577. Window : false
  578. },
  579. nexttoken,
  580. node = {
  581. __filename : false,
  582. __dirname : false,
  583. Buffer : false,
  584. console : false,
  585. exports : true, // In Node it is ok to exports = module.exports = foo();
  586. GLOBAL : false,
  587. global : false,
  588. module : false,
  589. process : false,
  590. require : false,
  591. setTimeout : false,
  592. clearTimeout : false,
  593. setInterval : false,
  594. clearInterval : false
  595. },
  596. noreach,
  597. option,
  598. predefined, // Global variables defined by option
  599. prereg,
  600. prevtoken,
  601. prototypejs = {
  602. "$" : false,
  603. "$$" : false,
  604. "$A" : false,
  605. "$F" : false,
  606. "$H" : false,
  607. "$R" : false,
  608. "$break" : false,
  609. "$continue" : false,
  610. "$w" : false,
  611. Abstract : false,
  612. Ajax : false,
  613. Class : false,
  614. Enumerable : false,
  615. Element : false,
  616. Event : false,
  617. Field : false,
  618. Form : false,
  619. Hash : false,
  620. Insertion : false,
  621. ObjectRange : false,
  622. PeriodicalExecuter: false,
  623. Position : false,
  624. Prototype : false,
  625. Selector : false,
  626. Template : false,
  627. Toggle : false,
  628. Try : false,
  629. Autocompleter : false,
  630. Builder : false,
  631. Control : false,
  632. Draggable : false,
  633. Draggables : false,
  634. Droppables : false,
  635. Effect : false,
  636. Sortable : false,
  637. SortableObserver : false,
  638. Sound : false,
  639. Scriptaculous : false
  640. },
  641. quotmark,
  642. rhino = {
  643. defineClass : false,
  644. deserialize : false,
  645. gc : false,
  646. help : false,
  647. importPackage: false,
  648. "java" : false,
  649. load : false,
  650. loadClass : false,
  651. print : false,
  652. quit : false,
  653. readFile : false,
  654. readUrl : false,
  655. runCommand : false,
  656. seal : false,
  657. serialize : false,
  658. spawn : false,
  659. sync : false,
  660. toint32 : false,
  661. version : false
  662. },
  663. scope, // The current scope
  664. stack,
  665. // standard contains the global names that are provided by the
  666. // ECMAScript standard.
  667. standard = {
  668. Array : false,
  669. Boolean : false,
  670. Date : false,
  671. decodeURI : false,
  672. decodeURIComponent : false,
  673. encodeURI : false,
  674. encodeURIComponent : false,
  675. Error : false,
  676. "eval" : false,
  677. EvalError : false,
  678. Function : false,
  679. hasOwnProperty : false,
  680. isFinite : false,
  681. isNaN : false,
  682. JSON : false,
  683. Map : false,
  684. Math : false,
  685. NaN : false,
  686. Number : false,
  687. Object : false,
  688. parseInt : false,
  689. parseFloat : false,
  690. RangeError : false,
  691. ReferenceError : false,
  692. RegExp : false,
  693. Set : false,
  694. String : false,
  695. SyntaxError : false,
  696. TypeError : false,
  697. URIError : false,
  698. WeakMap : false
  699. },
  700. // widely adopted global names that are not part of ECMAScript standard
  701. nonstandard = {
  702. escape : false,
  703. unescape : false
  704. },
  705. directive,
  706. syntax = {},
  707. tab,
  708. token,
  709. unuseds,
  710. urls,
  711. useESNextSyntax,
  712. warnings,
  713. worker = {
  714. importScripts : true,
  715. postMessage : true,
  716. self : true
  717. },
  718. wsh = {
  719. ActiveXObject : true,
  720. Enumerator : true,
  721. GetObject : true,
  722. ScriptEngine : true,
  723. ScriptEngineBuildVersion : true,
  724. ScriptEngineMajorVersion : true,
  725. ScriptEngineMinorVersion : true,
  726. VBArray : true,
  727. WSH : true,
  728. WScript : true,
  729. XDomainRequest : true
  730. },
  731. yui = {
  732. YUI : false,
  733. Y : false,
  734. YUI_config : false
  735. };
  736. // Regular expressions. Some of these are stupidly long.
  737. var ax, cx, tx, nx, nxg, lx, ix, jx, ft;
  738. (function () {
  739. /*jshint maxlen:300 */
  740. // unsafe comment or string
  741. ax = /@cc|<\/?|script|\]\s*\]|<\s*!|&lt/i;
  742. // unsafe characters that are silently deleted by one or more browsers
  743. cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
  744. // token
  745. tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/=(?!(\S*\/[gim]?))|\/(\*(jshint|jslint|members?|global)?|\/)?|\*[\/=]?|\+(?:=|\++)?|-(?:=|-+)?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=!]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/;
  746. // characters in strings that need escapement
  747. nx = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
  748. nxg = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  749. // star slash
  750. lx = /\*\//;
  751. // identifier
  752. ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/;
  753. // javascript url
  754. jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i;
  755. // catches /* falls through */ comments
  756. ft = /^\s*\/\*\s*falls\sthrough\s*\*\/\s*$/;
  757. }());
  758. function F() {} // Used by Object.create
  759. function is_own(object, name) {
  760. // The object.hasOwnProperty method fails when the property under consideration
  761. // is named 'hasOwnProperty'. So we have to use this more convoluted form.
  762. return Object.prototype.hasOwnProperty.call(object, name);
  763. }
  764. function checkOption(name, t) {
  765. if (valOptions[name] === undefined && boolOptions[name] === undefined) {
  766. warning("Bad option: '" + name + "'.", t);
  767. }
  768. }
  769. function isString(obj) {
  770. return Object.prototype.toString.call(obj) === "[object String]";
  771. }
  772. // Provide critical ES5 functions to ES3.
  773. if (typeof Array.isArray !== "function") {
  774. Array.isArray = function (o) {
  775. return Object.prototype.toString.apply(o) === "[object Array]";
  776. };
  777. }
  778. if (!Array.prototype.forEach) {
  779. Array.prototype.forEach = function (fn, scope) {
  780. var len = this.length;
  781. for (var i = 0; i < len; i++) {
  782. fn.call(scope || this, this[i], i, this);
  783. }
  784. };
  785. }
  786. if (!Array.prototype.indexOf) {
  787. Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
  788. if (this === null || this === undefined) {
  789. throw new TypeError();
  790. }
  791. var t = new Object(this);
  792. var len = t.length >>> 0;
  793. if (len === 0) {
  794. return -1;
  795. }
  796. var n = 0;
  797. if (arguments.length > 0) {
  798. n = Number(arguments[1]);
  799. if (n != n) { // shortcut for verifying if it's NaN
  800. n = 0;
  801. } else if (n !== 0 && n != Infinity && n != -Infinity) {
  802. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  803. }
  804. }
  805. if (n >= len) {
  806. return -1;
  807. }
  808. var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
  809. for (; k < len; k++) {
  810. if (k in t && t[k] === searchElement) {
  811. return k;
  812. }
  813. }
  814. return -1;
  815. };
  816. }
  817. if (typeof Object.create !== "function") {
  818. Object.create = function (o) {
  819. F.prototype = o;
  820. return new F();
  821. };
  822. }
  823. if (typeof Object.keys !== "function") {
  824. Object.keys = function (o) {
  825. var a = [], k;
  826. for (k in o) {
  827. if (is_own(o, k)) {
  828. a.push(k);
  829. }
  830. }
  831. return a;
  832. };
  833. }
  834. // Non standard methods
  835. function isAlpha(str) {
  836. return (str >= "a" && str <= "z\uffff") ||
  837. (str >= "A" && str <= "Z\uffff");
  838. }
  839. function isDigit(str) {
  840. return (str >= "0" && str <= "9");
  841. }
  842. function isIdentifier(token, value) {
  843. if (!token)
  844. return false;
  845. if (!token.identifier || token.value !== value)
  846. return false;
  847. return true;
  848. }
  849. function supplant(str, data) {
  850. return str.replace(/\{([^{}]*)\}/g, function (a, b) {
  851. var r = data[b];
  852. return typeof r === "string" || typeof r === "number" ? r : a;
  853. });
  854. }
  855. function combine(t, o) {
  856. var n;
  857. for (n in o) {
  858. if (is_own(o, n) && !is_own(JSHINT.blacklist, n)) {
  859. t[n] = o[n];
  860. }
  861. }
  862. }
  863. function updatePredefined() {
  864. Object.keys(JSHINT.blacklist).forEach(function (key) {
  865. delete predefined[key];
  866. });
  867. }
  868. function assume() {
  869. if (option.couch) {
  870. combine(predefined, couch);
  871. }
  872. if (option.rhino) {
  873. combine(predefined, rhino);
  874. }
  875. if (option.prototypejs) {
  876. combine(predefined, prototypejs);
  877. }
  878. if (option.node) {
  879. combine(predefined, node);
  880. option.globalstrict = true;
  881. }
  882. if (option.devel) {
  883. combine(predefined, devel);
  884. }
  885. if (option.dojo) {
  886. combine(predefined, dojo);
  887. }
  888. if (option.browser) {
  889. combine(predefined, browser);
  890. }
  891. if (option.nonstandard) {
  892. combine(predefined, nonstandard);
  893. }
  894. if (option.jquery) {
  895. combine(predefined, jquery);
  896. }
  897. if (option.mootools) {
  898. combine(predefined, mootools);
  899. }
  900. if (option.worker) {
  901. combine(predefined, worker);
  902. }
  903. if (option.wsh) {
  904. combine(predefined, wsh);
  905. }
  906. if (option.esnext) {
  907. useESNextSyntax();
  908. }
  909. if (option.globalstrict && option.strict !== false) {
  910. option.strict = true;
  911. }
  912. if (option.yui) {
  913. combine(predefined, yui);
  914. }
  915. }
  916. // Produce an error warning.
  917. function quit(message, line, chr) {
  918. var percentage = Math.floor((line / lines.length) * 100);
  919. throw {
  920. name: "JSHintError",
  921. line: line,
  922. character: chr,
  923. message: message + " (" + percentage + "% scanned).",
  924. raw: message
  925. };
  926. }
  927. function isundef(scope, m, t, a) {
  928. return JSHINT.undefs.push([scope, m, t, a]);
  929. }
  930. function warning(m, t, a, b, c, d) {
  931. var ch, l, w;
  932. t = t || nexttoken;
  933. if (t.id === "(end)") { // `~
  934. t = token;
  935. }
  936. l = t.line || 0;
  937. ch = t.from || 0;
  938. w = {
  939. id: "(error)",
  940. raw: m,
  941. evidence: lines[l - 1] || "",
  942. line: l,
  943. character: ch,
  944. scope: JSHINT.scope,
  945. a: a,
  946. b: b,
  947. c: c,
  948. d: d
  949. };
  950. w.reason = supplant(m, w);
  951. JSHINT.errors.push(w);
  952. if (option.passfail) {
  953. quit("Stopping. ", l, ch);
  954. }
  955. warnings += 1;
  956. if (warnings >= option.maxerr) {
  957. quit("Too many errors.", l, ch);
  958. }
  959. return w;
  960. }
  961. function warningAt(m, l, ch, a, b, c, d) {
  962. return warning(m, {
  963. line: l,
  964. from: ch
  965. }, a, b, c, d);
  966. }
  967. function error(m, t, a, b, c, d) {
  968. warning(m, t, a, b, c, d);
  969. }
  970. function errorAt(m, l, ch, a, b, c, d) {
  971. return error(m, {
  972. line: l,
  973. from: ch
  974. }, a, b, c, d);
  975. }
  976. // Tracking of "internal" scripts, like eval containing a static string
  977. function addInternalSrc(elem, src) {
  978. var i;
  979. i = {
  980. id: "(internal)",
  981. elem: elem,
  982. value: src
  983. };
  984. JSHINT.internals.push(i);
  985. return i;
  986. }
  987. // lexical analysis and token construction
  988. var lex = (function lex() {
  989. var character, from, line, s;
  990. // Private lex methods
  991. function nextLine() {
  992. var at,
  993. match,
  994. tw; // trailing whitespace check
  995. if (line >= lines.length)
  996. return false;
  997. character = 1;
  998. s = lines[line];
  999. line += 1;
  1000. // If smarttabs option is used check for spaces followed by tabs only.
  1001. // Otherwise check for any occurence of mixed tabs and spaces.
  1002. // Tabs and one space followed by block comment is allowed.
  1003. if (option.smarttabs) {
  1004. // negative look-behind for "//"
  1005. match = s.match(/(\/\/)? \t/);
  1006. at = match && !match[1] ? 0 : -1;
  1007. } else {
  1008. at = s.search(/ \t|\t [^\*]/);
  1009. }
  1010. if (at >= 0)
  1011. warningAt("Mixed spaces and tabs.", line, at + 1);
  1012. s = s.replace(/\t/g, tab);
  1013. at = s.search(cx);
  1014. if (at >= 0)
  1015. warningAt("Unsafe character.", line, at);
  1016. if (option.maxlen && option.maxlen < s.length)
  1017. warningAt("Line too long.", line, s.length);
  1018. // Check for trailing whitespaces
  1019. tw = option.trailing && s.match(/^(.*?)\s+$/);
  1020. if (tw && !/^\s+$/.test(s)) {
  1021. warningAt("Trailing whitespace.", line, tw[1].length + 1);
  1022. }
  1023. return true;
  1024. }
  1025. // Produce a token object. The token inherits from a syntax symbol.
  1026. function it(type, value) {
  1027. var i, t;
  1028. function checkName(name) {
  1029. if (!option.proto && name === "__proto__") {
  1030. warningAt("The '{a}' property is deprecated.", line, from, name);
  1031. return;
  1032. }
  1033. if (!option.iterator && name === "__iterator__") {
  1034. warningAt("'{a}' is only available in JavaScript 1.7.", line, from, name);
  1035. return;
  1036. }
  1037. // Check for dangling underscores unless we're in Node
  1038. // environment and this identifier represents built-in
  1039. // Node globals with underscores.
  1040. var hasDangling = /^(_+.*|.*_+)$/.test(name);
  1041. if (option.nomen && hasDangling && name !== "_") {
  1042. if (option.node && token.id !== "." && /^(__dirname|__filename)$/.test(name))
  1043. return;
  1044. warningAt("Unexpected {a} in '{b}'.", line, from, "dangling '_'", name);
  1045. return;
  1046. }
  1047. // Check for non-camelcase names. Names like MY_VAR and
  1048. // _myVar are okay though.
  1049. if (option.camelcase) {
  1050. if (name.replace(/^_+/, "").indexOf("_") > -1 && !name.match(/^[A-Z0-9_]*$/)) {
  1051. warningAt("Identifier '{a}' is not in camel case.", line, from, value);
  1052. }
  1053. }
  1054. }
  1055. if (type === "(color)" || type === "(range)") {
  1056. t = {type: type};
  1057. } else if (type === "(punctuator)" ||
  1058. (type === "(identifier)" && is_own(syntax, value))) {
  1059. t = syntax[value] || syntax["(error)"];
  1060. } else {
  1061. t = syntax[type];
  1062. }
  1063. t = Object.create(t);
  1064. if (type === "(string)" || type === "(range)") {
  1065. if (!option.scripturl && jx.test(value)) {
  1066. warningAt("Script URL.", line, from);
  1067. }
  1068. }
  1069. if (type === "(identifier)") {
  1070. t.identifier = true;
  1071. checkName(value);
  1072. }
  1073. t.value = value;
  1074. t.line = line;
  1075. t.character = character;
  1076. t.from = from;
  1077. i = t.id;
  1078. if (i !== "(endline)") {
  1079. prereg = i &&
  1080. (("(,=:[!&|?{};".indexOf(i.charAt(i.length - 1)) >= 0) ||
  1081. i === "return" ||
  1082. i === "case");
  1083. }
  1084. return t;
  1085. }
  1086. // Public lex methods
  1087. return {
  1088. init: function (source) {
  1089. if (typeof source === "string") {
  1090. lines = source
  1091. .replace(/\r\n/g, "\n")
  1092. .replace(/\r/g, "\n")
  1093. .split("\n");
  1094. } else {
  1095. lines = source;
  1096. }
  1097. // If the first line is a shebang (#!), make it a blank and move on.
  1098. // Shebangs are used by Node scripts.
  1099. if (lines[0] && lines[0].substr(0, 2) === "#!")
  1100. lines[0] = "";
  1101. line = 0;
  1102. nextLine();
  1103. from = 1;
  1104. },
  1105. range: function (begin, end) {
  1106. var c, value = "";
  1107. from = character;
  1108. if (s.charAt(0) !== begin) {
  1109. errorAt("Expected '{a}' and instead saw '{b}'.",
  1110. line, character, begin, s.charAt(0));
  1111. }
  1112. for (;;) {
  1113. s = s.slice(1);
  1114. character += 1;
  1115. c = s.charAt(0);
  1116. switch (c) {
  1117. case "":
  1118. errorAt("Missing '{a}'.", line, character, c);
  1119. break;
  1120. case end:
  1121. s = s.slice(1);
  1122. character += 1;
  1123. return it("(range)", value);
  1124. case "\\":
  1125. warningAt("Unexpected '{a}'.", line, character, c);
  1126. }
  1127. value += c;
  1128. }
  1129. },
  1130. // token -- this is called by advance to get the next token
  1131. token: function () {
  1132. var b, c, captures, d, depth, high, i, l, low, q, t, isLiteral, isInRange, n;
  1133. function match(x) {
  1134. var r = x.exec(s), r1;
  1135. if (r) {
  1136. l = r[0].length;
  1137. r1 = r[1];
  1138. c = r1.charAt(0);
  1139. s = s.substr(l);
  1140. from = character + l - r1.length;
  1141. character += l;
  1142. return r1;
  1143. }
  1144. }
  1145. function string(x) {
  1146. var c, j, r = "", allowNewLine = false;
  1147. if (jsonmode && x !== "\"") {
  1148. warningAt("Strings must use doublequote.",
  1149. line, character);
  1150. }
  1151. if (option.quotmark) {
  1152. if (option.quotmark === "single" && x !== "'") {
  1153. warningAt("Strings must use singlequote.",
  1154. line, character);
  1155. } else if (option.quotmark === "double" && x !== "\"") {
  1156. warningAt("Strings must use doublequote.",
  1157. line, character);
  1158. } else if (option.quotmark === true) {
  1159. quotmark = quotmark || x;
  1160. if (quotmark !== x) {
  1161. warningAt("Mixed double and single quotes.",
  1162. line, character);
  1163. }
  1164. }
  1165. }
  1166. function esc(n) {
  1167. var i = parseInt(s.substr(j + 1, n), 16);
  1168. j += n;
  1169. if (i >= 32 && i <= 126 &&
  1170. i !== 34 && i !== 92 && i !== 39) {
  1171. warningAt("Unnecessary escapement.", line, character);
  1172. }
  1173. character += n;
  1174. c = String.fromCharCode(i);
  1175. }
  1176. j = 0;
  1177. unclosedString:
  1178. for (;;) {
  1179. while (j >= s.length) {
  1180. j = 0;
  1181. var cl = line, cf = from;
  1182. if (!nextLine()) {
  1183. errorAt("Unclosed string.", cl, cf);
  1184. break unclosedString;
  1185. }
  1186. if (allowNewLine) {
  1187. allowNewLine = false;
  1188. } else {
  1189. warningAt("Unclosed string.", cl, cf);
  1190. }
  1191. }
  1192. c = s.charAt(j);
  1193. if (c === x) {
  1194. character += 1;
  1195. s = s.substr(j + 1);
  1196. return it("(string)", r, x);
  1197. }
  1198. if (c < " ") {
  1199. if (c === "\n" || c === "\r") {
  1200. break;
  1201. }
  1202. warningAt("Control character in string: {a}.",
  1203. line, character + j, s.slice(0, j));
  1204. } else if (c === "\\") {
  1205. j += 1;
  1206. character += 1;
  1207. c = s.charAt(j);
  1208. n = s.charAt(j + 1);
  1209. switch (c) {
  1210. case "\\":
  1211. case "\"":
  1212. case "/":
  1213. break;
  1214. case "\'":
  1215. if (jsonmode) {
  1216. warningAt("Avoid \\'.", line, character);
  1217. }
  1218. break;
  1219. case "b":
  1220. c = "\b";
  1221. break;
  1222. case "f":
  1223. c = "\f";
  1224. break;
  1225. case "n":
  1226. c = "\n";
  1227. break;
  1228. case "r":
  1229. c = "\r";
  1230. break;
  1231. case "t":
  1232. c = "\t";
  1233. break;
  1234. case "0":
  1235. c = "\0";
  1236. // Octal literals fail in strict mode
  1237. // check if the number is between 00 and 07
  1238. // where 'n' is the token next to 'c'
  1239. if (n >= 0 && n <= 7 && directive["use strict"]) {
  1240. warningAt(
  1241. "Octal literals are not allowed in strict mode.",
  1242. line, character);
  1243. }
  1244. break;
  1245. case "u":
  1246. esc(4);
  1247. break;
  1248. case "v":
  1249. if (jsonmode) {
  1250. warningAt("Avoid \\v.", line, character);
  1251. }
  1252. c = "\v";
  1253. break;
  1254. case "x":
  1255. if (jsonmode) {
  1256. warningAt("Avoid \\x-.", line, character);
  1257. }
  1258. esc(2);
  1259. break;
  1260. case "":
  1261. // last character is escape character
  1262. // always allow new line if escaped, but show
  1263. // warning if option is not set
  1264. allowNewLine = true;
  1265. if (option.multistr) {
  1266. if (jsonmode) {
  1267. warningAt("Avoid EOL escapement.", line, character);
  1268. }
  1269. c = "";
  1270. character -= 1;
  1271. break;
  1272. }
  1273. warningAt("Bad escapement of EOL. Use option multistr if needed.",
  1274. line, character);
  1275. break;
  1276. case "!":
  1277. if (s.charAt(j - 2) === "<")
  1278. break;
  1279. /*falls through*/
  1280. default:
  1281. warningAt("Bad escapement.", line, character);
  1282. }
  1283. }
  1284. r += c;
  1285. character += 1;
  1286. j += 1;
  1287. }
  1288. }
  1289. for (;;) {
  1290. if (!s) {
  1291. return it(nextLine() ? "(endline)" : "(end)", "");
  1292. }
  1293. t = match(tx);
  1294. if (!t) {
  1295. t = "";
  1296. c = "";
  1297. while (s && s < "!") {
  1298. s = s.substr(1);
  1299. }
  1300. if (s) {
  1301. errorAt("Unexpected '{a}'.", line, character, s.substr(0, 1));
  1302. s = "";
  1303. }
  1304. } else {
  1305. // identifier
  1306. if (isAlpha(c) || c === "_" || c === "$") {
  1307. return it("(identifier)", t);
  1308. }
  1309. // number
  1310. if (isDigit(c)) {
  1311. if (!isFinite(Number(t))) {
  1312. warningAt("Bad number '{a}'.",
  1313. line, character, t);
  1314. }
  1315. if (isAlpha(s.substr(0, 1))) {
  1316. warningAt("Missing space after '{a}'.",
  1317. line, character, t);
  1318. }
  1319. if (c === "0") {
  1320. d = t.substr(1, 1);
  1321. if (isDigit(d)) {
  1322. if (token.id !== ".") {
  1323. warningAt("Don't use extra leading zeros '{a}'.",
  1324. line, character, t);
  1325. }
  1326. } else if (jsonmode && (d === "x" || d === "X")) {
  1327. warningAt("Avoid 0x-. '{a}'.",
  1328. line, character, t);
  1329. }
  1330. }
  1331. if (t.substr(t.length - 1) === ".") {
  1332. warningAt(
  1333. "A trailing decimal point can be confused with a dot '{a}'.", line, character, t);
  1334. }
  1335. return it("(number)", t);
  1336. }
  1337. switch (t) {
  1338. // string
  1339. case "\"":
  1340. case "'":
  1341. return string(t);
  1342. // // comment
  1343. case "//":
  1344. s = "";
  1345. token.comment = true;
  1346. break;
  1347. // /* comment
  1348. case "/*":
  1349. for (;;) {
  1350. i = s.search(lx);
  1351. if (i >= 0) {
  1352. break;
  1353. }
  1354. if (!nextLine()) {
  1355. errorAt("Unclosed comment.", line, character);
  1356. }
  1357. }
  1358. s = s.substr(i + 2);
  1359. token.comment = true;
  1360. break;
  1361. // /*members /*jshint /*global
  1362. case "/*members":
  1363. case "/*member":
  1364. case "/*jshint":
  1365. case "/*jslint":
  1366. case "/*global":
  1367. case "*/":
  1368. return {
  1369. value: t,
  1370. type: "special",
  1371. line: line,
  1372. character: character,
  1373. from: from
  1374. };
  1375. case "":
  1376. break;
  1377. // /
  1378. case "/":
  1379. if (s.charAt(0) === "=") {
  1380. errorAt("A regular expression literal can be confused with '/='.",
  1381. line, from);
  1382. }
  1383. if (prereg) {
  1384. depth = 0;
  1385. captures = 0;
  1386. l = 0;
  1387. for (;;) {
  1388. b = true;
  1389. c = s.charAt(l);
  1390. l += 1;
  1391. switch (c) {
  1392. case "":
  1393. errorAt("Unclosed regular expression.", line, from);
  1394. return quit("Stopping.", line, from);
  1395. case "/":
  1396. if (depth > 0) {
  1397. warningAt("{a} unterminated regular expression " +
  1398. "group(s).", line, from + l, depth);
  1399. }
  1400. c = s.substr(0, l - 1);
  1401. q = {
  1402. g: true,
  1403. i: true,
  1404. m: true
  1405. };
  1406. while (q[s.charAt(l)] === true) {
  1407. q[s.charAt(l)] = false;
  1408. l += 1;
  1409. }
  1410. character += l;
  1411. s = s.substr(l);
  1412. q = s.charAt(0);
  1413. if (q === "/" || q === "*") {
  1414. errorAt("Confusing regular expression.",
  1415. line, from);
  1416. }
  1417. return it("(regexp)", c);
  1418. case "\\":
  1419. c = s.charAt(l);
  1420. if (c < " ") {
  1421. warningAt(
  1422. "Unexpected control character in regular expression.", line, from + l);
  1423. } else if (c === "<") {
  1424. warningAt(
  1425. "Unexpected escaped character '{a}' in regular expression.", line, from + l, c);
  1426. }
  1427. l += 1;
  1428. break;
  1429. case "(":
  1430. depth += 1;
  1431. b = false;
  1432. if (s.charAt(l) === "?") {
  1433. l += 1;
  1434. switch (s.charAt(l)) {
  1435. case ":":
  1436. case "=":
  1437. case "!":
  1438. l += 1;
  1439. break;
  1440. default:
  1441. warningAt(
  1442. "Expected '{a}' and instead saw '{b}'.", line, from + l, ":", s.charAt(l));
  1443. }
  1444. } else {
  1445. captures += 1;
  1446. }
  1447. break;
  1448. case "|":
  1449. b = false;
  1450. break;
  1451. case ")":
  1452. if (depth === 0) {
  1453. warningAt("Unescaped '{a}'.",
  1454. line, from + l, ")");
  1455. } else {
  1456. depth -= 1;
  1457. }
  1458. break;
  1459. case " ":
  1460. q = 1;
  1461. while (s.charAt(l) === " ") {
  1462. l += 1;
  1463. q += 1;
  1464. }
  1465. if (q > 1) {
  1466. warningAt(
  1467. "Spaces are hard to count. Use {{a}}.", line, from + l, q);
  1468. }
  1469. break;
  1470. case "[":
  1471. c = s.charAt(l);
  1472. if (c === "^") {
  1473. l += 1;
  1474. if (s.charAt(l) === "]") {
  1475. errorAt("Unescaped '{a}'.",
  1476. line, from + l, "^");
  1477. }
  1478. }
  1479. if (c === "]") {
  1480. warningAt("Empty class.", line,
  1481. from + l - 1);
  1482. }
  1483. isLiteral = false;
  1484. isInRange = false;
  1485. klass:
  1486. do {
  1487. c = s.charAt(l);
  1488. l += 1;
  1489. switch (c) {
  1490. case "[":
  1491. case "^":
  1492. warningAt("Unescaped '{a}'.",
  1493. line, from + l, c);
  1494. if (isInRange) {
  1495. isInRange = false;
  1496. } else {
  1497. isLiteral = true;
  1498. }
  1499. break;
  1500. case "-":
  1501. if (isLiteral && !isInRange) {
  1502. isLiteral = false;
  1503. isInRange = true;
  1504. } else if (isInRange) {
  1505. isInRange = false;
  1506. } else if (s.charAt(l) === "]") {
  1507. isInRange = true;
  1508. } else {
  1509. if (option.regexdash !== (l === 2 || (l === 3 &&
  1510. s.charAt(1) === "^"))) {
  1511. warningAt("Unescaped '{a}'.",
  1512. line, from + l - 1, "-");
  1513. }
  1514. isLiteral = true;
  1515. }
  1516. break;
  1517. case "]":
  1518. if (isInRange && !option.regexdash) {
  1519. warningAt("Unescaped '{a}'.",
  1520. line, from + l - 1, "-");
  1521. }
  1522. break klass;
  1523. case "\\":
  1524. c = s.charAt(l);
  1525. if (c < " ") {
  1526. warningAt(
  1527. "Unexpected control character in regular expression.", line, from + l);
  1528. } else if (c === "<") {
  1529. warningAt(
  1530. "Unexpected escaped character '{a}' in regular expression.", line, from + l, c);
  1531. }
  1532. l += 1;
  1533. // \w, \s and \d are never part of a character range
  1534. if (/[wsd]/i.test(c)) {
  1535. if (isInRange) {
  1536. warningAt("Unescaped '{a}'.",
  1537. line, from + l, "-");
  1538. isInRange = false;
  1539. }
  1540. isLiteral = false;
  1541. } else if (isInRange) {
  1542. isInRange = false;
  1543. } else {
  1544. isLiteral = true;
  1545. }
  1546. break;
  1547. case "/":
  1548. warningAt("Unescaped '{a}'.",
  1549. line, from + l - 1, "/");
  1550. if (isInRange) {
  1551. isInRange = false;
  1552. } else {
  1553. isLiteral = true;
  1554. }
  1555. break;
  1556. case "<":
  1557. if (isInRange) {
  1558. isInRange = false;
  1559. } else {
  1560. isLiteral = true;
  1561. }
  1562. break;
  1563. default:
  1564. if (isInRange) {
  1565. isInRange = false;
  1566. } else {
  1567. isLiteral = true;
  1568. }
  1569. }
  1570. } while (c);
  1571. break;
  1572. case ".":
  1573. if (option.regexp) {
  1574. warningAt("Insecure '{a}'.", line,
  1575. from + l, c);
  1576. }
  1577. break;
  1578. case "]":
  1579. case "?":
  1580. case "{":
  1581. case "}":
  1582. case "+":
  1583. case "*":
  1584. warningAt("Unescaped '{a}'.", line,
  1585. from + l, c);
  1586. }
  1587. if (b) {
  1588. switch (s.charAt(l)) {
  1589. case "?":
  1590. case "+":
  1591. case "*":
  1592. l += 1;
  1593. if (s.charAt(l) === "?") {
  1594. l += 1;
  1595. }
  1596. break;
  1597. case "{":
  1598. l += 1;
  1599. c = s.charAt(l);
  1600. if (c < "0" || c > "9") {
  1601. warningAt(
  1602. "Expected a number and instead saw '{a}'.", line, from + l, c);
  1603. break; // No reason to continue checking numbers.
  1604. }
  1605. l += 1;
  1606. low = +c;
  1607. for (;;) {
  1608. c = s.charAt(l);
  1609. if (c < "0" || c > "9") {
  1610. break;
  1611. }
  1612. l += 1;
  1613. low = +c + (low * 10);
  1614. }
  1615. high = low;
  1616. if (c === ",") {
  1617. l += 1;
  1618. high = Infinity;
  1619. c = s.charAt(l);
  1620. if (c >= "0" && c <= "9") {
  1621. l += 1;
  1622. high = +c;
  1623. for (;;) {
  1624. c = s.charAt(l);
  1625. if (c < "0" || c > "9") {
  1626. break;
  1627. }
  1628. l += 1;
  1629. high = +c + (high * 10);
  1630. }
  1631. }
  1632. }
  1633. if (s.charAt(l) !== "}") {
  1634. warningAt(
  1635. "Expected '{a}' and instead saw '{b}'.", line, from + l, "}", c);
  1636. } else {
  1637. l += 1;
  1638. }
  1639. if (s.charAt(l) === "?") {
  1640. l += 1;
  1641. }
  1642. if (low > high) {
  1643. warningAt(
  1644. "'{a}' should not be greater than '{b}'.", line, from + l, low, high);
  1645. }
  1646. }
  1647. }
  1648. }
  1649. c = s.substr(0, l - 1);
  1650. character += l;
  1651. s = s.substr(l);
  1652. return it("(regexp)", c);
  1653. }
  1654. return it("(punctuator)", t);
  1655. // punctuator
  1656. case "#":
  1657. return it("(punctuator)", t);
  1658. default:
  1659. return it("(punctuator)", t);
  1660. }
  1661. }
  1662. }
  1663. }
  1664. };
  1665. }());
  1666. function addlabel(t, type, token) {
  1667. if (t === "hasOwnProperty") {
  1668. warning("'hasOwnProperty' is a really bad name.");
  1669. }
  1670. // Define t in the current function in the current scope.
  1671. if (type === "exception") {
  1672. if (is_own(funct["(context)"], t)) {
  1673. if (funct[t] !== true && !option.node) {
  1674. warning("Value of '{a}' may be overwritten in IE.", nexttoken, t);
  1675. }
  1676. }
  1677. }
  1678. if (is_own(funct, t) && !funct["(global)"]) {
  1679. if (funct[t] === true) {
  1680. if (option.latedef)
  1681. warning("'{a}' was used before it was defined.", nexttoken, t);
  1682. } else {
  1683. if (!option.shadow && type !== "exception") {
  1684. warning("'{a}' is already defined.", nexttoken, t);
  1685. }
  1686. }
  1687. }
  1688. funct[t] = type;
  1689. if (token) {
  1690. funct["(tokens)"][t] = token;
  1691. }
  1692. if (funct["(global)"]) {
  1693. global[t] = funct;
  1694. if (is_own(implied, t)) {
  1695. if (option.latedef)
  1696. warning("'{a}' was used before it was defined.", nexttoken, t);
  1697. delete implied[t];
  1698. }
  1699. } else {
  1700. scope[t] = funct;
  1701. }
  1702. }
  1703. function doOption() {
  1704. var nt = nexttoken;
  1705. var o = nt.value;
  1706. var quotmarkValue = option.quotmark;
  1707. var predef = {};
  1708. var b, obj, filter, t, tn, v, minus;
  1709. switch (o) {
  1710. case "*/":
  1711. error("Unbegun comment.");
  1712. break;
  1713. case "/*members":
  1714. case "/*member":
  1715. o = "/*members";
  1716. if (!membersOnly) {
  1717. membersOnly = {};
  1718. }
  1719. obj = membersOnly;
  1720. option.quotmark = false;
  1721. break;
  1722. case "/*jshint":
  1723. case "/*jslint":
  1724. obj = option;
  1725. filter = boolOptions;
  1726. break;
  1727. case "/*global":
  1728. obj = predef;
  1729. break;
  1730. default:
  1731. error("What?");
  1732. }
  1733. t = lex.token();
  1734. loop:
  1735. for (;;) {
  1736. minus = false;
  1737. for (;;) {
  1738. if (t.type === "special" && t.value === "*/") {
  1739. break loop;
  1740. }
  1741. if (t.id !== "(endline)" && t.id !== ",") {
  1742. break;
  1743. }
  1744. t = lex.token();
  1745. }
  1746. if (o === "/*global" && t.value === "-") {
  1747. minus = true;
  1748. t = lex.token();
  1749. }
  1750. if (t.type !== "(string)" && t.type !== "(identifier)" && o !== "/*members") {
  1751. error("Bad option.", t);
  1752. }
  1753. v = lex.token();
  1754. if (v.id === ":") {
  1755. v = lex.token();
  1756. if (obj === membersOnly) {
  1757. error("Expected '{a}' and instead saw '{b}'.", t, "*/", ":");
  1758. }
  1759. if (o === "/*jshint") {
  1760. checkOption(t.value, t);
  1761. }
  1762. var numericVals = [
  1763. "maxstatements",
  1764. "maxparams",
  1765. "maxdepth",
  1766. "maxcomplexity",
  1767. "maxerr",
  1768. "maxlen",
  1769. "indent"
  1770. ];
  1771. if (numericVals.indexOf(t.value) > -1 && (o === "/*jshint" || o === "/*jslint")) {
  1772. b = +v.value;
  1773. if (typeof b !== "number" || !isFinite(b) || b <= 0 || Math.floor(b) !== b) {
  1774. error("Expected a small integer and instead saw '{a}'.", v, v.value);
  1775. }
  1776. if (t.value === "indent")
  1777. obj.white = true;
  1778. obj[t.value] = b;
  1779. } else if (t.value === "validthis") {
  1780. if (funct["(global)"]) {
  1781. error("Option 'validthis' can't be used in a global scope.");
  1782. } else {
  1783. if (v.value === "true" || v.value === "false")
  1784. obj[t.value] = v.value === "true";
  1785. else
  1786. error("Bad option value.", v);
  1787. }
  1788. } else if (t.value === "quotmark" && (o === "/*jshint")) {
  1789. switch (v.value) {
  1790. case "true":
  1791. obj.quotmark = true;
  1792. break;
  1793. case "false":
  1794. obj.quotmark = false;
  1795. break;
  1796. case "double":
  1797. case "single":
  1798. obj.quotmark = v.value;
  1799. break;
  1800. default:
  1801. error("Bad option value.", v);
  1802. }
  1803. } else if (v.value === "true" || v.value === "false") {
  1804. if (o === "/*jslint") {
  1805. tn = renamedOptions[t.value] || t.value;
  1806. obj[tn] = v.value === "true";
  1807. if (invertedOptions[tn] !== undefined) {
  1808. obj[tn] = !obj[tn];
  1809. }
  1810. } else {
  1811. obj[t.value] = v.value === "true";
  1812. }
  1813. if (t.value === "newcap")
  1814. obj["(explicitNewcap)"] = true;
  1815. } else {
  1816. error("Bad option value.", v);
  1817. }
  1818. t = lex.token();
  1819. } else {
  1820. if (o === "/*jshint" || o === "/*jslint") {
  1821. error("Missing option value.", t);
  1822. }
  1823. obj[t.value] = false;
  1824. if (o === "/*global" && minus === true) {
  1825. JSHINT.blacklist[t.value] = t.value;
  1826. updatePredefined();
  1827. }
  1828. t = v;
  1829. }
  1830. }
  1831. if (o === "/*members") {
  1832. option.quotmark = quotmarkValue;
  1833. }
  1834. combine(predefined, predef);
  1835. for (var key in predef) {
  1836. if (is_own(predef, key)) {
  1837. declared[key] = nt;
  1838. }
  1839. }
  1840. if (filter) {
  1841. assume();
  1842. }
  1843. }
  1844. // We need a peek function. If it has an argument, it peeks that much farther
  1845. // ahead. It is used to distinguish
  1846. // for ( var i in ...
  1847. // from
  1848. // for ( var i = ...
  1849. function peek(p) {
  1850. var i = p || 0, j = 0, t;
  1851. while (j <= i) {
  1852. t = lookahead[j];
  1853. if (!t) {
  1854. t = lookahead[j] = lex.token();
  1855. }
  1856. j += 1;
  1857. }
  1858. return t;
  1859. }
  1860. // Produce the next token. It looks for programming errors.
  1861. function advance(id, t) {
  1862. switch (token.id) {
  1863. case "(number)":
  1864. if (nexttoken.id === ".") {
  1865. warning("A dot following a number can be confused with a decimal point.", token);
  1866. }
  1867. break;
  1868. case "-":
  1869. if (nexttoken.id === "-" || nexttoken.id === "--") {
  1870. warning("Confusing minusses.");
  1871. }
  1872. break;
  1873. case "+":
  1874. if (nexttoken.id === "+" || nexttoken.id === "++") {
  1875. warning("Confusing plusses.");
  1876. }
  1877. break;
  1878. }
  1879. if (token.type === "(string)" || token.identifier) {
  1880. anonname = token.value;
  1881. }
  1882. if (id && nexttoken.id !== id) {
  1883. if (t) {
  1884. if (nexttoken.id === "(end)") {
  1885. warning("Unmatched '{a}'.", t, t.id);
  1886. } else {
  1887. warning("Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.",
  1888. nexttoken, id, t.id, t.line, nexttoken.value);
  1889. }
  1890. } else if (nexttoken.type !== "(identifier)" ||
  1891. nexttoken.value !== id) {
  1892. warning("Expected '{a}' and instead saw '{b}'.",
  1893. nexttoken, id, nexttoken.value);
  1894. }
  1895. }
  1896. prevtoken = token;
  1897. token = nexttoken;
  1898. for (;;) {
  1899. nexttoken = lookahead.shift() || lex.token();
  1900. if (nexttoken.id === "(end)" || nexttoken.id === "(error)") {
  1901. return;
  1902. }
  1903. if (nexttoken.type === "special") {
  1904. doOption();
  1905. } else {
  1906. if (nexttoken.id !== "(endline)") {
  1907. break;
  1908. }
  1909. }
  1910. }
  1911. }
  1912. // This is the heart of JSHINT, the Pratt parser. In addition to parsing, it
  1913. // is looking for ad hoc lint patterns. We add .fud to Pratt's model, which is
  1914. // like .nud except that it is only used on the first token of a statement.
  1915. // Having .fud makes it much easier to define statement-oriented languages like
  1916. // JavaScript. I retained Pratt's nomenclature.
  1917. // .nud Null denotation
  1918. // .fud First null denotation
  1919. // .led Left denotation
  1920. // lbp Left binding power
  1921. // rbp Right binding power
  1922. // They are elements of the parsing method called Top Down Operator Precedence.
  1923. function expression(rbp, initial) {
  1924. var left, isArray = false, isObject = false;
  1925. if (nexttoken.id === "(end)")
  1926. error("Unexpected early end of program.", token);
  1927. advance();
  1928. if (initial) {
  1929. anonname = "anonymous";
  1930. funct["(verb)"] = token.value;
  1931. }
  1932. if (initial === true && token.fud) {
  1933. left = token.fud();
  1934. } else {
  1935. if (token.nud) {
  1936. left = token.nud();
  1937. } else {
  1938. if (nexttoken.type === "(number)" && token.id === ".") {
  1939. warning("A leading decimal point can be confused with a dot: '.{a}'.",
  1940. token, nexttoken.value);
  1941. advance();
  1942. return token;
  1943. } else {
  1944. error("Expected an identifier and instead saw '{a}'.",
  1945. token, token.id);
  1946. }
  1947. }
  1948. while (rbp < nexttoken.lbp) {
  1949. isArray = token.value === "Array";
  1950. isObject = token.value === "Object";
  1951. // #527, new Foo.Array(), Foo.Array(), new Foo.Object(), Foo.Object()
  1952. // Line breaks in IfStatement heads exist to satisfy the checkJSHint
  1953. // "Line too long." error.
  1954. if (left && (left.value || (left.first && left.first.value))) {
  1955. // If the left.value is not "new", or the left.first.value is a "."
  1956. // then safely assume that this is not "new Array()" and possibly
  1957. // not "new Object()"...
  1958. if (left.value !== "new" ||
  1959. (left.first && left.first.value && left.first.value === ".")) {
  1960. isArray = false;
  1961. // ...In the case of Object, if the left.value and token.value
  1962. // are not equal, then safely assume that this not "new Object()"
  1963. if (left.value !== token.value) {
  1964. isObject = false;
  1965. }
  1966. }
  1967. }
  1968. advance();
  1969. if (isArray && token.id === "(" && nexttoken.id === ")")
  1970. warning("Use the array literal notation [].", token);
  1971. if (isObject && token.id === "(" && nexttoken.id === ")")
  1972. warning("Use the object literal notation {}.", token);
  1973. if (token.led) {
  1974. left = token.led(left);
  1975. } else {
  1976. error("Expected an operator and instead saw '{a}'.",
  1977. token, token.id);
  1978. }
  1979. }
  1980. }
  1981. return left;
  1982. }
  1983. // Functions for conformance of style.
  1984. function adjacent(left, right) {
  1985. left = left || token;
  1986. right = right || nexttoken;
  1987. if (option.white) {
  1988. if (left.character !== right.from && left.line === right.line) {
  1989. left.from += (left.character - left.from);
  1990. warning("Unexpected space after '{a}'.", left, left.value);
  1991. }
  1992. }
  1993. }
  1994. function nobreak(left, right) {
  1995. left = left || token;
  1996. right = right || nexttoken;
  1997. if (option.white && (left.character !== right.from || left.line !== right.line)) {
  1998. warning("Unexpected space before '{a}'.", right, right.value);
  1999. }
  2000. }
  2001. function nospace(left, right) {
  2002. left = left || token;
  2003. right = right || nexttoken;
  2004. if (option.white && !left.comment) {
  2005. if (left.line === right.line) {
  2006. adjacent(left, right);
  2007. }
  2008. }
  2009. }
  2010. function nonadjacent(left, right) {
  2011. if (option.white) {
  2012. left = left || token;
  2013. right = right || nexttoken;
  2014. if (left.value === ";" && right.value === ";") {
  2015. return;
  2016. }
  2017. if (left.line === right.line && left.character === right.from) {
  2018. left.from += (left.character - left.from);
  2019. warning("Missing space after '{a}'.",
  2020. left, left.value);
  2021. }
  2022. }
  2023. }
  2024. function nobreaknonadjacent(left, right) {
  2025. left = left || token;
  2026. right = right || nexttoken;
  2027. if (!option.laxbreak && left.line !== right.line) {
  2028. warning("Bad line breaking before '{a}'.", right, right.id);
  2029. } else if (option.white) {
  2030. left = left || token;
  2031. right = right || nexttoken;
  2032. if (left.character === right.from) {
  2033. left.from += (left.character - left.from);
  2034. warning("Missing space after '{a}'.",
  2035. left, left.value);
  2036. }
  2037. }
  2038. }
  2039. function indentation(bias) {
  2040. var i;
  2041. if (option.white && nexttoken.id !== "(end)") {
  2042. i = indent + (bias || 0);
  2043. if (nexttoken.from !== i) {
  2044. warning(
  2045. "Expected '{a}' to have an indentation at {b} instead at {c}.",
  2046. nexttoken, nexttoken.value, i, nexttoken.from);
  2047. }
  2048. }
  2049. }
  2050. function nolinebreak(t) {
  2051. t = t || token;
  2052. if (t.line !== nexttoken.line) {
  2053. warning("Line breaking error '{a}'.", t, t.value);
  2054. }
  2055. }
  2056. function comma() {
  2057. if (token.line !== nexttoken.line) {
  2058. if (!option.laxcomma) {
  2059. if (comma.first) {
  2060. warning("Comma warnings can be turned off with 'laxcomma'");
  2061. comma.first = false;
  2062. }
  2063. warning("Bad line breaking before '{a}'.", token, nexttoken.id);
  2064. }
  2065. } else if (!token.comment && token.character !== nexttoken.from && option.white) {
  2066. token.from += (token.character - token.from);
  2067. warning("Unexpected space after '{a}'.", token, token.value);
  2068. }
  2069. advance(",");
  2070. nonadjacent(token, nexttoken);
  2071. }
  2072. // Functional constructors for making the symbols that will be inherited by
  2073. // tokens.
  2074. function symbol(s, p) {
  2075. var x = syntax[s];
  2076. if (!x || typeof x !== "object") {
  2077. syntax[s] = x = {
  2078. id: s,
  2079. lbp: p,
  2080. value: s
  2081. };
  2082. }
  2083. return x;
  2084. }
  2085. function delim(s) {
  2086. return symbol(s, 0);
  2087. }
  2088. function stmt(s, f) {
  2089. var x = delim(s);
  2090. x.identifier = x.reserved = true;
  2091. x.fud = f;
  2092. return x;
  2093. }
  2094. function blockstmt(s, f) {
  2095. var x = stmt(s, f);
  2096. x.block = true;
  2097. return x;
  2098. }
  2099. function reserveName(x) {
  2100. var c = x.id.charAt(0);
  2101. if ((c >= "a" && c <= "z") || (c >= "A" && c <= "Z")) {
  2102. x.identifier = x.reserved = true;
  2103. }
  2104. return x;
  2105. }
  2106. function prefix(s, f) {
  2107. var x = symbol(s, 150);
  2108. reserveName(x);
  2109. x.nud = (typeof f === "function") ? f : function () {
  2110. this.right = expression(150);
  2111. this.arity = "unary";
  2112. if (this.id === "++" || this.id === "--") {
  2113. if (option.plusplus) {
  2114. warning("Unexpected use of '{a}'.", this, this.id);
  2115. } else if ((!this.right.identifier || this.right.reserved) &&
  2116. this.right.id !== "." && this.right.id !== "[") {
  2117. warning("Bad operand.", this);
  2118. }
  2119. }
  2120. return this;
  2121. };
  2122. return x;
  2123. }
  2124. function type(s, f) {
  2125. var x = delim(s);
  2126. x.type = s;
  2127. x.nud = f;
  2128. return x;
  2129. }
  2130. function reserve(s, f) {
  2131. var x = type(s, f);
  2132. x.identifier = x.reserved = true;
  2133. return x;
  2134. }
  2135. function reservevar(s, v) {
  2136. return reserve(s, function () {
  2137. if (typeof v === "function") {
  2138. v(this);
  2139. }
  2140. return this;
  2141. });
  2142. }
  2143. function infix(s, f, p, w) {
  2144. var x = symbol(s, p);
  2145. reserveName(x);
  2146. x.led = function (left) {
  2147. if (!w) {
  2148. nobreaknonadjacent(prevtoken, token);
  2149. nonadjacent(token, nexttoken);
  2150. }
  2151. if (s === "in" && left.id === "!") {
  2152. warning("Confusing use of '{a}'.", left, "!");
  2153. }
  2154. if (typeof f === "function") {
  2155. return f(left, this);
  2156. } else {
  2157. this.left = left;
  2158. this.right = expression(p);
  2159. return this;
  2160. }
  2161. };
  2162. return x;
  2163. }
  2164. function relation(s, f) {
  2165. var x = symbol(s, 100);
  2166. x.led = function (left) {
  2167. nobreaknonadjacent(prevtoken, token);
  2168. nonadjacent(token, nexttoken);
  2169. var right = expression(100);
  2170. if (isIdentifier(left, "NaN") || isIdentifier(right, "NaN")) {
  2171. warning("Use the isNaN function to compare with NaN.", this);
  2172. } else if (f) {
  2173. f.apply(this, [left, right]);
  2174. }
  2175. if (left.id === "!") {
  2176. warning("Confusing use of '{a}'.", left, "!");
  2177. }
  2178. if (right.id === "!") {
  2179. warning("Confusing use of '{a}'.", right, "!");
  2180. }
  2181. this.left = left;
  2182. this.right = right;
  2183. return this;
  2184. };
  2185. return x;
  2186. }
  2187. function isPoorRelation(node) {
  2188. return node &&
  2189. ((node.type === "(number)" && +node.value === 0) ||
  2190. (node.type === "(string)" && node.value === "") ||
  2191. (node.type === "null" && !option.eqnull) ||
  2192. node.type === "true" ||
  2193. node.type === "false" ||
  2194. node.type === "undefined");
  2195. }
  2196. function assignop(s) {
  2197. symbol(s, 20).exps = true;
  2198. return infix(s, function (left, that) {
  2199. that.left = left;
  2200. if (predefined[left.value] === false &&
  2201. scope[left.value]["(global)"] === true) {
  2202. warning("Read only.", left);
  2203. } else if (left["function"]) {
  2204. warning("'{a}' is a function.", left, left.value);
  2205. }
  2206. if (left) {
  2207. if (option.esnext && funct[left.value] === "const") {
  2208. warning("Attempting to override '{a}' which is a constant", left, left.value);
  2209. }
  2210. if (left.id === "." || left.id === "[") {
  2211. if (!left.left || left.left.value === "arguments") {
  2212. warning("Bad assignment.", that);
  2213. }
  2214. that.right = expression(19);
  2215. return that;
  2216. } else if (left.identifier && !left.reserved) {
  2217. if (funct[left.value] === "exception") {
  2218. warning("Do not assign to the exception parameter.", left);
  2219. }
  2220. that.right = expression(19);
  2221. return that;
  2222. }
  2223. if (left === syntax["function"]) {
  2224. warning(
  2225. "Expected an identifier in an assignment and instead saw a function invocation.",
  2226. token);
  2227. }
  2228. }
  2229. error("Bad assignment.", that);
  2230. }, 20);
  2231. }
  2232. function bitwise(s, f, p) {
  2233. var x = symbol(s, p);
  2234. reserveName(x);
  2235. x.led = (typeof f === "function") ? f : function (left) {
  2236. if (option.bitwise) {
  2237. warning("Unexpected use of '{a}'.", this, this.id);
  2238. }
  2239. this.left = left;
  2240. this.right = expression(p);
  2241. return this;
  2242. };
  2243. return x;
  2244. }
  2245. function bitwiseassignop(s) {
  2246. symbol(s, 20).exps = true;
  2247. return infix(s, function (left, that) {
  2248. if (option.bitwise) {
  2249. warning("Unexpected use of '{a}'.", that, that.id);
  2250. }
  2251. nonadjacent(prevtoken, token);
  2252. nonadjacent(token, nexttoken);
  2253. if (left) {
  2254. if (left.id === "." || left.id === "[" ||
  2255. (left.identifier && !left.reserved)) {
  2256. expression(19);
  2257. return that;
  2258. }
  2259. if (left === syntax["function"]) {
  2260. warning(
  2261. "Expected an identifier in an assignment, and instead saw a function invocation.",
  2262. token);
  2263. }
  2264. return that;
  2265. }
  2266. error("Bad assignment.", that);
  2267. }, 20);
  2268. }
  2269. function suffix(s) {
  2270. var x = symbol(s, 150);
  2271. x.led = function (left) {
  2272. if (option.plusplus) {
  2273. warning("Unexpected use of '{a}'.", this, this.id);
  2274. } else if ((!left.identifier || left.reserved) &&
  2275. left.id !== "." && left.id !== "[") {
  2276. warning("Bad operand.", this);
  2277. }
  2278. this.left = left;
  2279. return this;
  2280. };
  2281. return x;
  2282. }
  2283. // fnparam means that this identifier is being defined as a function
  2284. // argument (see identifier())
  2285. function optionalidentifier(fnparam) {
  2286. if (nexttoken.identifier) {
  2287. advance();
  2288. if (token.reserved && !option.es5) {
  2289. // `undefined` as a function param is a common pattern to protect
  2290. // against the case when somebody does `undefined = true` and
  2291. // help with minification. More info: https://gist.github.com/315916
  2292. if (!fnparam || token.value !== "undefined") {
  2293. warning("Expected an identifier and instead saw '{a}' (a reserved word).",
  2294. token, token.id);
  2295. }
  2296. }
  2297. return token.value;
  2298. }
  2299. }
  2300. // fnparam means that this identifier is being defined as a function
  2301. // argument
  2302. function identifier(fnparam) {
  2303. var i = optionalidentifier(fnparam);
  2304. if (i) {
  2305. return i;
  2306. }
  2307. if (token.id === "function" && nexttoken.id === "(") {
  2308. warning("Missing name in function declaration.");
  2309. } else {
  2310. error("Expected an identifier and instead saw '{a}'.",
  2311. nexttoken, nexttoken.value);
  2312. }
  2313. }
  2314. function reachable(s) {
  2315. var i = 0, t;
  2316. if (nexttoken.id !== ";" || noreach) {
  2317. return;
  2318. }
  2319. for (;;) {
  2320. t = peek(i);
  2321. if (t.reach) {
  2322. return;
  2323. }
  2324. if (t.id !== "(endline)") {
  2325. if (t.id === "function") {
  2326. if (!option.latedef) {
  2327. break;
  2328. }
  2329. warning(
  2330. "Inner functions should be listed at the top of the outer function.", t);
  2331. break;
  2332. }
  2333. warning("Unreachable '{a}' after '{b}'.", t, t.value, s);
  2334. break;
  2335. }
  2336. i += 1;
  2337. }
  2338. }
  2339. function statement(noindent) {
  2340. var i = indent, r, s = scope, t = nexttoken;
  2341. if (t.id === ";") {
  2342. advance(";");
  2343. return;
  2344. }
  2345. // Is this a labelled statement?
  2346. if (t.identifier && !t.reserved && peek().id === ":") {
  2347. advance();
  2348. advance(":");
  2349. scope = Object.create(s);
  2350. addlabel(t.value, "label");
  2351. if (!nexttoken.labelled && nexttoken.value !== "{") {
  2352. warning("Label '{a}' on {b} statement.", nexttoken, t.value, nexttoken.value);
  2353. }
  2354. if (jx.test(t.value + ":")) {
  2355. warning("Label '{a}' looks like a javascript url.", t, t.value);
  2356. }
  2357. nexttoken.label = t.value;
  2358. t = nexttoken;
  2359. }
  2360. // Is it a lonely block?
  2361. if (t.id === "{") {
  2362. block(true, true);
  2363. return;
  2364. }
  2365. // Parse the statement.
  2366. if (!noindent) {
  2367. indentation();
  2368. }
  2369. r = expression(0, true);
  2370. // Look for the final semicolon.
  2371. if (!t.block) {
  2372. if (!option.expr && (!r || !r.exps)) {
  2373. warning("Expected an assignment or function call and instead saw an expression.",
  2374. token);
  2375. } else if (option.nonew && r.id === "(" && r.left.id === "new") {
  2376. warning("Do not use 'new' for side effects.", t);
  2377. }
  2378. if (nexttoken.id === ",") {
  2379. return comma();
  2380. }
  2381. if (nexttoken.id !== ";") {
  2382. if (!option.asi) {
  2383. // If this is the last statement in a block that ends on
  2384. // the same line *and* option lastsemic is on, ignore the warning.
  2385. // Otherwise, complain about missing semicolon.
  2386. if (!option.lastsemic || nexttoken.id !== "}" ||
  2387. nexttoken.line !== token.line) {
  2388. warningAt("Missing semicolon.", token.line, token.character);
  2389. }
  2390. }
  2391. } else {
  2392. adjacent(token, nexttoken);
  2393. advance(";");
  2394. nonadjacent(token, nexttoken);
  2395. }
  2396. }
  2397. // Restore the indentation.
  2398. indent = i;
  2399. scope = s;
  2400. return r;
  2401. }
  2402. function statements(startLine) {
  2403. var a = [], p;
  2404. while (!nexttoken.reach && nexttoken.id !== "(end)") {
  2405. if (nexttoken.id === ";") {
  2406. p = peek();
  2407. if (!p || p.id !== "(") {
  2408. warning("Unnecessary semicolon.");
  2409. }
  2410. advance(";");
  2411. } else {
  2412. a.push(statement(startLine === nexttoken.line));
  2413. }
  2414. }
  2415. return a;
  2416. }
  2417. /*
  2418. * read all directives
  2419. * recognizes a simple form of asi, but always
  2420. * warns, if it is used
  2421. */
  2422. function directives() {
  2423. var i, p, pn;
  2424. for (;;) {
  2425. if (nexttoken.id === "(string)") {
  2426. p = peek(0);
  2427. if (p.id === "(endline)") {
  2428. i = 1;
  2429. do {
  2430. pn = peek(i);
  2431. i = i + 1;
  2432. } while (pn.id === "(endline)");
  2433. if (pn.id !== ";") {
  2434. if (pn.id !== "(string)" && pn.id !== "(number)" &&
  2435. pn.id !== "(regexp)" && pn.identifier !== true &&
  2436. pn.id !== "}") {
  2437. break;
  2438. }
  2439. warning("Missing semicolon.", nexttoken);
  2440. } else {
  2441. p = pn;
  2442. }
  2443. } else if (p.id === "}") {
  2444. // directive with no other statements, warn about missing semicolon
  2445. warning("Missing semicolon.", p);
  2446. } else if (p.id !== ";") {
  2447. break;
  2448. }
  2449. indentation();
  2450. advance();
  2451. if (directive[token.value]) {
  2452. warning("Unnecessary directive \"{a}\".", token, token.value);
  2453. }
  2454. if (token.value === "use strict") {
  2455. if (!option["(explicitNewcap)"])
  2456. option.newcap = true;
  2457. option.undef = true;
  2458. }
  2459. // there's no directive negation, so always set to true
  2460. directive[token.value] = true;
  2461. if (p.id === ";") {
  2462. advance(";");
  2463. }
  2464. continue;
  2465. }
  2466. break;
  2467. }
  2468. }
  2469. /*
  2470. * Parses a single block. A block is a sequence of statements wrapped in
  2471. * braces.
  2472. *
  2473. * ordinary - true for everything but function bodies and try blocks.
  2474. * stmt - true if block can be a single statement (e.g. in if/for/while).
  2475. * isfunc - true if block is a function body
  2476. */
  2477. function block(ordinary, stmt, isfunc) {
  2478. var a,
  2479. b = inblock,
  2480. old_indent = indent,
  2481. m,
  2482. s = scope,
  2483. t,
  2484. line,
  2485. d;
  2486. inblock = ordinary;
  2487. if (!ordinary || !option.funcscope)
  2488. scope = Object.create(scope);
  2489. nonadjacent(token, nexttoken);
  2490. t = nexttoken;
  2491. var metrics = funct["(metrics)"];
  2492. metrics.nestedBlockDepth += 1;
  2493. metrics.verifyMaxNestedBlockDepthPerFunction();
  2494. if (nexttoken.id === "{") {
  2495. advance("{");
  2496. line = token.line;
  2497. if (nexttoken.id !== "}") {
  2498. indent += option.indent;
  2499. while (!ordinary && nexttoken.from > indent) {
  2500. indent += option.indent;
  2501. }
  2502. if (isfunc) {
  2503. m = {};
  2504. for (d in directive) {
  2505. if (is_own(directive, d)) {
  2506. m[d] = directive[d];
  2507. }
  2508. }
  2509. directives();
  2510. if (option.strict && funct["(context)"]["(global)"]) {
  2511. if (!m["use strict"] && !directive["use strict"]) {
  2512. warning("Missing \"use strict\" statement.");
  2513. }
  2514. }
  2515. }
  2516. a = statements(line);
  2517. metrics.statementCount += a.length;
  2518. if (isfunc) {
  2519. directive = m;
  2520. }
  2521. indent -= option.indent;
  2522. if (line !== nexttoken.line) {
  2523. indentation();
  2524. }
  2525. } else if (line !== nexttoken.line) {
  2526. indentation();
  2527. }
  2528. advance("}", t);
  2529. indent = old_indent;
  2530. } else if (!ordinary) {
  2531. error("Expected '{a}' and instead saw '{b}'.",
  2532. nexttoken, "{", nexttoken.value);
  2533. } else {
  2534. if (!stmt || option.curly)
  2535. warning("Expected '{a}' and instead saw '{b}'.",
  2536. nexttoken, "{", nexttoken.value);
  2537. noreach = true;
  2538. indent += option.indent;
  2539. // test indentation only if statement is in new line
  2540. a = [statement(nexttoken.line === token.line)];
  2541. indent -= option.indent;
  2542. noreach = false;
  2543. }
  2544. funct["(verb)"] = null;
  2545. if (!ordinary || !option.funcscope) scope = s;
  2546. inblock = b;
  2547. if (ordinary && option.noempty && (!a || a.length === 0)) {
  2548. warning("Empty block.");
  2549. }
  2550. metrics.nestedBlockDepth -= 1;
  2551. return a;
  2552. }
  2553. function countMember(m) {
  2554. if (membersOnly && typeof membersOnly[m] !== "boolean") {
  2555. warning("Unexpected /*member '{a}'.", token, m);
  2556. }
  2557. if (typeof member[m] === "number") {
  2558. member[m] += 1;
  2559. } else {
  2560. member[m] = 1;
  2561. }
  2562. }
  2563. function note_implied(token) {
  2564. var name = token.value, line = token.line, a = implied[name];
  2565. if (typeof a === "function") {
  2566. a = false;
  2567. }
  2568. if (!a) {
  2569. a = [line];
  2570. implied[name] = a;
  2571. } else if (a[a.length - 1] !== line) {
  2572. a.push(line);
  2573. }
  2574. }
  2575. // Build the syntax table by declaring the syntactic elements of the language.
  2576. type("(number)", function () {
  2577. return this;
  2578. });
  2579. type("(string)", function () {
  2580. return this;
  2581. });
  2582. syntax["(identifier)"] = {
  2583. type: "(identifier)",
  2584. lbp: 0,
  2585. identifier: true,
  2586. nud: function () {
  2587. var v = this.value,
  2588. s = scope[v],
  2589. f;
  2590. if (typeof s === "function") {
  2591. // Protection against accidental inheritance.
  2592. s = undefined;
  2593. } else if (typeof s === "boolean") {
  2594. f = funct;
  2595. funct = functions[0];
  2596. addlabel(v, "var");
  2597. s = funct;
  2598. funct = f;
  2599. }
  2600. // The name is in scope and defined in the current function.
  2601. if (funct === s) {
  2602. // Change 'unused' to 'var', and reject labels.
  2603. switch (funct[v]) {
  2604. case "unused":
  2605. funct[v] = "var";
  2606. break;
  2607. case "unction":
  2608. funct[v] = "function";
  2609. this["function"] = true;
  2610. break;
  2611. case "function":
  2612. this["function"] = true;
  2613. break;
  2614. case "label":
  2615. warning("'{a}' is a statement label.", token, v);
  2616. break;
  2617. }
  2618. } else if (funct["(global)"]) {
  2619. // The name is not defined in the function. If we are in the global
  2620. // scope, then we have an undefined variable.
  2621. //
  2622. // Operators typeof and delete do not raise runtime errors even if
  2623. // the base object of a reference is null so no need to display warning
  2624. // if we're inside of typeof or delete.
  2625. if (option.undef && typeof predefined[v] !== "boolean") {
  2626. // Attempting to subscript a null reference will throw an
  2627. // error, even within the typeof and delete operators
  2628. if (!(anonname === "typeof" || anonname === "delete") ||
  2629. (nexttoken && (nexttoken.value === "." || nexttoken.value === "["))) {
  2630. isundef(funct, "'{a}' is not defined.", token, v);
  2631. }
  2632. }
  2633. note_implied(token);
  2634. } else {
  2635. // If the name is already defined in the current
  2636. // function, but not as outer, then there is a scope error.
  2637. switch (funct[v]) {
  2638. case "closure":
  2639. case "function":
  2640. case "var":
  2641. case "unused":
  2642. warning("'{a}' used out of scope.", token, v);
  2643. break;
  2644. case "label":
  2645. warning("'{a}' is a statement label.", token, v);
  2646. break;
  2647. case "outer":
  2648. case "global":
  2649. break;
  2650. default:
  2651. // If the name is defined in an outer function, make an outer entry,
  2652. // and if it was unused, make it var.
  2653. if (s === true) {
  2654. funct[v] = true;
  2655. } else if (s === null) {
  2656. warning("'{a}' is not allowed.", token, v);
  2657. note_implied(token);
  2658. } else if (typeof s !== "object") {
  2659. // Operators typeof and delete do not raise runtime errors even
  2660. // if the base object of a reference is null so no need to
  2661. // display warning if we're inside of typeof or delete.
  2662. if (option.undef) {
  2663. // Attempting to subscript a null reference will throw an
  2664. // error, even within the typeof and delete operators
  2665. if (!(anonname === "typeof" || anonname === "delete") ||
  2666. (nexttoken &&
  2667. (nexttoken.value === "." || nexttoken.value === "["))) {
  2668. isundef(funct, "'{a}' is not defined.", token, v);
  2669. }
  2670. }
  2671. funct[v] = true;
  2672. note_implied(token);
  2673. } else {
  2674. switch (s[v]) {
  2675. case "function":
  2676. case "unction":
  2677. this["function"] = true;
  2678. s[v] = "closure";
  2679. funct[v] = s["(global)"] ? "global" : "outer";
  2680. break;
  2681. case "var":
  2682. case "unused":
  2683. s[v] = "closure";
  2684. funct[v] = s["(global)"] ? "global" : "outer";
  2685. break;
  2686. case "closure":
  2687. funct[v] = s["(global)"] ? "global" : "outer";
  2688. break;
  2689. case "label":
  2690. warning("'{a}' is a statement label.", token, v);
  2691. }
  2692. }
  2693. }
  2694. }
  2695. return this;
  2696. },
  2697. led: function () {
  2698. error("Expected an operator and instead saw '{a}'.",
  2699. nexttoken, nexttoken.value);
  2700. }
  2701. };
  2702. type("(regexp)", function () {
  2703. return this;
  2704. });
  2705. // ECMAScript parser
  2706. delim("(endline)");
  2707. delim("(begin)");
  2708. delim("(end)").reach = true;
  2709. delim("</").reach = true;
  2710. delim("<!");
  2711. delim("<!--");
  2712. delim("-->");
  2713. delim("(error)").reach = true;
  2714. delim("}").reach = true;
  2715. delim(")");
  2716. delim("]");
  2717. delim("\"").reach = true;
  2718. delim("'").reach = true;
  2719. delim(";");
  2720. delim(":").reach = true;
  2721. delim(",");
  2722. delim("#");
  2723. delim("@");
  2724. reserve("else");
  2725. reserve("case").reach = true;
  2726. reserve("catch");
  2727. reserve("default").reach = true;
  2728. reserve("finally");
  2729. reservevar("arguments", function (x) {
  2730. if (directive["use strict"] && funct["(global)"]) {
  2731. warning("Strict violation.", x);
  2732. }
  2733. });
  2734. reservevar("eval");
  2735. reservevar("false");
  2736. reservevar("Infinity");
  2737. reservevar("null");
  2738. reservevar("this", function (x) {
  2739. if (directive["use strict"] && !option.validthis && ((funct["(statement)"] &&
  2740. funct["(name)"].charAt(0) > "Z") || funct["(global)"])) {
  2741. warning("Possible strict violation.", x);
  2742. }
  2743. });
  2744. reservevar("true");
  2745. reservevar("undefined");
  2746. assignop("=", "assign", 20);
  2747. assignop("+=", "assignadd", 20);
  2748. assignop("-=", "assignsub", 20);
  2749. assignop("*=", "assignmult", 20);
  2750. assignop("/=", "assigndiv", 20).nud = function () {
  2751. error("A regular expression literal can be confused with '/='.");
  2752. };
  2753. assignop("%=", "assignmod", 20);
  2754. bitwiseassignop("&=", "assignbitand", 20);
  2755. bitwiseassignop("|=", "assignbitor", 20);
  2756. bitwiseassignop("^=", "assignbitxor", 20);
  2757. bitwiseassignop("<<=", "assignshiftleft", 20);
  2758. bitwiseassignop(">>=", "assignshiftright", 20);
  2759. bitwiseassignop(">>>=", "assignshiftrightunsigned", 20);
  2760. infix("?", function (left, that) {
  2761. that.left = left;
  2762. that.right = expression(10);
  2763. advance(":");
  2764. that["else"] = expression(10);
  2765. return that;
  2766. }, 30);
  2767. infix("||", "or", 40);
  2768. infix("&&", "and", 50);
  2769. bitwise("|", "bitor", 70);
  2770. bitwise("^", "bitxor", 80);
  2771. bitwise("&", "bitand", 90);
  2772. relation("==", function (left, right) {
  2773. var eqnull = option.eqnull && (left.value === "null" || right.value === "null");
  2774. if (!eqnull && option.eqeqeq)
  2775. warning("Expected '{a}' and instead saw '{b}'.", this, "===", "==");
  2776. else if (isPoorRelation(left))
  2777. warning("Use '{a}' to compare with '{b}'.", this, "===", left.value);
  2778. else if (isPoorRelation(right))
  2779. warning("Use '{a}' to compare with '{b}'.", this, "===", right.value);
  2780. return this;
  2781. });
  2782. relation("===");
  2783. relation("!=", function (left, right) {
  2784. var eqnull = option.eqnull &&
  2785. (left.value === "null" || right.value === "null");
  2786. if (!eqnull && option.eqeqeq) {
  2787. warning("Expected '{a}' and instead saw '{b}'.",
  2788. this, "!==", "!=");
  2789. } else if (isPoorRelation(left)) {
  2790. warning("Use '{a}' to compare with '{b}'.",
  2791. this, "!==", left.value);
  2792. } else if (isPoorRelation(right)) {
  2793. warning("Use '{a}' to compare with '{b}'.",
  2794. this, "!==", right.value);
  2795. }
  2796. return this;
  2797. });
  2798. relation("!==");
  2799. relation("<");
  2800. relation(">");
  2801. relation("<=");
  2802. relation(">=");
  2803. bitwise("<<", "shiftleft", 120);
  2804. bitwise(">>", "shiftright", 120);
  2805. bitwise(">>>", "shiftrightunsigned", 120);
  2806. infix("in", "in", 120);
  2807. infix("instanceof", "instanceof", 120);
  2808. infix("+", function (left, that) {
  2809. var right = expression(130);
  2810. if (left && right && left.id === "(string)" && right.id === "(string)") {
  2811. left.value += right.value;
  2812. left.character = right.character;
  2813. if (!option.scripturl && jx.test(left.value)) {
  2814. warning("JavaScript URL.", left);
  2815. }
  2816. return left;
  2817. }
  2818. that.left = left;
  2819. that.right = right;
  2820. return that;
  2821. }, 130);
  2822. prefix("+", "num");
  2823. prefix("+++", function () {
  2824. warning("Confusing pluses.");
  2825. this.right = expression(150);
  2826. this.arity = "unary";
  2827. return this;
  2828. });
  2829. infix("+++", function (left) {
  2830. warning("Confusing pluses.");
  2831. this.left = left;
  2832. this.right = expression(130);
  2833. return this;
  2834. }, 130);
  2835. infix("-", "sub", 130);
  2836. prefix("-", "neg");
  2837. prefix("---", function () {
  2838. warning("Confusing minuses.");
  2839. this.right = expression(150);
  2840. this.arity = "unary";
  2841. return this;
  2842. });
  2843. infix("---", function (left) {
  2844. warning("Confusing minuses.");
  2845. this.left = left;
  2846. this.right = expression(130);
  2847. return this;
  2848. }, 130);
  2849. infix("*", "mult", 140);
  2850. infix("/", "div", 140);
  2851. infix("%", "mod", 140);
  2852. suffix("++", "postinc");
  2853. prefix("++", "preinc");
  2854. syntax["++"].exps = true;
  2855. suffix("--", "postdec");
  2856. prefix("--", "predec");
  2857. syntax["--"].exps = true;
  2858. prefix("delete", function () {
  2859. var p = expression(0);
  2860. if (!p || (p.id !== "." && p.id !== "[")) {
  2861. warning("Variables should not be deleted.");
  2862. }
  2863. this.first = p;
  2864. return this;
  2865. }).exps = true;
  2866. prefix("~", function () {
  2867. if (option.bitwise) {
  2868. warning("Unexpected '{a}'.", this, "~");
  2869. }
  2870. expression(150);
  2871. return this;
  2872. });
  2873. prefix("!", function () {
  2874. this.right = expression(150);
  2875. this.arity = "unary";
  2876. if (bang[this.right.id] === true) {
  2877. warning("Confusing use of '{a}'.", this, "!");
  2878. }
  2879. return this;
  2880. });
  2881. prefix("typeof", "typeof");
  2882. prefix("new", function () {
  2883. var c = expression(155), i;
  2884. if (c && c.id !== "function") {
  2885. if (c.identifier) {
  2886. c["new"] = true;
  2887. switch (c.value) {
  2888. case "Number":
  2889. case "String":
  2890. case "Boolean":
  2891. case "Math":
  2892. case "JSON":
  2893. warning("Do not use {a} as a constructor.", prevtoken, c.value);
  2894. break;
  2895. case "Function":
  2896. if (!option.evil) {
  2897. warning("The Function constructor is eval.");
  2898. }
  2899. break;
  2900. case "Date":
  2901. case "RegExp":
  2902. break;
  2903. default:
  2904. if (c.id !== "function") {
  2905. i = c.value.substr(0, 1);
  2906. if (option.newcap && (i < "A" || i > "Z") && !is_own(global, c.value)) {
  2907. warning("A constructor name should start with an uppercase letter.",
  2908. token);
  2909. }
  2910. }
  2911. }
  2912. } else {
  2913. if (c.id !== "." && c.id !== "[" && c.id !== "(") {
  2914. warning("Bad constructor.", token);
  2915. }
  2916. }
  2917. } else {
  2918. if (!option.supernew)
  2919. warning("Weird construction. Delete 'new'.", this);
  2920. }
  2921. adjacent(token, nexttoken);
  2922. if (nexttoken.id !== "(" && !option.supernew) {
  2923. warning("Missing '()' invoking a constructor.",
  2924. token, token.value);
  2925. }
  2926. this.first = c;
  2927. return this;
  2928. });
  2929. syntax["new"].exps = true;
  2930. prefix("void").exps = true;
  2931. infix(".", function (left, that) {
  2932. adjacent(prevtoken, token);
  2933. nobreak();
  2934. var m = identifier();
  2935. if (typeof m === "string") {
  2936. countMember(m);
  2937. }
  2938. that.left = left;
  2939. that.right = m;
  2940. if (left && left.value === "arguments" && (m === "callee" || m === "caller")) {
  2941. if (option.noarg)
  2942. warning("Avoid arguments.{a}.", left, m);
  2943. else if (directive["use strict"])
  2944. error("Strict violation.");
  2945. } else if (!option.evil && left && left.value === "document" &&
  2946. (m === "write" || m === "writeln")) {
  2947. warning("document.write can be a form of eval.", left);
  2948. }
  2949. if (!option.evil && (m === "eval" || m === "execScript")) {
  2950. warning("eval is evil.");
  2951. }
  2952. return that;
  2953. }, 160, true);
  2954. infix("(", function (left, that) {
  2955. if (prevtoken.id !== "}" && prevtoken.id !== ")") {
  2956. nobreak(prevtoken, token);
  2957. }
  2958. nospace();
  2959. if (option.immed && !left.immed && left.id === "function") {
  2960. warning("Wrap an immediate function invocation in parentheses " +
  2961. "to assist the reader in understanding that the expression " +
  2962. "is the result of a function, and not the function itself.");
  2963. }
  2964. var n = 0,
  2965. p = [];
  2966. if (left) {
  2967. if (left.type === "(identifier)") {
  2968. if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) {
  2969. if ("Number String Boolean Date Object".indexOf(left.value) === -1) {
  2970. if (left.value === "Math") {
  2971. warning("Math is not a function.", left);
  2972. } else if (option.newcap) {
  2973. warning("Missing 'new' prefix when invoking a constructor.", left);
  2974. }
  2975. }
  2976. }
  2977. }
  2978. }
  2979. if (nexttoken.id !== ")") {
  2980. for (;;) {
  2981. p[p.length] = expression(10);
  2982. n += 1;
  2983. if (nexttoken.id !== ",") {
  2984. break;
  2985. }
  2986. comma();
  2987. }
  2988. }
  2989. advance(")");
  2990. nospace(prevtoken, token);
  2991. if (typeof left === "object") {
  2992. if (left.value === "parseInt" && n === 1) {
  2993. warning("Missing radix parameter.", token);
  2994. }
  2995. if (!option.evil) {
  2996. if (left.value === "eval" || left.value === "Function" ||
  2997. left.value === "execScript") {
  2998. warning("eval is evil.", left);
  2999. if (p[0] && [0].id === "(string)") {
  3000. addInternalSrc(left, p[0].value);
  3001. }
  3002. } else if (p[0] && p[0].id === "(string)" &&
  3003. (left.value === "setTimeout" ||
  3004. left.value === "setInterval")) {
  3005. warning(
  3006. "Implied eval is evil. Pass a function instead of a string.", left);
  3007. addInternalSrc(left, p[0].value);
  3008. // window.setTimeout/setInterval
  3009. } else if (p[0] && p[0].id === "(string)" &&
  3010. left.value === "." &&
  3011. left.left.value === "window" &&
  3012. (left.right === "setTimeout" ||
  3013. left.right === "setInterval")) {
  3014. warning(
  3015. "Implied eval is evil. Pass a function instead of a string.", left);
  3016. addInternalSrc(left, p[0].value);
  3017. }
  3018. }
  3019. if (!left.identifier && left.id !== "." && left.id !== "[" &&
  3020. left.id !== "(" && left.id !== "&&" && left.id !== "||" &&
  3021. left.id !== "?") {
  3022. warning("Bad invocation.", left);
  3023. }
  3024. }
  3025. that.left = left;
  3026. return that;
  3027. }, 155, true).exps = true;
  3028. prefix("(", function () {
  3029. nospace();
  3030. if (nexttoken.id === "function") {
  3031. nexttoken.immed = true;
  3032. }
  3033. var v = expression(0);
  3034. advance(")", this);
  3035. nospace(prevtoken, token);
  3036. if (option.immed && v.id === "function") {
  3037. if (nexttoken.id !== "(" &&
  3038. (nexttoken.id !== "." || (peek().value !== "call" && peek().value !== "apply"))) {
  3039. warning(
  3040. "Do not wrap function literals in parens unless they are to be immediately invoked.",
  3041. this);
  3042. }
  3043. }
  3044. return v;
  3045. });
  3046. infix("[", function (left, that) {
  3047. nobreak(prevtoken, token);
  3048. nospace();
  3049. var e = expression(0), s;
  3050. if (e && e.type === "(string)") {
  3051. if (!option.evil && (e.value === "eval" || e.value === "execScript")) {
  3052. warning("eval is evil.", that);
  3053. }
  3054. countMember(e.value);
  3055. if (!option.sub && ix.test(e.value)) {
  3056. s = syntax[e.value];
  3057. if (!s || !s.reserved) {
  3058. warning("['{a}'] is better written in dot notation.",
  3059. prevtoken, e.value);
  3060. }
  3061. }
  3062. }
  3063. advance("]", that);
  3064. nospace(prevtoken, token);
  3065. that.left = left;
  3066. that.right = e;
  3067. return that;
  3068. }, 160, true);
  3069. prefix("[", function () {
  3070. var b = token.line !== nexttoken.line;
  3071. this.first = [];
  3072. if (b) {
  3073. indent += option.indent;
  3074. if (nexttoken.from === indent + option.indent) {
  3075. indent += option.indent;
  3076. }
  3077. }
  3078. while (nexttoken.id !== "(end)") {
  3079. while (nexttoken.id === ",") {
  3080. if (!option.es5)
  3081. warning("Extra comma.");
  3082. advance(",");
  3083. }
  3084. if (nexttoken.id === "]") {
  3085. break;
  3086. }
  3087. if (b && token.line !== nexttoken.line) {
  3088. indentation();
  3089. }
  3090. this.first.push(expression(10));
  3091. if (nexttoken.id === ",") {
  3092. comma();
  3093. if (nexttoken.id === "]" && !option.es5) {
  3094. warning("Extra comma.", token);
  3095. break;
  3096. }
  3097. } else {
  3098. break;
  3099. }
  3100. }
  3101. if (b) {
  3102. indent -= option.indent;
  3103. indentation();
  3104. }
  3105. advance("]", this);
  3106. return this;
  3107. }, 160);
  3108. function property_name() {
  3109. var id = optionalidentifier(true);
  3110. if (!id) {
  3111. if (nexttoken.id === "(string)") {
  3112. id = nexttoken.value;
  3113. advance();
  3114. } else if (nexttoken.id === "(number)") {
  3115. id = nexttoken.value.toString();
  3116. advance();
  3117. }
  3118. }
  3119. return id;
  3120. }
  3121. function functionparams() {
  3122. var next = nexttoken;
  3123. var params = [];
  3124. var ident;
  3125. advance("(");
  3126. nospace();
  3127. if (nexttoken.id === ")") {
  3128. advance(")");
  3129. return;
  3130. }
  3131. for (;;) {
  3132. ident = identifier(true);
  3133. params.push(ident);
  3134. addlabel(ident, "unused", token);
  3135. if (nexttoken.id === ",") {
  3136. comma();
  3137. } else {
  3138. advance(")", next);
  3139. nospace(prevtoken, token);
  3140. return params;
  3141. }
  3142. }
  3143. }
  3144. function doFunction(name, statement) {
  3145. var f;
  3146. var oldOption = option;
  3147. var oldScope = scope;
  3148. option = Object.create(option);
  3149. scope = Object.create(scope);
  3150. funct = {
  3151. "(name)" : name || "\"" + anonname + "\"",
  3152. "(line)" : nexttoken.line,
  3153. "(character)": nexttoken.character,
  3154. "(context)" : funct,
  3155. "(breakage)" : 0,
  3156. "(loopage)" : 0,
  3157. "(metrics)" : createMetrics(nexttoken),
  3158. "(scope)" : scope,
  3159. "(statement)": statement,
  3160. "(tokens)" : {}
  3161. };
  3162. f = funct;
  3163. token.funct = funct;
  3164. functions.push(funct);
  3165. if (name) {
  3166. addlabel(name, "function");
  3167. }
  3168. funct["(params)"] = functionparams();
  3169. funct["(metrics)"].verifyMaxParametersPerFunction(funct["(params)"]);
  3170. block(false, false, true);
  3171. funct["(metrics)"].verifyMaxStatementsPerFunction();
  3172. funct["(metrics)"].verifyMaxComplexityPerFunction();
  3173. scope = oldScope;
  3174. option = oldOption;
  3175. funct["(last)"] = token.line;
  3176. funct["(lastcharacter)"] = token.character;
  3177. funct = funct["(context)"];
  3178. return f;
  3179. }
  3180. function createMetrics(functionStartToken) {
  3181. return {
  3182. statementCount: 0,
  3183. nestedBlockDepth: -1,
  3184. ComplexityCount: 1,
  3185. verifyMaxStatementsPerFunction: function () {
  3186. if (option.maxstatements &&
  3187. this.statementCount > option.maxstatements) {
  3188. var message = "Too many statements per function (" + this.statementCount + ").";
  3189. warning(message, functionStartToken);
  3190. }
  3191. },
  3192. verifyMaxParametersPerFunction: function (params) {
  3193. params = params || [];
  3194. if (option.maxparams && params.length > option.maxparams) {
  3195. var message = "Too many parameters per function (" + params.length + ").";
  3196. warning(message, functionStartToken);
  3197. }
  3198. },
  3199. verifyMaxNestedBlockDepthPerFunction: function () {
  3200. if (option.maxdepth &&
  3201. this.nestedBlockDepth > 0 &&
  3202. this.nestedBlockDepth === option.maxdepth + 1) {
  3203. var message = "Blocks are nested too deeply (" + this.nestedBlockDepth + ").";
  3204. warning(message);
  3205. }
  3206. },
  3207. verifyMaxComplexityPerFunction: function () {
  3208. var max = option.maxcomplexity;
  3209. var cc = this.ComplexityCount;
  3210. if (max && cc > max) {
  3211. var message = "Cyclomatic complexity is too high per function (" + cc + ").";
  3212. warning(message, functionStartToken);
  3213. }
  3214. }
  3215. };
  3216. }
  3217. function increaseComplexityCount() {
  3218. funct["(metrics)"].ComplexityCount += 1;
  3219. }
  3220. (function (x) {
  3221. x.nud = function () {
  3222. var b, f, i, p, t;
  3223. var props = {}; // All properties, including accessors
  3224. function saveProperty(name, token) {
  3225. if (props[name] && is_own(props, name))
  3226. warning("Duplicate member '{a}'.", nexttoken, i);
  3227. else
  3228. props[name] = {};
  3229. props[name].basic = true;
  3230. props[name].basicToken = token;
  3231. }
  3232. function saveSetter(name, token) {
  3233. if (props[name] && is_own(props, name)) {
  3234. if (props[name].basic || props[name].setter)
  3235. warning("Duplicate member '{a}'.", nexttoken, i);
  3236. } else {
  3237. props[name] = {};
  3238. }
  3239. props[name].setter = true;
  3240. props[name].setterToken = token;
  3241. }
  3242. function saveGetter(name) {
  3243. if (props[name] && is_own(props, name)) {
  3244. if (props[name].basic || props[name].getter)
  3245. warning("Duplicate member '{a}'.", nexttoken, i);
  3246. } else {
  3247. props[name] = {};
  3248. }
  3249. props[name].getter = true;
  3250. props[name].getterToken = token;
  3251. }
  3252. b = token.line !== nexttoken.line;
  3253. if (b) {
  3254. indent += option.indent;
  3255. if (nexttoken.from === indent + option.indent) {
  3256. indent += option.indent;
  3257. }
  3258. }
  3259. for (;;) {
  3260. if (nexttoken.id === "}") {
  3261. break;
  3262. }
  3263. if (b) {
  3264. indentation();
  3265. }
  3266. if (nexttoken.value === "get" && peek().id !== ":") {
  3267. advance("get");
  3268. if (!option.es5) {
  3269. error("get/set are ES5 features.");
  3270. }
  3271. i = property_name();
  3272. if (!i) {
  3273. error("Missing property name.");
  3274. }
  3275. saveGetter(i);
  3276. t = nexttoken;
  3277. adjacent(token, nexttoken);
  3278. f = doFunction();
  3279. p = f["(params)"];
  3280. if (p) {
  3281. warning("Unexpected parameter '{a}' in get {b} function.", t, p[0], i);
  3282. }
  3283. adjacent(token, nexttoken);
  3284. } else if (nexttoken.value === "set" && peek().id !== ":") {
  3285. advance("set");
  3286. if (!option.es5) {
  3287. error("get/set are ES5 features.");
  3288. }
  3289. i = property_name();
  3290. if (!i) {
  3291. error("Missing property name.");
  3292. }
  3293. saveSetter(i, nexttoken);
  3294. t = nexttoken;
  3295. adjacent(token, nexttoken);
  3296. f = doFunction();
  3297. p = f["(params)"];
  3298. if (!p || p.length !== 1) {
  3299. warning("Expected a single parameter in set {a} function.", t, i);
  3300. }
  3301. } else {
  3302. i = property_name();
  3303. saveProperty(i, nexttoken);
  3304. if (typeof i !== "string") {
  3305. break;
  3306. }
  3307. advance(":");
  3308. nonadjacent(token, nexttoken);
  3309. expression(10);
  3310. }
  3311. countMember(i);
  3312. if (nexttoken.id === ",") {
  3313. comma();
  3314. if (nexttoken.id === ",") {
  3315. warning("Extra comma.", token);
  3316. } else if (nexttoken.id === "}" && !option.es5) {
  3317. warning("Extra comma.", token);
  3318. }
  3319. } else {
  3320. break;
  3321. }
  3322. }
  3323. if (b) {
  3324. indent -= option.indent;
  3325. indentation();
  3326. }
  3327. advance("}", this);
  3328. // Check for lonely setters if in the ES5 mode.
  3329. if (option.es5) {
  3330. for (var name in props) {
  3331. if (is_own(props, name) && props[name].setter && !props[name].getter) {
  3332. warning("Setter is defined without getter.", props[name].setterToken);
  3333. }
  3334. }
  3335. }
  3336. return this;
  3337. };
  3338. x.fud = function () {
  3339. error("Expected to see a statement and instead saw a block.", token);
  3340. };
  3341. }(delim("{")));
  3342. // This Function is called when esnext option is set to true
  3343. // it adds the `const` statement to JSHINT
  3344. useESNextSyntax = function () {
  3345. var conststatement = stmt("const", function (prefix) {
  3346. var id, name, value;
  3347. this.first = [];
  3348. for (;;) {
  3349. nonadjacent(token, nexttoken);
  3350. id = identifier();
  3351. if (funct[id] === "const") {
  3352. warning("const '" + id + "' has already been declared");
  3353. }
  3354. if (funct["(global)"] && predefined[id] === false) {
  3355. warning("Redefinition of '{a}'.", token, id);
  3356. }
  3357. addlabel(id, "const");
  3358. if (prefix) {
  3359. break;
  3360. }
  3361. name = token;
  3362. this.first.push(token);
  3363. if (nexttoken.id !== "=") {
  3364. warning("const " +
  3365. "'{a}' is initialized to 'undefined'.", token, id);
  3366. }
  3367. if (nexttoken.id === "=") {
  3368. nonadjacent(token, nexttoken);
  3369. advance("=");
  3370. nonadjacent(token, nexttoken);
  3371. if (nexttoken.id === "undefined") {
  3372. warning("It is not necessary to initialize " +
  3373. "'{a}' to 'undefined'.", token, id);
  3374. }
  3375. if (peek(0).id === "=" && nexttoken.identifier) {
  3376. error("Constant {a} was not declared correctly.",
  3377. nexttoken, nexttoken.value);
  3378. }
  3379. value = expression(0);
  3380. name.first = value;
  3381. }
  3382. if (nexttoken.id !== ",") {
  3383. break;
  3384. }
  3385. comma();
  3386. }
  3387. return this;
  3388. });
  3389. conststatement.exps = true;
  3390. };
  3391. var varstatement = stmt("var", function (prefix) {
  3392. // JavaScript does not have block scope. It only has function scope. So,
  3393. // declaring a variable in a block can have unexpected consequences.
  3394. var id, name, value;
  3395. if (funct["(onevar)"] && option.onevar) {
  3396. warning("Too many var statements.");
  3397. } else if (!funct["(global)"]) {
  3398. funct["(onevar)"] = true;
  3399. }
  3400. this.first = [];
  3401. for (;;) {
  3402. nonadjacent(token, nexttoken);
  3403. id = identifier();
  3404. if (option.esnext && funct[id] === "const") {
  3405. warning("const '" + id + "' has already been declared");
  3406. }
  3407. if (funct["(global)"] && predefined[id] === false) {
  3408. warning("Redefinition of '{a}'.", token, id);
  3409. }
  3410. addlabel(id, "unused", token);
  3411. if (prefix) {
  3412. break;
  3413. }
  3414. name = token;
  3415. this.first.push(token);
  3416. if (nexttoken.id === "=") {
  3417. nonadjacent(token, nexttoken);
  3418. advance("=");
  3419. nonadjacent(token, nexttoken);
  3420. if (nexttoken.id === "undefined") {
  3421. warning("It is not necessary to initialize '{a}' to 'undefined'.", token, id);
  3422. }
  3423. if (peek(0).id === "=" && nexttoken.identifier) {
  3424. error("Variable {a} was not declared correctly.",
  3425. nexttoken, nexttoken.value);
  3426. }
  3427. value = expression(0);
  3428. name.first = value;
  3429. }
  3430. if (nexttoken.id !== ",") {
  3431. break;
  3432. }
  3433. comma();
  3434. }
  3435. return this;
  3436. });
  3437. varstatement.exps = true;
  3438. blockstmt("function", function () {
  3439. if (inblock) {
  3440. warning("Function declarations should not be placed in blocks. " +
  3441. "Use a function expression or move the statement to the top of " +
  3442. "the outer function.", token);
  3443. }
  3444. var i = identifier();
  3445. if (option.esnext && funct[i] === "const") {
  3446. warning("const '" + i + "' has already been declared");
  3447. }
  3448. adjacent(token, nexttoken);
  3449. addlabel(i, "unction", token);
  3450. doFunction(i, { statement: true });
  3451. if (nexttoken.id === "(" && nexttoken.line === token.line) {
  3452. error(
  3453. "Function declarations are not invocable. Wrap the whole function invocation in parens.");
  3454. }
  3455. return this;
  3456. });
  3457. prefix("function", function () {
  3458. var i = optionalidentifier();
  3459. if (i) {
  3460. adjacent(token, nexttoken);
  3461. } else {
  3462. nonadjacent(token, nexttoken);
  3463. }
  3464. doFunction(i);
  3465. if (!option.loopfunc && funct["(loopage)"]) {
  3466. warning("Don't make functions within a loop.");
  3467. }
  3468. return this;
  3469. });
  3470. blockstmt("if", function () {
  3471. var t = nexttoken;
  3472. increaseComplexityCount();
  3473. advance("(");
  3474. nonadjacent(this, t);
  3475. nospace();
  3476. expression(20);
  3477. if (nexttoken.id === "=") {
  3478. if (!option.boss)
  3479. warning("Expected a conditional expression and instead saw an assignment.");
  3480. advance("=");
  3481. expression(20);
  3482. }
  3483. advance(")", t);
  3484. nospace(prevtoken, token);
  3485. block(true, true);
  3486. if (nexttoken.id === "else") {
  3487. nonadjacent(token, nexttoken);
  3488. advance("else");
  3489. if (nexttoken.id === "if" || nexttoken.id === "switch") {
  3490. statement(true);
  3491. } else {
  3492. block(true, true);
  3493. }
  3494. }
  3495. return this;
  3496. });
  3497. blockstmt("try", function () {
  3498. var b;
  3499. function doCatch() {
  3500. var oldScope = scope;
  3501. var e;
  3502. advance("catch");
  3503. nonadjacent(token, nexttoken);
  3504. advance("(");
  3505. scope = Object.create(oldScope);
  3506. e = nexttoken.value;
  3507. if (nexttoken.type !== "(identifier)") {
  3508. e = null;
  3509. warning("Expected an identifier and instead saw '{a}'.", nexttoken, e);
  3510. }
  3511. advance();
  3512. advance(")");
  3513. funct = {
  3514. "(name)" : "(catch)",
  3515. "(line)" : nexttoken.line,
  3516. "(character)": nexttoken.character,
  3517. "(context)" : funct,
  3518. "(breakage)" : funct["(breakage)"],
  3519. "(loopage)" : funct["(loopage)"],
  3520. "(scope)" : scope,
  3521. "(statement)": false,
  3522. "(metrics)" : createMetrics(nexttoken),
  3523. "(catch)" : true,
  3524. "(tokens)" : {}
  3525. };
  3526. if (e) {
  3527. addlabel(e, "exception");
  3528. }
  3529. token.funct = funct;
  3530. functions.push(funct);
  3531. block(false);
  3532. scope = oldScope;
  3533. funct["(last)"] = token.line;
  3534. funct["(lastcharacter)"] = token.character;
  3535. funct = funct["(context)"];
  3536. }
  3537. block(false);
  3538. if (nexttoken.id === "catch") {
  3539. increaseComplexityCount();
  3540. doCatch();
  3541. b = true;
  3542. }
  3543. if (nexttoken.id === "finally") {
  3544. advance("finally");
  3545. block(false);
  3546. return;
  3547. } else if (!b) {
  3548. error("Expected '{a}' and instead saw '{b}'.",
  3549. nexttoken, "catch", nexttoken.value);
  3550. }
  3551. return this;
  3552. });
  3553. blockstmt("while", function () {
  3554. var t = nexttoken;
  3555. funct["(breakage)"] += 1;
  3556. funct["(loopage)"] += 1;
  3557. increaseComplexityCount();
  3558. advance("(");
  3559. nonadjacent(this, t);
  3560. nospace();
  3561. expression(20);
  3562. if (nexttoken.id === "=") {
  3563. if (!option.boss)
  3564. warning("Expected a conditional expression and instead saw an assignment.");
  3565. advance("=");
  3566. expression(20);
  3567. }
  3568. advance(")", t);
  3569. nospace(prevtoken, token);
  3570. block(true, true);
  3571. funct["(breakage)"] -= 1;
  3572. funct["(loopage)"] -= 1;
  3573. return this;
  3574. }).labelled = true;
  3575. blockstmt("with", function () {
  3576. var t = nexttoken;
  3577. if (directive["use strict"]) {
  3578. error("'with' is not allowed in strict mode.", token);
  3579. } else if (!option.withstmt) {
  3580. warning("Don't use 'with'.", token);
  3581. }
  3582. advance("(");
  3583. nonadjacent(this, t);
  3584. nospace();
  3585. expression(0);
  3586. advance(")", t);
  3587. nospace(prevtoken, token);
  3588. block(true, true);
  3589. return this;
  3590. });
  3591. blockstmt("switch", function () {
  3592. var t = nexttoken,
  3593. g = false;
  3594. funct["(breakage)"] += 1;
  3595. advance("(");
  3596. nonadjacent(this, t);
  3597. nospace();
  3598. this.condition = expression(20);
  3599. advance(")", t);
  3600. nospace(prevtoken, token);
  3601. nonadjacent(token, nexttoken);
  3602. t = nexttoken;
  3603. advance("{");
  3604. nonadjacent(token, nexttoken);
  3605. indent += option.indent;
  3606. this.cases = [];
  3607. for (;;) {
  3608. switch (nexttoken.id) {
  3609. case "case":
  3610. switch (funct["(verb)"]) {
  3611. case "break":
  3612. case "case":
  3613. case "continue":
  3614. case "return":
  3615. case "switch":
  3616. case "throw":
  3617. break;
  3618. default:
  3619. // You can tell JSHint that you don't use break intentionally by
  3620. // adding a comment /* falls through */ on a line just before
  3621. // the next `case`.
  3622. if (!ft.test(lines[nexttoken.line - 2])) {
  3623. warning(
  3624. "Expected a 'break' statement before 'case'.",
  3625. token);
  3626. }
  3627. }
  3628. indentation(-option.indent);
  3629. advance("case");
  3630. this.cases.push(expression(20));
  3631. increaseComplexityCount();
  3632. g = true;
  3633. advance(":");
  3634. funct["(verb)"] = "case";
  3635. break;
  3636. case "default":
  3637. switch (funct["(verb)"]) {
  3638. case "break":
  3639. case "continue":
  3640. case "return":
  3641. case "throw":
  3642. break;
  3643. default:
  3644. if (!ft.test(lines[nexttoken.line - 2])) {
  3645. warning(
  3646. "Expected a 'break' statement before 'default'.",
  3647. token);
  3648. }
  3649. }
  3650. indentation(-option.indent);
  3651. advance("default");
  3652. g = true;
  3653. advance(":");
  3654. break;
  3655. case "}":
  3656. indent -= option.indent;
  3657. indentation();
  3658. advance("}", t);
  3659. if (this.cases.length === 1 || this.condition.id === "true" ||
  3660. this.condition.id === "false") {
  3661. if (!option.onecase)
  3662. warning("This 'switch' should be an 'if'.", this);
  3663. }
  3664. funct["(breakage)"] -= 1;
  3665. funct["(verb)"] = undefined;
  3666. return;
  3667. case "(end)":
  3668. error("Missing '{a}'.", nexttoken, "}");
  3669. return;
  3670. default:
  3671. if (g) {
  3672. switch (token.id) {
  3673. case ",":
  3674. error("Each value should have its own case label.");
  3675. return;
  3676. case ":":
  3677. g = false;
  3678. statements();
  3679. break;
  3680. default:
  3681. error("Missing ':' on a case clause.", token);
  3682. return;
  3683. }
  3684. } else {
  3685. if (token.id === ":") {
  3686. advance(":");
  3687. error("Unexpected '{a}'.", token, ":");
  3688. statements();
  3689. } else {
  3690. error("Expected '{a}' and instead saw '{b}'.",
  3691. nexttoken, "case", nexttoken.value);
  3692. return;
  3693. }
  3694. }
  3695. }
  3696. }
  3697. }).labelled = true;
  3698. stmt("debugger", function () {
  3699. if (!option.debug) {
  3700. warning("All 'debugger' statements should be removed.");
  3701. }
  3702. return this;
  3703. }).exps = true;
  3704. (function () {
  3705. var x = stmt("do", function () {
  3706. funct["(breakage)"] += 1;
  3707. funct["(loopage)"] += 1;
  3708. increaseComplexityCount();
  3709. this.first = block(true);
  3710. advance("while");
  3711. var t = nexttoken;
  3712. nonadjacent(token, t);
  3713. advance("(");
  3714. nospace();
  3715. expression(20);
  3716. if (nexttoken.id === "=") {
  3717. if (!option.boss)
  3718. warning("Expected a conditional expression and instead saw an assignment.");
  3719. advance("=");
  3720. expression(20);
  3721. }
  3722. advance(")", t);
  3723. nospace(prevtoken, token);
  3724. funct["(breakage)"] -= 1;
  3725. funct["(loopage)"] -= 1;
  3726. return this;
  3727. });
  3728. x.labelled = true;
  3729. x.exps = true;
  3730. }());
  3731. blockstmt("for", function () {
  3732. var s, t = nexttoken;
  3733. funct["(breakage)"] += 1;
  3734. funct["(loopage)"] += 1;
  3735. increaseComplexityCount();
  3736. advance("(");
  3737. nonadjacent(this, t);
  3738. nospace();
  3739. if (peek(nexttoken.id === "var" ? 1 : 0).id === "in") {
  3740. if (nexttoken.id === "var") {
  3741. advance("var");
  3742. varstatement.fud.call(varstatement, true);
  3743. } else {
  3744. switch (funct[nexttoken.value]) {
  3745. case "unused":
  3746. funct[nexttoken.value] = "var";
  3747. break;
  3748. case "var":
  3749. break;
  3750. default:
  3751. warning("Bad for in variable '{a}'.",
  3752. nexttoken, nexttoken.value);
  3753. }
  3754. advance();
  3755. }
  3756. advance("in");
  3757. expression(20);
  3758. advance(")", t);
  3759. s = block(true, true);
  3760. if (option.forin && s && (s.length > 1 || typeof s[0] !== "object" ||
  3761. s[0].value !== "if")) {
  3762. warning("The body of a for in should be wrapped in an if statement to filter " +
  3763. "unwanted properties from the prototype.", this);
  3764. }
  3765. funct["(breakage)"] -= 1;
  3766. funct["(loopage)"] -= 1;
  3767. return this;
  3768. } else {
  3769. if (nexttoken.id !== ";") {
  3770. if (nexttoken.id === "var") {
  3771. advance("var");
  3772. varstatement.fud.call(varstatement);
  3773. } else {
  3774. for (;;) {
  3775. expression(0, "for");
  3776. if (nexttoken.id !== ",") {
  3777. break;
  3778. }
  3779. comma();
  3780. }
  3781. }
  3782. }
  3783. nolinebreak(token);
  3784. advance(";");
  3785. if (nexttoken.id !== ";") {
  3786. expression(20);
  3787. if (nexttoken.id === "=") {
  3788. if (!option.boss)
  3789. warning("Expected a conditional expression and instead saw an assignment.");
  3790. advance("=");
  3791. expression(20);
  3792. }
  3793. }
  3794. nolinebreak(token);
  3795. advance(";");
  3796. if (nexttoken.id === ";") {
  3797. error("Expected '{a}' and instead saw '{b}'.",
  3798. nexttoken, ")", ";");
  3799. }
  3800. if (nexttoken.id !== ")") {
  3801. for (;;) {
  3802. expression(0, "for");
  3803. if (nexttoken.id !== ",") {
  3804. break;
  3805. }
  3806. comma();
  3807. }
  3808. }
  3809. advance(")", t);
  3810. nospace(prevtoken, token);
  3811. block(true, true);
  3812. funct["(breakage)"] -= 1;
  3813. funct["(loopage)"] -= 1;
  3814. return this;
  3815. }
  3816. }).labelled = true;
  3817. stmt("break", function () {
  3818. var v = nexttoken.value;
  3819. if (funct["(breakage)"] === 0)
  3820. warning("Unexpected '{a}'.", nexttoken, this.value);
  3821. if (!option.asi)
  3822. nolinebreak(this);
  3823. if (nexttoken.id !== ";") {
  3824. if (token.line === nexttoken.line) {
  3825. if (funct[v] !== "label") {
  3826. warning("'{a}' is not a statement label.", nexttoken, v);
  3827. } else if (scope[v] !== funct) {
  3828. warning("'{a}' is out of scope.", nexttoken, v);
  3829. }
  3830. this.first = nexttoken;
  3831. advance();
  3832. }
  3833. }
  3834. reachable("break");
  3835. return this;
  3836. }).exps = true;
  3837. stmt("continue", function () {
  3838. var v = nexttoken.value;
  3839. if (funct["(breakage)"] === 0)
  3840. warning("Unexpected '{a}'.", nexttoken, this.value);
  3841. if (!option.asi)
  3842. nolinebreak(this);
  3843. if (nexttoken.id !== ";") {
  3844. if (token.line === nexttoken.line) {
  3845. if (funct[v] !== "label") {
  3846. warning("'{a}' is not a statement label.", nexttoken, v);
  3847. } else if (scope[v] !== funct) {
  3848. warning("'{a}' is out of scope.", nexttoken, v);
  3849. }
  3850. this.first = nexttoken;
  3851. advance();
  3852. }
  3853. } else if (!funct["(loopage)"]) {
  3854. warning("Unexpected '{a}'.", nexttoken, this.value);
  3855. }
  3856. reachable("continue");
  3857. return this;
  3858. }).exps = true;
  3859. stmt("return", function () {
  3860. if (this.line === nexttoken.line) {
  3861. if (nexttoken.id === "(regexp)")
  3862. warning("Wrap the /regexp/ literal in parens to disambiguate the slash operator.");
  3863. if (nexttoken.id !== ";" && !nexttoken.reach) {
  3864. nonadjacent(token, nexttoken);
  3865. if (peek().value === "=" && !option.boss) {
  3866. warningAt("Did you mean to return a conditional instead of an assignment?",
  3867. token.line, token.character + 1);
  3868. }
  3869. this.first = expression(0);
  3870. }
  3871. } else if (!option.asi) {
  3872. nolinebreak(this); // always warn (Line breaking error)
  3873. }
  3874. reachable("return");
  3875. return this;
  3876. }).exps = true;
  3877. stmt("throw", function () {
  3878. nolinebreak(this);
  3879. nonadjacent(token, nexttoken);
  3880. this.first = expression(20);
  3881. reachable("throw");
  3882. return this;
  3883. }).exps = true;
  3884. // Superfluous reserved words
  3885. reserve("class");
  3886. reserve("const");
  3887. reserve("enum");
  3888. reserve("export");
  3889. reserve("extends");
  3890. reserve("import");
  3891. reserve("super");
  3892. reserve("let");
  3893. reserve("yield");
  3894. reserve("implements");
  3895. reserve("interface");
  3896. reserve("package");
  3897. reserve("private");
  3898. reserve("protected");
  3899. reserve("public");
  3900. reserve("static");
  3901. // Parse JSON
  3902. function jsonValue() {
  3903. function jsonObject() {
  3904. var o = {}, t = nexttoken;
  3905. advance("{");
  3906. if (nexttoken.id !== "}") {
  3907. for (;;) {
  3908. if (nexttoken.id === "(end)") {
  3909. error("Missing '}' to match '{' from line {a}.",
  3910. nexttoken, t.line);
  3911. } else if (nexttoken.id === "}") {
  3912. warning("Unexpected comma.", token);
  3913. break;
  3914. } else if (nexttoken.id === ",") {
  3915. error("Unexpected comma.", nexttoken);
  3916. } else if (nexttoken.id !== "(string)") {
  3917. warning("Expected a string and instead saw {a}.",
  3918. nexttoken, nexttoken.value);
  3919. }
  3920. if (o[nexttoken.value] === true) {
  3921. warning("Duplicate key '{a}'.",
  3922. nexttoken, nexttoken.value);
  3923. } else if ((nexttoken.value === "__proto__" &&
  3924. !option.proto) || (nexttoken.value === "__iterator__" &&
  3925. !option.iterator)) {
  3926. warning("The '{a}' key may produce unexpected results.",
  3927. nexttoken, nexttoken.value);
  3928. } else {
  3929. o[nexttoken.value] = true;
  3930. }
  3931. advance();
  3932. advance(":");
  3933. jsonValue();
  3934. if (nexttoken.id !== ",") {
  3935. break;
  3936. }
  3937. advance(",");
  3938. }
  3939. }
  3940. advance("}");
  3941. }
  3942. function jsonArray() {
  3943. var t = nexttoken;
  3944. advance("[");
  3945. if (nexttoken.id !== "]") {
  3946. for (;;) {
  3947. if (nexttoken.id === "(end)") {
  3948. error("Missing ']' to match '[' from line {a}.",
  3949. nexttoken, t.line);
  3950. } else if (nexttoken.id === "]") {
  3951. warning("Unexpected comma.", token);
  3952. break;
  3953. } else if (nexttoken.id === ",") {
  3954. error("Unexpected comma.", nexttoken);
  3955. }
  3956. jsonValue();
  3957. if (nexttoken.id !== ",") {
  3958. break;
  3959. }
  3960. advance(",");
  3961. }
  3962. }
  3963. advance("]");
  3964. }
  3965. switch (nexttoken.id) {
  3966. case "{":
  3967. jsonObject();
  3968. break;
  3969. case "[":
  3970. jsonArray();
  3971. break;
  3972. case "true":
  3973. case "false":
  3974. case "null":
  3975. case "(number)":
  3976. case "(string)":
  3977. advance();
  3978. break;
  3979. case "-":
  3980. advance("-");
  3981. if (token.character !== nexttoken.from) {
  3982. warning("Unexpected space after '-'.", token);
  3983. }
  3984. adjacent(token, nexttoken);
  3985. advance("(number)");
  3986. break;
  3987. default:
  3988. error("Expected a JSON value.", nexttoken);
  3989. }
  3990. }
  3991. // The actual JSHINT function itself.
  3992. var itself = function (s, o, g) {
  3993. var a, i, k, x;
  3994. var optionKeys;
  3995. var newOptionObj = {};
  3996. if (o && o.scope) {
  3997. JSHINT.scope = o.scope;
  3998. } else {
  3999. JSHINT.errors = [];
  4000. JSHINT.undefs = [];
  4001. JSHINT.internals = [];
  4002. JSHINT.blacklist = {};
  4003. JSHINT.scope = "(main)";
  4004. }
  4005. predefined = Object.create(standard);
  4006. declared = Object.create(null);
  4007. combine(predefined, g || {});
  4008. if (o) {
  4009. a = o.predef;
  4010. if (a) {
  4011. if (!Array.isArray(a) && typeof a === "object") {
  4012. a = Object.keys(a);
  4013. }
  4014. a.forEach(function (item) {
  4015. var slice;
  4016. if (item[0] === "-") {
  4017. slice = item.slice(1);
  4018. JSHINT.blacklist[slice] = slice;
  4019. } else {
  4020. predefined[item] = true;
  4021. }
  4022. });
  4023. }
  4024. optionKeys = Object.keys(o);
  4025. for (x = 0; x < optionKeys.length; x++) {
  4026. newOptionObj[optionKeys[x]] = o[optionKeys[x]];
  4027. if (optionKeys[x] === "newcap" && o[optionKeys[x]] === false)
  4028. newOptionObj["(explicitNewcap)"] = true;
  4029. if (optionKeys[x] === "indent")
  4030. newOptionObj.white = true;
  4031. }
  4032. }
  4033. option = newOptionObj;
  4034. option.indent = option.indent || 4;
  4035. option.maxerr = option.maxerr || 50;
  4036. tab = "";
  4037. for (i = 0; i < option.indent; i += 1) {
  4038. tab += " ";
  4039. }
  4040. indent = 1;
  4041. global = Object.create(predefined);
  4042. scope = global;
  4043. funct = {
  4044. "(global)": true,
  4045. "(name)": "(global)",
  4046. "(scope)": scope,
  4047. "(breakage)": 0,
  4048. "(loopage)": 0,
  4049. "(tokens)": {},
  4050. "(metrics)": createMetrics(nexttoken)
  4051. };
  4052. functions = [funct];
  4053. urls = [];
  4054. stack = null;
  4055. member = {};
  4056. membersOnly = null;
  4057. implied = {};
  4058. inblock = false;
  4059. lookahead = [];
  4060. jsonmode = false;
  4061. warnings = 0;
  4062. lines = [];
  4063. unuseds = [];
  4064. if (!isString(s) && !Array.isArray(s)) {
  4065. errorAt("Input is neither a string nor an array of strings.", 0);
  4066. return false;
  4067. }
  4068. if (isString(s) && /^\s*$/g.test(s)) {
  4069. errorAt("Input is an empty string.", 0);
  4070. return false;
  4071. }
  4072. if (s.length === 0) {
  4073. errorAt("Input is an empty array.", 0);
  4074. return false;
  4075. }
  4076. lex.init(s);
  4077. prereg = true;
  4078. directive = {};
  4079. prevtoken = token = nexttoken = syntax["(begin)"];
  4080. // Check options
  4081. for (var name in o) {
  4082. if (is_own(o, name)) {
  4083. checkOption(name, token);
  4084. }
  4085. }
  4086. assume();
  4087. // combine the passed globals after we've assumed all our options
  4088. combine(predefined, g || {});
  4089. //reset values
  4090. comma.first = true;
  4091. quotmark = undefined;
  4092. try {
  4093. advance();
  4094. switch (nexttoken.id) {
  4095. case "{":
  4096. case "[":
  4097. option.laxbreak = true;
  4098. jsonmode = true;
  4099. jsonValue();
  4100. break;
  4101. default:
  4102. directives();
  4103. if (directive["use strict"] && !option.globalstrict) {
  4104. warning("Use the function form of \"use strict\".", prevtoken);
  4105. }
  4106. statements();
  4107. }
  4108. advance((nexttoken && nexttoken.value !== ".") ? "(end)" : undefined);
  4109. var markDefined = function (name, context) {
  4110. do {
  4111. if (typeof context[name] === "string") {
  4112. // JSHINT marks unused variables as 'unused' and
  4113. // unused function declaration as 'unction'. This
  4114. // code changes such instances back 'var' and
  4115. // 'closure' so that the code in JSHINT.data()
  4116. // doesn't think they're unused.
  4117. if (context[name] === "unused")
  4118. context[name] = "var";
  4119. else if (context[name] === "unction")
  4120. context[name] = "closure";
  4121. return true;
  4122. }
  4123. context = context["(context)"];
  4124. } while (context);
  4125. return false;
  4126. };
  4127. var clearImplied = function (name, line) {
  4128. if (!implied[name])
  4129. return;
  4130. var newImplied = [];
  4131. for (var i = 0; i < implied[name].length; i += 1) {
  4132. if (implied[name][i] !== line)
  4133. newImplied.push(implied[name][i]);
  4134. }
  4135. if (newImplied.length === 0)
  4136. delete implied[name];
  4137. else
  4138. implied[name] = newImplied;
  4139. };
  4140. var warnUnused = function (name, token) {
  4141. var line = token.line;
  4142. var chr = token.character;
  4143. if (option.unused)
  4144. warningAt("'{a}' is defined but never used.", line, chr, name);
  4145. unuseds.push({
  4146. name: name,
  4147. line: line,
  4148. character: chr
  4149. });
  4150. };
  4151. var checkUnused = function (func, key) {
  4152. var type = func[key];
  4153. var token = func["(tokens)"][key];
  4154. if (key.charAt(0) === "(")
  4155. return;
  4156. if (type !== "unused" && type !== "unction")
  4157. return;
  4158. // Params are checked separately from other variables.
  4159. if (func["(params)"] && func["(params)"].indexOf(key) !== -1)
  4160. return;
  4161. warnUnused(key, token);
  4162. };
  4163. // Check queued 'x is not defined' instances to see if they're still undefined.
  4164. for (i = 0; i < JSHINT.undefs.length; i += 1) {
  4165. k = JSHINT.undefs[i].slice(0);
  4166. if (markDefined(k[2].value, k[0])) {
  4167. clearImplied(k[2].value, k[2].line);
  4168. } else {
  4169. warning.apply(warning, k.slice(1));
  4170. }
  4171. }
  4172. functions.forEach(function (func) {
  4173. for (var key in func) {
  4174. if (is_own(func, key)) {
  4175. checkUnused(func, key);
  4176. }
  4177. }
  4178. if (!func["(params)"])
  4179. return;
  4180. var params = func["(params)"].slice();
  4181. var param = params.pop();
  4182. var type;
  4183. while (param) {
  4184. type = func[param];
  4185. // 'undefined' is a special case for (function (window, undefined) { ... })();
  4186. // patterns.
  4187. if (param === "undefined")
  4188. return;
  4189. if (type !== "unused" && type !== "unction")
  4190. return;
  4191. warnUnused(param, func["(tokens)"][param]);
  4192. param = params.pop();
  4193. }
  4194. });
  4195. for (var key in declared) {
  4196. if (is_own(declared, key) && !is_own(global, key)) {
  4197. warnUnused(key, declared[key]);
  4198. }
  4199. }
  4200. } catch (e) {
  4201. if (e) {
  4202. var nt = nexttoken || {};
  4203. JSHINT.errors.push({
  4204. raw : e.raw,
  4205. reason : e.message,
  4206. line : e.line || nt.line,
  4207. character : e.character || nt.from
  4208. }, null);
  4209. }
  4210. }
  4211. // Loop over the listed "internals", and check them as well.
  4212. if (JSHINT.scope === "(main)") {
  4213. o = o || {};
  4214. for (i = 0; i < JSHINT.internals.length; i += 1) {
  4215. k = JSHINT.internals[i];
  4216. o.scope = k.elem;
  4217. itself(k.value, o, g);
  4218. }
  4219. }
  4220. return JSHINT.errors.length === 0;
  4221. };
  4222. // Data summary.
  4223. itself.data = function () {
  4224. var data = {
  4225. functions: [],
  4226. options: option
  4227. };
  4228. var implieds = [];
  4229. var members = [];
  4230. var fu, f, i, j, n, globals;
  4231. if (itself.errors.length) {
  4232. data.errors = itself.errors;
  4233. }
  4234. if (jsonmode) {
  4235. data.json = true;
  4236. }
  4237. for (n in implied) {
  4238. if (is_own(implied, n)) {
  4239. implieds.push({
  4240. name: n,
  4241. line: implied[n]
  4242. });
  4243. }
  4244. }
  4245. if (implieds.length > 0) {
  4246. data.implieds = implieds;
  4247. }
  4248. if (urls.length > 0) {
  4249. data.urls = urls;
  4250. }
  4251. globals = Object.keys(scope);
  4252. if (globals.length > 0) {
  4253. data.globals = globals;
  4254. }
  4255. for (i = 1; i < functions.length; i += 1) {
  4256. f = functions[i];
  4257. fu = {};
  4258. for (j = 0; j < functionicity.length; j += 1) {
  4259. fu[functionicity[j]] = [];
  4260. }
  4261. for (j = 0; j < functionicity.length; j += 1) {
  4262. if (fu[functionicity[j]].length === 0) {
  4263. delete fu[functionicity[j]];
  4264. }
  4265. }
  4266. fu.name = f["(name)"];
  4267. fu.param = f["(params)"];
  4268. fu.line = f["(line)"];
  4269. fu.character = f["(character)"];
  4270. fu.last = f["(last)"];
  4271. fu.lastcharacter = f["(lastcharacter)"];
  4272. data.functions.push(fu);
  4273. }
  4274. if (unuseds.length > 0) {
  4275. data.unused = unuseds;
  4276. }
  4277. members = [];
  4278. for (n in member) {
  4279. if (typeof member[n] === "number") {
  4280. data.member = member;
  4281. break;
  4282. }
  4283. }
  4284. return data;
  4285. };
  4286. itself.jshint = itself;
  4287. return itself;
  4288. }());
  4289. // Make JSHINT a Node module, if possible.
  4290. if (typeof exports === "object" && exports) {
  4291. exports.JSHINT = JSHINT;
  4292. }