jshint.js 150 KB

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