fulljslint.js 183 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291
  1. // jslint.js
  2. // 2009-08-01
  3. /*
  4. Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
  5. Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. this software and associated documentation files (the "Software"), to deal in
  7. the Software without restriction, including without limitation the rights to
  8. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  9. of the Software, and to permit persons to whom the Software is furnished to do
  10. so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in all
  12. copies or substantial portions of the Software.
  13. The Software shall be used for Good, not Evil.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. SOFTWARE.
  21. */
  22. /*
  23. JSLINT is a global function. It takes two parameters.
  24. var myResult = JSLINT(source, option);
  25. The first parameter is either a string or an array of strings. If it is a
  26. string, it will be split on '\n' or '\r'. If it is an array of strings, it
  27. is assumed that each string represents one line. The source can be a
  28. JavaScript text, or HTML text, or a Konfabulator text.
  29. The second parameter is an optional object of options which control the
  30. operation of JSLINT. Most of the options are booleans: They are all are
  31. optional and have a default value of false.
  32. If it checks out, JSLINT returns true. Otherwise, it returns false.
  33. If false, you can inspect JSLINT.errors to find out the problems.
  34. JSLINT.errors is an array of objects containing these members:
  35. {
  36. line : The line (relative to 0) at which the lint was found
  37. character : The character (relative to 0) at which the lint was found
  38. reason : The problem
  39. evidence : The text line in which the problem occurred
  40. raw : The raw message before the details were inserted
  41. a : The first detail
  42. b : The second detail
  43. c : The third detail
  44. d : The fourth detail
  45. }
  46. If a fatal error was found, a null will be the last element of the
  47. JSLINT.errors array.
  48. You can request a Function Report, which shows all of the functions
  49. and the parameters and vars that they use. This can be used to find
  50. implied global variables and other problems. The report is in HTML and
  51. can be inserted in an HTML <body>.
  52. var myReport = JSLINT.report(limited);
  53. If limited is true, then the report will be limited to only errors.
  54. You can request a data structure which contains JSLint's results.
  55. var myData = JSLINT.data();
  56. It returns a structure with this form:
  57. {
  58. errors: [
  59. {
  60. line: NUMBER,
  61. character: NUMBER,
  62. reason: STRING,
  63. evidence: STRING
  64. }
  65. ],
  66. functions: [
  67. name: STRING,
  68. line: NUMBER,
  69. last: NUMBER,
  70. param: [
  71. STRING
  72. ],
  73. closure: [
  74. STRING
  75. ],
  76. var: [
  77. STRING
  78. ],
  79. exception: [
  80. STRING
  81. ],
  82. outer: [
  83. STRING
  84. ],
  85. unused: [
  86. STRING
  87. ],
  88. global: [
  89. STRING
  90. ],
  91. label: [
  92. STRING
  93. ]
  94. ],
  95. globals: [
  96. STRING
  97. ],
  98. member: {
  99. STRING: NUMBER
  100. },
  101. unuseds: [
  102. {
  103. name: STRING,
  104. line: NUMBER
  105. }
  106. ],
  107. implieds: [
  108. {
  109. name: STRING,
  110. line: NUMBER
  111. }
  112. ],
  113. urls: [
  114. STRING
  115. ],
  116. json: BOOLEAN
  117. }
  118. Empty arrays will not be included.
  119. */
  120. /*jslint
  121. evil: true, nomen: false, onevar: false, regexp: false, strict: true
  122. */
  123. /*members "\b", "\t", "\n", "\f", "\r", "\"", "%", "(begin)",
  124. "(breakage)", "(context)", "(error)", "(global)", "(identifier)",
  125. "(last)", "(line)", "(loopage)", "(name)", "(onevar)", "(param)",
  126. "(params)", "(scope)", "(verb)", "++", "--", "\/", ADSAFE, Array,
  127. Boolean, COM, Canvas, CustomAnimation, Date, Debug, E, Error, EvalError,
  128. FadeAnimation, Flash, FormField, Frame, Function, HotKey, Image, JSON,
  129. LN10, LN2, LOG10E, LOG2E, MAX_VALUE, MIN_VALUE, Math, MenuItem,
  130. MoveAnimation, NEGATIVE_INFINITY, Number, Object, Option, PI,
  131. POSITIVE_INFINITY, Point, RangeError, Rectangle, ReferenceError, RegExp,
  132. ResizeAnimation, RotateAnimation, SQRT1_2, SQRT2, ScrollBar, String,
  133. Style, SyntaxError, System, Text, TextArea, Timer, TypeError, URIError,
  134. URL, Web, Window, XMLDOM, XMLHttpRequest, "\\", a, abbr, acronym,
  135. addEventListener, address, adsafe, alert, aliceblue, animator,
  136. antiquewhite, appleScript, applet, apply, approved, aqua, aquamarine,
  137. area, arguments, arity, autocomplete, azure, b, background,
  138. "background-attachment", "background-color", "background-image",
  139. "background-position", "background-repeat", base, bdo, beep, beige, big,
  140. bisque, bitwise, black, blanchedalmond, block, blockquote, blue,
  141. blueviolet, blur, body, border, "border-bottom", "border-bottom-color",
  142. "border-bottom-style", "border-bottom-width", "border-collapse",
  143. "border-color", "border-left", "border-left-color", "border-left-style",
  144. "border-left-width", "border-right", "border-right-color",
  145. "border-right-style", "border-right-width", "border-spacing",
  146. "border-style", "border-top", "border-top-color", "border-top-style",
  147. "border-top-width", "border-width", bottom, br, brown, browser,
  148. burlywood, button, bytesToUIString, c, cadetblue, call, callee, caller,
  149. canvas, cap, caption, "caption-side", cases, center, charAt, charCodeAt,
  150. character, chartreuse, chocolate, chooseColor, chooseFile, chooseFolder,
  151. cite, clear, clearInterval, clearTimeout, clip, close, closeWidget,
  152. closed, closure, cm, code, col, colgroup, color, comment, condition,
  153. confirm, console, constructor, content, convertPathToHFS,
  154. convertPathToPlatform, coral, cornflowerblue, cornsilk,
  155. "counter-increment", "counter-reset", create, crimson, css, cursor,
  156. cyan, d, darkblue, darkcyan, darkgoldenrod, darkgray, darkgreen,
  157. darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred,
  158. darksalmon, darkseagreen, darkslateblue, darkslategray, darkturquoise,
  159. darkviolet, data, dd, debug, decodeURI, decodeURIComponent, deeppink,
  160. deepskyblue, defaultStatus, defineClass, del, deserialize, dfn,
  161. dimension, dimgray, dir, direction, display, div, dl, document,
  162. dodgerblue, dt, edition, else, em, embed, empty, "empty-cells",
  163. encodeURI, encodeURIComponent, entityify, eqeqeq, errors, escape, eval,
  164. event, evidence, evil, ex, exception, exec, exps, fieldset, filesystem,
  165. firebrick, first, float, floor, floralwhite, focus, focusWidget, font,
  166. "font-face", "font-family", "font-size", "font-size-adjust",
  167. "font-stretch", "font-style", "font-variant", "font-weight",
  168. forestgreen, forin, form, fragment, frame, frames, frameset, from,
  169. fromCharCode, fuchsia, fud, funct, function, functions, g, gainsboro,
  170. gc, getComputedStyle, ghostwhite, global, globals, gold, goldenrod,
  171. gray, green, greenyellow, h1, h2, h3, h4, h5, h6, hasOwnProperty, head,
  172. height, help, history, honeydew, hotpink, hr, html, i, iTunes, id,
  173. identifier, iframe, img, immed, implieds, import, in, include, indent,
  174. indexOf, indianred, indigo, init, input, ins, isAlpha,
  175. isApplicationRunning, isDigit, isFinite, isNaN, ivory, join, json, kbd,
  176. khaki, konfabulatorVersion, label, labelled, lang, last, lavender,
  177. lavenderblush, lawngreen, laxbreak, lbp, led, left, legend,
  178. lemonchiffon, length, "letter-spacing", li, lib, lightblue, lightcoral,
  179. lightcyan, lightgoldenrodyellow, lightgreen, lightpink, lightsalmon,
  180. lightseagreen, lightskyblue, lightslategray, lightsteelblue,
  181. lightyellow, lime, limegreen, line, "line-height", linen, link,
  182. "list-style", "list-style-image", "list-style-position",
  183. "list-style-type", load, loadClass, location, log, m, magenta, map,
  184. margin, "margin-bottom", "margin-left", "margin-right", "margin-top",
  185. "marker-offset", maroon, match, "max-height", "max-width", md5, media,
  186. mediumaquamarine, mediumblue, mediumorchid, mediumpurple,
  187. mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise,
  188. mediumvioletred, member, menu, message, meta, midnightblue,
  189. "min-height", "min-width", mintcream, mistyrose, mm, moccasin, moveBy,
  190. moveTo, name, navajowhite, navigator, navy, new, newcap, noframes,
  191. nomen, noscript, nud, object, ol, oldlace, olive, olivedrab, on, onblur,
  192. onerror, onevar, onfocus, onload, onresize, onunload, opacity, open,
  193. openURL, opener, opera, optgroup, option, orange, orangered, orchid,
  194. outer, outline, "outline-color", "outline-style", "outline-width",
  195. overflow, p, padding, "padding-bottom", "padding-left", "padding-right",
  196. "padding-top", page, "page-break-after", "page-break-before",
  197. palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip,
  198. param, params, parent, parseFloat, parseInt, passfail, pc, peachpuff,
  199. peru, pink, play, plum, plusplus, pop, popupMenu, position, powderblue,
  200. pre, predef, preferenceGroups, preferences, print, prompt, prototype,
  201. pt, purple, push, px, q, quit, quotes, random, range, raw, reach,
  202. readFile, readUrl, reason, red, regexp, reloadWidget,
  203. removeEventListener, replace, report, reserved, resizeBy, resizeTo,
  204. resolvePath, resumeUpdates, rhino, right, rosybrown, royalblue,
  205. runCommand, runCommandInBg, saddlebrown, safe, salmon, samp, sandybrown,
  206. saveAs, savePreferences, screen, script, scroll, scrollBy, scrollTo,
  207. seagreen, seal, search, seashell, select, serialize, setInterval,
  208. setTimeout, shift, showWidgetPreferences, sidebar, sienna, silver,
  209. skyblue, slateblue, slategray, sleep, slice, small, snow, sort, span,
  210. spawn, speak, split, springgreen, src, status, steelblue, strict,
  211. strong, style, styleproperty, sub, substr, sup, supplant,
  212. suppressUpdates, sync, system, table, "table-layout", tan, tbody, td,
  213. teal, tellWidget, test, "text-align", "text-decoration", "text-indent",
  214. "text-shadow", "text-transform", textarea, tfoot, th, thead, thistle,
  215. title, toLowerCase, toString, toUpperCase, toint32, token, tomato, top,
  216. tr, tt, turquoise, type, u, ul, undef, unescape, "unicode-bidi", unused,
  217. unwatch, updateNow, urls, value, valueOf, var, version,
  218. "vertical-align", violet, visibility, watch, wheat, white,
  219. "white-space", whitesmoke, widget, width, "word-spacing",
  220. yahooCheckLogin, yahooLogin, yahooLogout, yellow, yellowgreen,
  221. "z-index"
  222. */
  223. // We build the application inside a function so that we produce only a single
  224. // global variable. The function will be invoked, its return value is the JSLINT
  225. // application itself.
  226. "use strict";
  227. var JSLINT = (function () {
  228. var adsafe_id, // The widget's ADsafe id.
  229. adsafe_may, // The widget may load approved scripts.
  230. adsafe_went, // ADSAFE.go has been called.
  231. anonname, // The guessed name for anonymous functions.
  232. approved, // ADsafe approved urls.
  233. atrule = {
  234. 'import' : true,
  235. media : true,
  236. 'font-face': true,
  237. page : true
  238. },
  239. // These are members that should not be permitted in the safe subset.
  240. banned = { // the member names that ADsafe prohibits.
  241. 'arguments' : true,
  242. callee : true,
  243. caller : true,
  244. constructor : true,
  245. 'eval' : true,
  246. prototype : true,
  247. unwatch : true,
  248. valueOf : true,
  249. watch : true
  250. },
  251. // These are the JSLint boolean options.
  252. boolOptions = {
  253. adsafe : true, // if ADsafe should be enforced
  254. bitwise : true, // if bitwise operators should not be allowed
  255. browser : true, // if the standard browser globals should be predefined
  256. cap : true, // if upper case HTML should be allowed
  257. css : true, // if CSS workarounds should be tolerated
  258. debug : true, // if debugger statements should be allowed
  259. eqeqeq : true, // if === should be required
  260. evil : true, // if eval should be allowed
  261. forin : true, // if for in statements must filter
  262. fragment : true, // if HTML fragments should be allowed
  263. immed : true, // if immediate invocations must be wrapped in parens
  264. laxbreak : true, // if line breaks should not be checked
  265. newcap : true, // if constructor names must be capitalized
  266. nomen : true, // if names should be checked
  267. on : true, // if HTML event handlers should be allowed
  268. onevar : true, // if only one var statement per function should be allowed
  269. passfail : true, // if the scan should stop on first error
  270. plusplus : true, // if increment/decrement should not be allowed
  271. regexp : true, // if the . should not be allowed in regexp literals
  272. rhino : true, // if the Rhino environment globals should be predefined
  273. undef : true, // if variables should be declared before used
  274. safe : true, // if use of some browser features should be restricted
  275. sidebar : true, // if the System object should be predefined
  276. strict : true, // require the "use strict"; pragma
  277. sub : true, // if all forms of subscript notation are tolerated
  278. white : true, // if strict whitespace rules apply
  279. widget : true // if the Yahoo Widgets globals should be predefined
  280. },
  281. // browser contains a set of global names which are commonly provided by a
  282. // web browser environment.
  283. browser = {
  284. addEventListener: false,
  285. alert : false,
  286. blur : false,
  287. clearInterval : false,
  288. clearTimeout : false,
  289. close : false,
  290. closed : false,
  291. confirm : false,
  292. console : false,
  293. Debug : false,
  294. defaultStatus : false,
  295. document : false,
  296. event : false,
  297. focus : false,
  298. frames : false,
  299. getComputedStyle: false,
  300. history : false,
  301. Image : false,
  302. length : false,
  303. location : false,
  304. moveBy : false,
  305. moveTo : false,
  306. name : false,
  307. navigator : false,
  308. onblur : true,
  309. onerror : true,
  310. onfocus : true,
  311. onload : true,
  312. onresize : true,
  313. onunload : true,
  314. open : false,
  315. opener : false,
  316. opera : false,
  317. Option : false,
  318. parent : false,
  319. print : false,
  320. prompt : false,
  321. removeEventListener: false,
  322. resizeBy : false,
  323. resizeTo : false,
  324. screen : false,
  325. scroll : false,
  326. scrollBy : false,
  327. scrollTo : false,
  328. setInterval : false,
  329. setTimeout : false,
  330. status : false,
  331. top : false,
  332. XMLHttpRequest : false
  333. },
  334. cssAttributeData,
  335. cssAny,
  336. cssColorData = {
  337. "aliceblue" : true,
  338. "antiquewhite" : true,
  339. "aqua" : true,
  340. "aquamarine" : true,
  341. "azure" : true,
  342. "beige" : true,
  343. "bisque" : true,
  344. "black" : true,
  345. "blanchedalmond" : true,
  346. "blue" : true,
  347. "blueviolet" : true,
  348. "brown" : true,
  349. "burlywood" : true,
  350. "cadetblue" : true,
  351. "chartreuse" : true,
  352. "chocolate" : true,
  353. "coral" : true,
  354. "cornflowerblue" : true,
  355. "cornsilk" : true,
  356. "crimson" : true,
  357. "cyan" : true,
  358. "darkblue" : true,
  359. "darkcyan" : true,
  360. "darkgoldenrod" : true,
  361. "darkgray" : true,
  362. "darkgreen" : true,
  363. "darkkhaki" : true,
  364. "darkmagenta" : true,
  365. "darkolivegreen" : true,
  366. "darkorange" : true,
  367. "darkorchid" : true,
  368. "darkred" : true,
  369. "darksalmon" : true,
  370. "darkseagreen" : true,
  371. "darkslateblue" : true,
  372. "darkslategray" : true,
  373. "darkturquoise" : true,
  374. "darkviolet" : true,
  375. "deeppink" : true,
  376. "deepskyblue" : true,
  377. "dimgray" : true,
  378. "dodgerblue" : true,
  379. "firebrick" : true,
  380. "floralwhite" : true,
  381. "forestgreen" : true,
  382. "fuchsia" : true,
  383. "gainsboro" : true,
  384. "ghostwhite" : true,
  385. "gold" : true,
  386. "goldenrod" : true,
  387. "gray" : true,
  388. "green" : true,
  389. "greenyellow" : true,
  390. "honeydew" : true,
  391. "hotpink" : true,
  392. "indianred" : true,
  393. "indigo" : true,
  394. "ivory" : true,
  395. "khaki" : true,
  396. "lavender" : true,
  397. "lavenderblush" : true,
  398. "lawngreen" : true,
  399. "lemonchiffon" : true,
  400. "lightblue" : true,
  401. "lightcoral" : true,
  402. "lightcyan" : true,
  403. "lightgoldenrodyellow" : true,
  404. "lightgreen" : true,
  405. "lightpink" : true,
  406. "lightsalmon" : true,
  407. "lightseagreen" : true,
  408. "lightskyblue" : true,
  409. "lightslategray" : true,
  410. "lightsteelblue" : true,
  411. "lightyellow" : true,
  412. "lime" : true,
  413. "limegreen" : true,
  414. "linen" : true,
  415. "magenta" : true,
  416. "maroon" : true,
  417. "mediumaquamarine" : true,
  418. "mediumblue" : true,
  419. "mediumorchid" : true,
  420. "mediumpurple" : true,
  421. "mediumseagreen" : true,
  422. "mediumslateblue" : true,
  423. "mediumspringgreen" : true,
  424. "mediumturquoise" : true,
  425. "mediumvioletred" : true,
  426. "midnightblue" : true,
  427. "mintcream" : true,
  428. "mistyrose" : true,
  429. "moccasin" : true,
  430. "navajowhite" : true,
  431. "navy" : true,
  432. "oldlace" : true,
  433. "olive" : true,
  434. "olivedrab" : true,
  435. "orange" : true,
  436. "orangered" : true,
  437. "orchid" : true,
  438. "palegoldenrod" : true,
  439. "palegreen" : true,
  440. "paleturquoise" : true,
  441. "palevioletred" : true,
  442. "papayawhip" : true,
  443. "peachpuff" : true,
  444. "peru" : true,
  445. "pink" : true,
  446. "plum" : true,
  447. "powderblue" : true,
  448. "purple" : true,
  449. "red" : true,
  450. "rosybrown" : true,
  451. "royalblue" : true,
  452. "saddlebrown" : true,
  453. "salmon" : true,
  454. "sandybrown" : true,
  455. "seagreen" : true,
  456. "seashell" : true,
  457. "sienna" : true,
  458. "silver" : true,
  459. "skyblue" : true,
  460. "slateblue" : true,
  461. "slategray" : true,
  462. "snow" : true,
  463. "springgreen" : true,
  464. "steelblue" : true,
  465. "tan" : true,
  466. "teal" : true,
  467. "thistle" : true,
  468. "tomato" : true,
  469. "turquoise" : true,
  470. "violet" : true,
  471. "wheat" : true,
  472. "white" : true,
  473. "whitesmoke" : true,
  474. "yellow" : true,
  475. "yellowgreen" : true
  476. },
  477. cssBorderStyle,
  478. cssBreak,
  479. cssLengthData = {
  480. '%': true,
  481. 'cm': true,
  482. 'em': true,
  483. 'ex': true,
  484. 'in': true,
  485. 'mm': true,
  486. 'pc': true,
  487. 'pt': true,
  488. 'px': true
  489. },
  490. escapes = {
  491. '\b': '\\b',
  492. '\t': '\\t',
  493. '\n': '\\n',
  494. '\f': '\\f',
  495. '\r': '\\r',
  496. '"' : '\\"',
  497. '/' : '\\/',
  498. '\\': '\\\\'
  499. },
  500. funct, // The current function
  501. functionicity = [
  502. 'closure', 'exception', 'global', 'label',
  503. 'outer', 'unused', 'var'
  504. ],
  505. functions, // All of the functions
  506. global, // The global scope
  507. htmltag = {
  508. a: {},
  509. abbr: {},
  510. acronym: {},
  511. address: {},
  512. applet: {},
  513. area: {empty: true, parent: ' map '},
  514. b: {},
  515. base: {empty: true, parent: ' head '},
  516. bdo: {},
  517. big: {},
  518. blockquote: {},
  519. body: {parent: ' html noframes '},
  520. br: {empty: true},
  521. button: {},
  522. canvas: {parent: ' body p div th td '},
  523. caption: {parent: ' table '},
  524. center: {},
  525. cite: {},
  526. code: {},
  527. col: {empty: true, parent: ' table colgroup '},
  528. colgroup: {parent: ' table '},
  529. dd: {parent: ' dl '},
  530. del: {},
  531. dfn: {},
  532. dir: {},
  533. div: {},
  534. dl: {},
  535. dt: {parent: ' dl '},
  536. em: {},
  537. embed: {},
  538. fieldset: {},
  539. font: {},
  540. form: {},
  541. frame: {empty: true, parent: ' frameset '},
  542. frameset: {parent: ' html frameset '},
  543. h1: {},
  544. h2: {},
  545. h3: {},
  546. h4: {},
  547. h5: {},
  548. h6: {},
  549. head: {parent: ' html '},
  550. html: {parent: '*'},
  551. hr: {empty: true},
  552. i: {},
  553. iframe: {},
  554. img: {empty: true},
  555. input: {empty: true},
  556. ins: {},
  557. kbd: {},
  558. label: {},
  559. legend: {parent: ' fieldset '},
  560. li: {parent: ' dir menu ol ul '},
  561. link: {empty: true, parent: ' head '},
  562. map: {},
  563. menu: {},
  564. meta: {empty: true, parent: ' head noframes noscript '},
  565. noframes: {parent: ' html body '},
  566. noscript: {parent: ' body head noframes '},
  567. object: {},
  568. ol: {},
  569. optgroup: {parent: ' select '},
  570. option: {parent: ' optgroup select '},
  571. p: {},
  572. param: {empty: true, parent: ' applet object '},
  573. pre: {},
  574. q: {},
  575. samp: {},
  576. script: {empty: true, parent: ' body div frame head iframe p pre span '},
  577. select: {},
  578. small: {},
  579. span: {},
  580. strong: {},
  581. style: {parent: ' head ', empty: true},
  582. sub: {},
  583. sup: {},
  584. table: {},
  585. tbody: {parent: ' table '},
  586. td: {parent: ' tr '},
  587. textarea: {},
  588. tfoot: {parent: ' table '},
  589. th: {parent: ' tr '},
  590. thead: {parent: ' table '},
  591. title: {parent: ' head '},
  592. tr: {parent: ' table tbody thead tfoot '},
  593. tt: {},
  594. u: {},
  595. ul: {},
  596. 'var': {}
  597. },
  598. ids, // HTML ids
  599. implied, // Implied globals
  600. inblock,
  601. indent,
  602. jsonmode,
  603. lines,
  604. lookahead,
  605. member,
  606. membersOnly,
  607. nexttoken,
  608. noreach,
  609. option,
  610. predefined, // Global variables defined by option
  611. prereg,
  612. prevtoken,
  613. rhino = {
  614. defineClass : false,
  615. deserialize : false,
  616. gc : false,
  617. help : false,
  618. load : false,
  619. loadClass : false,
  620. print : false,
  621. quit : false,
  622. readFile : false,
  623. readUrl : false,
  624. runCommand : false,
  625. seal : false,
  626. serialize : false,
  627. spawn : false,
  628. sync : false,
  629. toint32 : false,
  630. version : false
  631. },
  632. scope, // The current scope
  633. sidebar = {
  634. System : false
  635. },
  636. src,
  637. stack,
  638. // standard contains the global names that are provided by the
  639. // ECMAScript standard.
  640. standard = {
  641. Array : false,
  642. Boolean : false,
  643. Date : false,
  644. decodeURI : false,
  645. decodeURIComponent : false,
  646. encodeURI : false,
  647. encodeURIComponent : false,
  648. Error : false,
  649. 'eval' : false,
  650. EvalError : false,
  651. Function : false,
  652. hasOwnProperty : false,
  653. isFinite : false,
  654. isNaN : false,
  655. JSON : false,
  656. Math : false,
  657. Number : false,
  658. Object : false,
  659. parseInt : false,
  660. parseFloat : false,
  661. RangeError : false,
  662. ReferenceError : false,
  663. RegExp : false,
  664. String : false,
  665. SyntaxError : false,
  666. TypeError : false,
  667. URIError : false
  668. },
  669. standard_member = {
  670. E : true,
  671. LN2 : true,
  672. LN10 : true,
  673. LOG2E : true,
  674. LOG10E : true,
  675. PI : true,
  676. SQRT1_2 : true,
  677. SQRT2 : true,
  678. MAX_VALUE : true,
  679. MIN_VALUE : true,
  680. NEGATIVE_INFINITY : true,
  681. POSITIVE_INFINITY : true
  682. },
  683. syntax = {},
  684. tab,
  685. token,
  686. urls,
  687. warnings,
  688. // widget contains the global names which are provided to a Yahoo
  689. // (fna Konfabulator) widget.
  690. widget = {
  691. alert : true,
  692. animator : true,
  693. appleScript : true,
  694. beep : true,
  695. bytesToUIString : true,
  696. Canvas : true,
  697. chooseColor : true,
  698. chooseFile : true,
  699. chooseFolder : true,
  700. closeWidget : true,
  701. COM : true,
  702. convertPathToHFS : true,
  703. convertPathToPlatform : true,
  704. CustomAnimation : true,
  705. escape : true,
  706. FadeAnimation : true,
  707. filesystem : true,
  708. Flash : true,
  709. focusWidget : true,
  710. form : true,
  711. FormField : true,
  712. Frame : true,
  713. HotKey : true,
  714. Image : true,
  715. include : true,
  716. isApplicationRunning : true,
  717. iTunes : true,
  718. konfabulatorVersion : true,
  719. log : true,
  720. md5 : true,
  721. MenuItem : true,
  722. MoveAnimation : true,
  723. openURL : true,
  724. play : true,
  725. Point : true,
  726. popupMenu : true,
  727. preferenceGroups : true,
  728. preferences : true,
  729. print : true,
  730. prompt : true,
  731. random : true,
  732. Rectangle : true,
  733. reloadWidget : true,
  734. ResizeAnimation : true,
  735. resolvePath : true,
  736. resumeUpdates : true,
  737. RotateAnimation : true,
  738. runCommand : true,
  739. runCommandInBg : true,
  740. saveAs : true,
  741. savePreferences : true,
  742. screen : true,
  743. ScrollBar : true,
  744. showWidgetPreferences : true,
  745. sleep : true,
  746. speak : true,
  747. Style : true,
  748. suppressUpdates : true,
  749. system : true,
  750. tellWidget : true,
  751. Text : true,
  752. TextArea : true,
  753. Timer : true,
  754. unescape : true,
  755. updateNow : true,
  756. URL : true,
  757. Web : true,
  758. widget : true,
  759. Window : true,
  760. XMLDOM : true,
  761. XMLHttpRequest : true,
  762. yahooCheckLogin : true,
  763. yahooLogin : true,
  764. yahooLogout : true
  765. },
  766. // xmode is used to adapt to the exceptions in html parsing.
  767. // It can have these states:
  768. // false .js script file
  769. // html
  770. // outer
  771. // script
  772. // style
  773. // scriptstring
  774. // styleproperty
  775. xmode,
  776. xquote,
  777. // unsafe comment or string
  778. ax = /@cc|<\/?|script|\]*s\]|<\s*!|&lt/i,
  779. // unsafe characters that are silently deleted by one or more browsers
  780. cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,
  781. // token
  782. tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/(\*(jslint|members?|global)?|=|\/)?|\*[\/=]?|\+[+=]?|-[\-=]?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=!]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/,
  783. // html token
  784. hx = /^\s*(['"=>\/&#]|<(?:\/|\!(?:--)?)?|[a-zA-Z][a-zA-Z0-9_\-]*|[0-9]+|--|.)/,
  785. // characters in strings that need escapement
  786. nx = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,
  787. nxg = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  788. // outer html token
  789. ox = /[>&]|<[\/!]?|--/,
  790. // star slash
  791. lx = /\*\/|\/\*/,
  792. // identifier
  793. ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/,
  794. // javascript url
  795. jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i,
  796. // url badness
  797. ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto/i,
  798. // style
  799. sx = /^\s*([{:#%.=,>+\[\]@()"';]|\*=?|\$=|\|=|\^=|~=|[a-zA-Z_][a-zA-Z0-9_\-]*|[0-9]+|<\/|\/\*)/,
  800. ssx = /^\s*([@#!"'};:\-%.=,+\[\]()*_]|[a-zA-Z][a-zA-Z0-9._\-]*|\/\*?|\d+(?:\.\d+)?|<\/)/,
  801. // attributes characters
  802. qx = /[^a-zA-Z0-9-_\/ ]/,
  803. // query characters for ids
  804. dx = /[\[\]\/\\"'*<>.&:(){}+=#]/,
  805. rx = {
  806. outer: hx,
  807. html: hx,
  808. style: sx,
  809. styleproperty: ssx
  810. };
  811. function F() {}
  812. if (typeof Object.create !== 'function') {
  813. Object.create = function (o) {
  814. F.prototype = o;
  815. return new F();
  816. };
  817. }
  818. function is_own(object, name) {
  819. return Object.prototype.hasOwnProperty.call(object, name);
  820. }
  821. function combine(t, o) {
  822. var n;
  823. for (n in o) {
  824. if (is_own(o, n)) {
  825. t[n] = o[n];
  826. }
  827. }
  828. }
  829. String.prototype.entityify = function () {
  830. return this.
  831. replace(/&/g, '&amp;').
  832. replace(/</g, '&lt;').
  833. replace(/>/g, '&gt;');
  834. };
  835. String.prototype.isAlpha = function () {
  836. return (this >= 'a' && this <= 'z\uffff') ||
  837. (this >= 'A' && this <= 'Z\uffff');
  838. };
  839. String.prototype.isDigit = function () {
  840. return (this >= '0' && this <= '9');
  841. };
  842. String.prototype.supplant = function (o) {
  843. return this.replace(/\{([^{}]*)\}/g, function (a, b) {
  844. var r = o[b];
  845. return typeof r === 'string' || typeof r === 'number' ? r : a;
  846. });
  847. };
  848. String.prototype.name = function () {
  849. // If the string looks like an identifier, then we can return it as is.
  850. // If the string contains no control characters, no quote characters, and no
  851. // backslash characters, then we can simply slap some quotes around it.
  852. // Otherwise we must also replace the offending characters with safe
  853. // sequences.
  854. if (ix.test(this)) {
  855. return this;
  856. }
  857. if (nx.test(this)) {
  858. return '"' + this.replace(nxg, function (a) {
  859. var c = escapes[a];
  860. if (c) {
  861. return c;
  862. }
  863. return '\\u' + ('0000' + a.charCodeAt().toString(16)).slice(-4);
  864. }) + '"';
  865. }
  866. return '"' + this + '"';
  867. };
  868. function assume() {
  869. if (!option.safe) {
  870. if (option.rhino) {
  871. combine(predefined, rhino);
  872. }
  873. if (option.browser || option.sidebar) {
  874. combine(predefined, browser);
  875. }
  876. if (option.sidebar) {
  877. combine(predefined, sidebar);
  878. }
  879. if (option.widget) {
  880. combine(predefined, widget);
  881. }
  882. }
  883. }
  884. // Produce an error warning.
  885. function quit(m, l, ch) {
  886. throw {
  887. name: 'JSLintError',
  888. line: l,
  889. character: ch,
  890. message: m + " (" + Math.floor((l / lines.length) * 100) +
  891. "% scanned)."
  892. };
  893. }
  894. function warning(m, t, a, b, c, d) {
  895. var ch, l, w;
  896. t = t || nexttoken;
  897. if (t.id === '(end)') { // `~
  898. t = token;
  899. }
  900. l = t.line || 0;
  901. ch = t.from || 0;
  902. w = {
  903. id: '(error)',
  904. raw: m,
  905. evidence: lines[l] || '',
  906. line: l,
  907. character: ch,
  908. a: a,
  909. b: b,
  910. c: c,
  911. d: d
  912. };
  913. w.reason = m.supplant(w);
  914. JSLINT.errors.push(w);
  915. if (option.passfail) {
  916. quit('Stopping. ', l, ch);
  917. }
  918. warnings += 1;
  919. /*if (warnings === 50) {
  920. quit("Too many errors.", l, ch);
  921. }*/
  922. return w;
  923. }
  924. function warningAt(m, l, ch, a, b, c, d) {
  925. return warning(m, {
  926. line: l,
  927. from: ch
  928. }, a, b, c, d);
  929. }
  930. function error(m, t, a, b, c, d) {
  931. var w = warning(m, t, a, b, c, d);
  932. quit("Stopping, unable to continue.", w.line, w.character);
  933. }
  934. function errorAt(m, l, ch, a, b, c, d) {
  935. return error(m, {
  936. line: l,
  937. from: ch
  938. }, a, b, c, d);
  939. }
  940. // lexical analysis
  941. var lex = (function lex() {
  942. var character, from, line, s;
  943. // Private lex methods
  944. function nextLine() {
  945. var at;
  946. if (line >= lines.length) {
  947. return false;
  948. }
  949. character = 1;
  950. s = lines[line].replace(/\t/g, tab);
  951. line += 1;
  952. at = s.search(cx);
  953. if (at >= 0) {
  954. warningAt("Unsafe character.", line, at);
  955. }
  956. return true;
  957. }
  958. // Produce a token object. The token inherits from a syntax symbol.
  959. function it(type, value) {
  960. var i, t;
  961. if (type === '(color)') {
  962. t = {type: type};
  963. } else if (type === '(punctuator)' ||
  964. (type === '(identifier)' && is_own(syntax, value))) {
  965. t = syntax[value] || syntax['(error)'];
  966. } else {
  967. t = syntax[type];
  968. }
  969. t = Object.create(t);
  970. if (type === '(string)' || type === '(range)') {
  971. if (jx.test(value)) {
  972. warningAt("Script URL.", line, from);
  973. }
  974. }
  975. if (type === '(identifier)') {
  976. t.identifier = true;
  977. if (option.nomen && value.charAt(0) === '_') {
  978. warningAt("Unexpected '_' in '{a}'.", line, from, value);
  979. }
  980. }
  981. t.value = value;
  982. t.line = line;
  983. t.character = character;
  984. t.from = from;
  985. i = t.id;
  986. if (i !== '(endline)') {
  987. prereg = i &&
  988. (('(,=:[!&|?{};'.indexOf(i.charAt(i.length - 1)) >= 0) ||
  989. i === 'return');
  990. }
  991. return t;
  992. }
  993. // Public lex methods
  994. return {
  995. init: function (source) {
  996. if (typeof source === 'string') {
  997. lines = source.
  998. replace(/\r\n/g, '\n').
  999. replace(/\r/g, '\n').
  1000. split('\n');
  1001. } else {
  1002. lines = source;
  1003. }
  1004. line = 0;
  1005. nextLine();
  1006. from = 1;
  1007. },
  1008. range: function (begin, end) {
  1009. var c, value = '';
  1010. from = character;
  1011. if (s.charAt(0) !== begin) {
  1012. errorAt("Expected '{a}' and instead saw '{b}'.",
  1013. line, character, begin, s.charAt(0));
  1014. }
  1015. for (;;) {
  1016. s = s.slice(1);
  1017. character += 1;
  1018. c = s.charAt(0);
  1019. switch (c) {
  1020. case '':
  1021. errorAt("Missing '{a}'.", line, character, c);
  1022. break;
  1023. case end:
  1024. s = s.slice(1);
  1025. character += 1;
  1026. return it('(range)', value);
  1027. case xquote:
  1028. case '\\':
  1029. case '\'':
  1030. case '"':
  1031. warningAt("Unexpected '{a}'.", line, character, c);
  1032. }
  1033. value += c;
  1034. }
  1035. },
  1036. // token -- this is called by advance to get the next token.
  1037. token: function () {
  1038. var b, c, captures, d, depth, high, i, l, low, q, t;
  1039. function match(x) {
  1040. var r = x.exec(s), r1;
  1041. if (r) {
  1042. l = r[0].length;
  1043. r1 = r[1];
  1044. c = r1.charAt(0);
  1045. s = s.substr(l);
  1046. from = character + l - r1.length;
  1047. character += l;
  1048. return r1;
  1049. }
  1050. }
  1051. function string(x) {
  1052. var c, j, r = '';
  1053. if (jsonmode && x !== '"') {
  1054. warningAt("Strings must use doublequote.",
  1055. line, character);
  1056. }
  1057. if (xquote === x || (xmode === 'scriptstring' && !xquote)) {
  1058. return it('(punctuator)', x);
  1059. }
  1060. function esc(n) {
  1061. var i = parseInt(s.substr(j + 1, n), 16);
  1062. j += n;
  1063. if (i >= 32 && i <= 126 &&
  1064. i !== 34 && i !== 92 && i !== 39) {
  1065. warningAt("Unnecessary escapement.", line, character);
  1066. }
  1067. character += n;
  1068. c = String.fromCharCode(i);
  1069. }
  1070. j = 0;
  1071. for (;;) {
  1072. while (j >= s.length) {
  1073. j = 0;
  1074. if (xmode !== 'html' || !nextLine()) {
  1075. errorAt("Unclosed string.", line, from);
  1076. }
  1077. }
  1078. c = s.charAt(j);
  1079. if (c === x) {
  1080. character += 1;
  1081. s = s.substr(j + 1);
  1082. return it('(string)', r, x);
  1083. }
  1084. if (c < ' ') {
  1085. if (c === '\n' || c === '\r') {
  1086. break;
  1087. }
  1088. warningAt("Control character in string: {a}.",
  1089. line, character + j, s.slice(0, j));
  1090. } else if (c === xquote) {
  1091. warningAt("Bad HTML string", line, character + j);
  1092. } else if (c === '<') {
  1093. if (option.safe && xmode === 'html') {
  1094. warningAt("ADsafe string violation.",
  1095. line, character + j);
  1096. } else if (s.charAt(j + 1) === '/' && (xmode || option.safe)) {
  1097. warningAt("Expected '<\\/' and instead saw '</'.", line, character);
  1098. } else if (s.charAt(j + 1) === '!' && (xmode || option.safe)) {
  1099. warningAt("Unexpected '<!' in a string.", line, character);
  1100. }
  1101. } else if (c === '\\') {
  1102. if (xmode === 'html') {
  1103. if (option.safe) {
  1104. warningAt("ADsafe string violation.",
  1105. line, character + j);
  1106. }
  1107. } else if (xmode === 'styleproperty') {
  1108. j += 1;
  1109. character += 1;
  1110. c = s.charAt(j);
  1111. if (c !== x) {
  1112. warningAt("Escapement in style string.",
  1113. line, character + j);
  1114. }
  1115. } else {
  1116. j += 1;
  1117. character += 1;
  1118. c = s.charAt(j);
  1119. switch (c) {
  1120. case xquote:
  1121. warningAt("Bad HTML string", line,
  1122. character + j);
  1123. break;
  1124. case '\\':
  1125. case '\'':
  1126. case '"':
  1127. case '/':
  1128. break;
  1129. case 'b':
  1130. c = '\b';
  1131. break;
  1132. case 'f':
  1133. c = '\f';
  1134. break;
  1135. case 'n':
  1136. c = '\n';
  1137. break;
  1138. case 'r':
  1139. c = '\r';
  1140. break;
  1141. case 't':
  1142. c = '\t';
  1143. break;
  1144. case 'u':
  1145. esc(4);
  1146. break;
  1147. case 'v':
  1148. c = '\v';
  1149. break;
  1150. case 'x':
  1151. if (jsonmode) {
  1152. warningAt("Avoid \\x-.", line, character);
  1153. }
  1154. esc(2);
  1155. break;
  1156. default:
  1157. warningAt("Bad escapement.", line, character);
  1158. }
  1159. }
  1160. }
  1161. r += c;
  1162. character += 1;
  1163. j += 1;
  1164. }
  1165. }
  1166. for (;;) {
  1167. if (!s) {
  1168. return it(nextLine() ? '(endline)' : '(end)', '');
  1169. }
  1170. while (xmode === 'outer') {
  1171. i = s.search(ox);
  1172. if (i === 0) {
  1173. break;
  1174. } else if (i > 0) {
  1175. character += 1;
  1176. s = s.slice(i);
  1177. break;
  1178. } else {
  1179. if (!nextLine()) {
  1180. return it('(end)', '');
  1181. }
  1182. }
  1183. }
  1184. t = match(rx[xmode] || tx);
  1185. if (!t) {
  1186. if (xmode === 'html') {
  1187. return it('(error)', s.charAt(0));
  1188. } else {
  1189. t = '';
  1190. c = '';
  1191. while (s && s < '!') {
  1192. s = s.substr(1);
  1193. }
  1194. if (s) {
  1195. errorAt("Unexpected '{a}'.",
  1196. line, character, s.substr(0, 1));
  1197. }
  1198. }
  1199. } else {
  1200. // identifier
  1201. if (c.isAlpha() || c === '_' || c === '$') {
  1202. return it('(identifier)', t);
  1203. }
  1204. // number
  1205. if (c.isDigit()) {
  1206. if (xmode !== 'style' && !isFinite(Number(t))) {
  1207. warningAt("Bad number '{a}'.",
  1208. line, character, t);
  1209. }
  1210. if (xmode !== 'style' &&
  1211. xmode !== 'styleproperty' &&
  1212. s.substr(0, 1).isAlpha()) {
  1213. warningAt("Missing space after '{a}'.",
  1214. line, character, t);
  1215. }
  1216. if (c === '0') {
  1217. d = t.substr(1, 1);
  1218. if (d.isDigit()) {
  1219. if (token.id !== '.' && xmode !== 'styleproperty') {
  1220. warningAt("Don't use extra leading zeros '{a}'.",
  1221. line, character, t);
  1222. }
  1223. } else if (jsonmode && (d === 'x' || d === 'X')) {
  1224. warningAt("Avoid 0x-. '{a}'.",
  1225. line, character, t);
  1226. }
  1227. }
  1228. if (t.substr(t.length - 1) === '.') {
  1229. warningAt(
  1230. "A trailing decimal point can be confused with a dot '{a}'.",
  1231. line, character, t);
  1232. }
  1233. return it('(number)', t);
  1234. }
  1235. switch (t) {
  1236. // string
  1237. case '"':
  1238. case "'":
  1239. return string(t);
  1240. // // comment
  1241. case '//':
  1242. if (src || (xmode && xmode !== 'script')) {
  1243. warningAt("Unexpected comment.", line, character);
  1244. } else if (xmode === 'script' && /<\s*\//i.test(s)) {
  1245. warningAt("Unexpected <\/ in comment.", line, character);
  1246. } else if ((option.safe || xmode === 'script') && ax.test(s)) {
  1247. warningAt("Dangerous comment.", line, character);
  1248. }
  1249. s = '';
  1250. token.comment = true;
  1251. break;
  1252. // /* comment
  1253. case '/*':
  1254. if (src || (xmode && xmode !== 'script' && xmode !== 'style' && xmode !== 'styleproperty')) {
  1255. warningAt("Unexpected comment.", line, character);
  1256. }
  1257. if (option.safe && ax.test(s)) {
  1258. warningAt("ADsafe comment violation.", line, character);
  1259. }
  1260. for (;;) {
  1261. i = s.search(lx);
  1262. if (i >= 0) {
  1263. break;
  1264. }
  1265. if (!nextLine()) {
  1266. errorAt("Unclosed comment.", line, character);
  1267. } else {
  1268. if (option.safe && ax.test(s)) {
  1269. warningAt("ADsafe comment violation.", line, character);
  1270. }
  1271. }
  1272. }
  1273. character += i + 2;
  1274. if (s.substr(i, 1) === '/') {
  1275. errorAt("Nested comment.", line, character);
  1276. }
  1277. s = s.substr(i + 2);
  1278. token.comment = true;
  1279. break;
  1280. // /*members /*jslint /*global
  1281. case '/*members':
  1282. case '/*member':
  1283. case '/*jslint':
  1284. case '/*global':
  1285. case '*/':
  1286. return {
  1287. value: t,
  1288. type: 'special',
  1289. line: line,
  1290. character: character,
  1291. from: from
  1292. };
  1293. case '':
  1294. break;
  1295. // /
  1296. case '/':
  1297. if (prereg) {
  1298. depth = 0;
  1299. captures = 0;
  1300. l = 0;
  1301. for (;;) {
  1302. b = true;
  1303. c = s.charAt(l);
  1304. l += 1;
  1305. switch (c) {
  1306. case '':
  1307. errorAt("Unclosed regular expression.", line, from);
  1308. return;
  1309. case '/':
  1310. if (depth > 0) {
  1311. warningAt("Unescaped '{a}'.", line, from + l, '/');
  1312. }
  1313. c = s.substr(0, l - 1);
  1314. q = {
  1315. g: true,
  1316. i: true,
  1317. m: true
  1318. };
  1319. while (q[s.charAt(l)] === true) {
  1320. q[s.charAt(l)] = false;
  1321. l += 1;
  1322. }
  1323. character += l;
  1324. s = s.substr(l);
  1325. return it('(regexp)', c);
  1326. case '\\':
  1327. c = s.charAt(l);
  1328. if (c < ' ') {
  1329. warningAt("Unexpected control character in regular expression.", line, from + l);
  1330. } else if (c === '<') {
  1331. warningAt("Unexpected escaped character '{a}' in regular expression.", line, from + l, c);
  1332. }
  1333. l += 1;
  1334. break;
  1335. case '(':
  1336. depth += 1;
  1337. b = false;
  1338. if (s.charAt(l) === '?') {
  1339. l += 1;
  1340. switch (s.charAt(l)) {
  1341. case ':':
  1342. case '=':
  1343. case '!':
  1344. l += 1;
  1345. break;
  1346. default:
  1347. warningAt("Expected '{a}' and instead saw '{b}'.", line, from + l, ':', s.charAt(l));
  1348. }
  1349. } else {
  1350. captures += 1;
  1351. }
  1352. break;
  1353. case ')':
  1354. if (depth === 0) {
  1355. warningAt("Unescaped '{a}'.", line, from + l, ')');
  1356. } else {
  1357. depth -= 1;
  1358. }
  1359. break;
  1360. case ' ':
  1361. q = 1;
  1362. while (s.charAt(l) === ' ') {
  1363. l += 1;
  1364. q += 1;
  1365. }
  1366. if (q > 1) {
  1367. warningAt("Spaces are hard to count. Use {{a}}.", line, from + l, q);
  1368. }
  1369. break;
  1370. case '[':
  1371. c = s.charAt(l);
  1372. if (c === '^') {
  1373. l += 1;
  1374. }
  1375. q = false;
  1376. if (c === ']') {
  1377. warningAt("Empty class.", line, from + l - 1);
  1378. q = true;
  1379. }
  1380. klass: do {
  1381. c = s.charAt(l);
  1382. l += 1;
  1383. switch (c) {
  1384. case '[':
  1385. case '^':
  1386. warningAt("Unescaped '{a}'.", line, from + l, c);
  1387. q = true;
  1388. break;
  1389. case '-':
  1390. if (q) {
  1391. q = false;
  1392. } else {
  1393. warningAt("Unescaped '{a}'.", line, from + l, '-');
  1394. q = true;
  1395. }
  1396. break;
  1397. case ']':
  1398. if (!q) {
  1399. warningAt("Unescaped '{a}'.", line, from + l - 1, ']');
  1400. }
  1401. break klass;
  1402. case '\\':
  1403. c = s.charAt(l);
  1404. if (c < ' ') {
  1405. warningAt("Unexpected control character in regular expression.", line, from + l);
  1406. } else if (c === '<') {
  1407. warningAt("Unexpected escaped character '{a}' in regular expression.", line, from + l, c);
  1408. }
  1409. l += 1;
  1410. q = true;
  1411. break;
  1412. case '/':
  1413. warningAt("Unescaped '{a}'.", line, from + l - 1, '/');
  1414. q = true;
  1415. break;
  1416. case '<':
  1417. if (xmode === 'script') {
  1418. c = s.charAt(l);
  1419. if (c === '!' || c === '/') {
  1420. warningAt("HTML confusion in regular expression '<{a}'.", line, from + l, c);
  1421. }
  1422. }
  1423. q = true;
  1424. break;
  1425. default:
  1426. q = true;
  1427. }
  1428. } while (c);
  1429. break;
  1430. case '.':
  1431. if (option.regexp) {
  1432. warningAt("Unexpected '{a}'.", line, from + l, c);
  1433. }
  1434. break;
  1435. case ']':
  1436. case '?':
  1437. case '{':
  1438. case '}':
  1439. case '+':
  1440. case '*':
  1441. warningAt("Unescaped '{a}'.", line, from + l, c);
  1442. break;
  1443. case '<':
  1444. if (xmode === 'script') {
  1445. c = s.charAt(l);
  1446. if (c === '!' || c === '/') {
  1447. warningAt("HTML confusion in regular expression '<{a}'.", line, from + l, c);
  1448. }
  1449. }
  1450. }
  1451. if (b) {
  1452. switch (s.charAt(l)) {
  1453. case '?':
  1454. case '+':
  1455. case '*':
  1456. l += 1;
  1457. if (s.charAt(l) === '?') {
  1458. l += 1;
  1459. }
  1460. break;
  1461. case '{':
  1462. l += 1;
  1463. c = s.charAt(l);
  1464. if (c < '0' || c > '9') {
  1465. warningAt("Expected a number and instead saw '{a}'.", line, from + l, c);
  1466. }
  1467. l += 1;
  1468. low = +c;
  1469. for (;;) {
  1470. c = s.charAt(l);
  1471. if (c < '0' || c > '9') {
  1472. break;
  1473. }
  1474. l += 1;
  1475. low = +c + (low * 10);
  1476. }
  1477. high = low;
  1478. if (c === ',') {
  1479. l += 1;
  1480. high = Infinity;
  1481. c = s.charAt(l);
  1482. if (c >= '0' && c <= '9') {
  1483. l += 1;
  1484. high = +c;
  1485. for (;;) {
  1486. c = s.charAt(l);
  1487. if (c < '0' || c > '9') {
  1488. break;
  1489. }
  1490. l += 1;
  1491. high = +c + (high * 10);
  1492. }
  1493. }
  1494. }
  1495. if (s.charAt(l) !== '}') {
  1496. warningAt("Expected '{a}' and instead saw '{b}'.", line, from + l, '}', c);
  1497. } else {
  1498. l += 1;
  1499. }
  1500. if (s.charAt(l) === '?') {
  1501. l += 1;
  1502. }
  1503. if (low > high) {
  1504. warningAt("'{a}' should not be greater than '{b}'.", line, from + l, low, high);
  1505. }
  1506. }
  1507. }
  1508. }
  1509. c = s.substr(0, l - 1);
  1510. character += l;
  1511. s = s.substr(l);
  1512. return it('(regexp)', c);
  1513. }
  1514. return it('(punctuator)', t);
  1515. // punctuator
  1516. case '<!--':
  1517. l = line;
  1518. c = character;
  1519. for (;;) {
  1520. i = s.indexOf('--');
  1521. if (i >= 0) {
  1522. break;
  1523. }
  1524. i = s.indexOf('<!');
  1525. if (i >= 0) {
  1526. errorAt("Nested HTML comment.",
  1527. line, character + i);
  1528. }
  1529. if (!nextLine()) {
  1530. errorAt("Unclosed HTML comment.", l, c);
  1531. }
  1532. }
  1533. l = s.indexOf('<!');
  1534. if (l >= 0 && l < i) {
  1535. errorAt("Nested HTML comment.",
  1536. line, character + l);
  1537. }
  1538. character += i;
  1539. if (s[i + 2] !== '>') {
  1540. errorAt("Expected -->.", line, character);
  1541. }
  1542. character += 3;
  1543. s = s.slice(i + 3);
  1544. break;
  1545. case '#':
  1546. if (xmode === 'html' || xmode === 'styleproperty') {
  1547. for (;;) {
  1548. c = s.charAt(0);
  1549. if ((c < '0' || c > '9') &&
  1550. (c < 'a' || c > 'f') &&
  1551. (c < 'A' || c > 'F')) {
  1552. break;
  1553. }
  1554. character += 1;
  1555. s = s.substr(1);
  1556. t += c;
  1557. }
  1558. if (t.length !== 4 && t.length !== 7) {
  1559. warningAt("Bad hex color '{a}'.", line,
  1560. from + l, t);
  1561. }
  1562. return it('(color)', t);
  1563. }
  1564. return it('(punctuator)', t);
  1565. default:
  1566. if (xmode === 'outer' && c === '&') {
  1567. character += 1;
  1568. s = s.substr(1);
  1569. for (;;) {
  1570. c = s.charAt(0);
  1571. character += 1;
  1572. s = s.substr(1);
  1573. if (c === ';') {
  1574. break;
  1575. }
  1576. if (!((c >= '0' && c <= '9') ||
  1577. (c >= 'a' && c <= 'z') ||
  1578. c === '#')) {
  1579. errorAt("Bad entity", line, from + l,
  1580. character);
  1581. }
  1582. }
  1583. break;
  1584. }
  1585. return it('(punctuator)', t);
  1586. }
  1587. }
  1588. }
  1589. }
  1590. };
  1591. }());
  1592. function addlabel(t, type) {
  1593. if (option.safe && funct['(global)'] && typeof predefined[t] !== 'boolean') {
  1594. warning('ADsafe global: ' + t + '.', token);
  1595. } else if (t === 'hasOwnProperty') {
  1596. warning("'hasOwnProperty' is a really bad name.");
  1597. }
  1598. // Define t in the current function in the current scope.
  1599. if (is_own(funct, t) && !funct['(global)']) {
  1600. warning(funct[t] === true ?
  1601. "'{a}' was used before it was defined." :
  1602. "'{a}' is already defined.",
  1603. nexttoken, t);
  1604. }
  1605. funct[t] = type;
  1606. if (type === 'label') {
  1607. scope[t] = funct;
  1608. } else if (funct['(global)']) {
  1609. global[t] = funct;
  1610. if (is_own(implied, t)) {
  1611. warning("'{a}' was used before it was defined.", nexttoken, t);
  1612. delete implied[t];
  1613. }
  1614. } else {
  1615. funct['(scope)'][t] = funct;
  1616. }
  1617. }
  1618. function doOption() {
  1619. var b, obj, filter, o = nexttoken.value, t, v;
  1620. switch (o) {
  1621. case '*/':
  1622. error("Unbegun comment.");
  1623. break;
  1624. case '/*members':
  1625. case '/*member':
  1626. o = '/*members';
  1627. if (!membersOnly) {
  1628. membersOnly = {};
  1629. }
  1630. obj = membersOnly;
  1631. break;
  1632. case '/*jslint':
  1633. if (option.safe) {
  1634. warning("ADsafe restriction.");
  1635. }
  1636. obj = option;
  1637. filter = boolOptions;
  1638. break;
  1639. case '/*global':
  1640. if (option.safe) {
  1641. warning("ADsafe restriction.");
  1642. }
  1643. obj = predefined;
  1644. break;
  1645. default:
  1646. }
  1647. t = lex.token();
  1648. loop: for (;;) {
  1649. for (;;) {
  1650. if (t.type === 'special' && t.value === '*/') {
  1651. break loop;
  1652. }
  1653. if (t.id !== '(endline)' && t.id !== ',') {
  1654. break;
  1655. }
  1656. t = lex.token();
  1657. }
  1658. if (t.type !== '(string)' && t.type !== '(identifier)' &&
  1659. o !== '/*members') {
  1660. error("Bad option.", t);
  1661. }
  1662. v = lex.token();
  1663. if (v.id === ':') {
  1664. v = lex.token();
  1665. if (obj === membersOnly) {
  1666. error("Expected '{a}' and instead saw '{b}'.",
  1667. t, '*/', ':');
  1668. }
  1669. if (t.value === 'indent' && o === '/*jslint') {
  1670. b = +v.value;
  1671. if (typeof b !== 'number' || !isFinite(b) || b <= 0 ||
  1672. Math.floor(b) !== b) {
  1673. error("Expected a small integer and instead saw '{a}'.",
  1674. v, v.value);
  1675. }
  1676. obj.white = true;
  1677. obj.indent = b;
  1678. } else if (v.value === 'true') {
  1679. obj[t.value] = true;
  1680. } else if (v.value === 'false') {
  1681. obj[t.value] = false;
  1682. } else {
  1683. error("Bad option value.", v);
  1684. }
  1685. t = lex.token();
  1686. } else {
  1687. if (o === '/*jslint') {
  1688. error("Missing option value.", t);
  1689. }
  1690. obj[t.value] = false;
  1691. t = v;
  1692. }
  1693. }
  1694. if (filter) {
  1695. assume();
  1696. }
  1697. }
  1698. // We need a peek function. If it has an argument, it peeks that much farther
  1699. // ahead. It is used to distinguish
  1700. // for ( var i in ...
  1701. // from
  1702. // for ( var i = ...
  1703. function peek(p) {
  1704. var i = p || 0, j = 0, t;
  1705. while (j <= i) {
  1706. t = lookahead[j];
  1707. if (!t) {
  1708. t = lookahead[j] = lex.token();
  1709. }
  1710. j += 1;
  1711. }
  1712. return t;
  1713. }
  1714. // Produce the next token. It looks for programming errors.
  1715. function advance(id, t) {
  1716. switch (token.id) {
  1717. case '(number)':
  1718. if (nexttoken.id === '.') {
  1719. warning(
  1720. "A dot following a number can be confused with a decimal point.", token);
  1721. }
  1722. break;
  1723. case '-':
  1724. if (nexttoken.id === '-' || nexttoken.id === '--') {
  1725. warning("Confusing minusses.");
  1726. }
  1727. break;
  1728. case '+':
  1729. if (nexttoken.id === '+' || nexttoken.id === '++') {
  1730. warning("Confusing plusses.");
  1731. }
  1732. break;
  1733. }
  1734. if (token.type === '(string)' || token.identifier) {
  1735. anonname = token.value;
  1736. }
  1737. if (id && nexttoken.id !== id) {
  1738. if (t) {
  1739. if (nexttoken.id === '(end)') {
  1740. warning("Unmatched '{a}'.", t, t.id);
  1741. } else {
  1742. warning("Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.",
  1743. nexttoken, id, t.id, t.line, nexttoken.value);
  1744. }
  1745. } else if (nexttoken.type !== '(identifier)' ||
  1746. nexttoken.value !== id) {
  1747. warning("Expected '{a}' and instead saw '{b}'.",
  1748. nexttoken, id, nexttoken.value);
  1749. }
  1750. }
  1751. prevtoken = token;
  1752. token = nexttoken;
  1753. for (;;) {
  1754. nexttoken = lookahead.shift() || lex.token();
  1755. if (nexttoken.id === '(end)' || nexttoken.id === '(error)') {
  1756. return;
  1757. }
  1758. if (nexttoken.type === 'special') {
  1759. doOption();
  1760. } else {
  1761. if (nexttoken.id !== '(endline)') {
  1762. break;
  1763. }
  1764. }
  1765. }
  1766. }
  1767. // This is the heart of JSLINT, the Pratt parser. In addition to parsing, it
  1768. // is looking for ad hoc lint patterns. We add to Pratt's model .fud, which is
  1769. // like nud except that it is only used on the first token of a statement.
  1770. // Having .fud makes it much easier to define JavaScript. I retained Pratt's
  1771. // nomenclature.
  1772. // .nud Null denotation
  1773. // .fud First null denotation
  1774. // .led Left denotation
  1775. // lbp Left binding power
  1776. // rbp Right binding power
  1777. // They are key to the parsing method called Top Down Operator Precedence.
  1778. function parse(rbp, initial) {
  1779. var left, o;
  1780. if (nexttoken.id === '(end)') {
  1781. error("Unexpected early end of program.", token);
  1782. }
  1783. advance();
  1784. if (option.safe && typeof predefined[token.value] === 'boolean' &&
  1785. (nexttoken.id !== '(' && nexttoken.id !== '.')) {
  1786. warning('ADsafe violation.', token);
  1787. }
  1788. if (initial) {
  1789. anonname = 'anonymous';
  1790. funct['(verb)'] = token.value;
  1791. }
  1792. if (initial === true && token.fud) {
  1793. left = token.fud();
  1794. } else {
  1795. if (token.nud) {
  1796. o = token.exps;
  1797. left = token.nud();
  1798. } else {
  1799. if (nexttoken.type === '(number)' && token.id === '.') {
  1800. warning(
  1801. "A leading decimal point can be confused with a dot: '.{a}'.",
  1802. token, nexttoken.value);
  1803. advance();
  1804. return token;
  1805. } else {
  1806. error("Expected an identifier and instead saw '{a}'.",
  1807. token, token.id);
  1808. }
  1809. }
  1810. while (rbp < nexttoken.lbp) {
  1811. o = nexttoken.exps;
  1812. advance();
  1813. if (token.led) {
  1814. left = token.led(left);
  1815. } else {
  1816. error("Expected an operator and instead saw '{a}'.",
  1817. token, token.id);
  1818. }
  1819. }
  1820. if (initial && !o) {
  1821. warning(
  1822. "Expected an assignment or function call and instead saw an expression.",
  1823. token);
  1824. }
  1825. }
  1826. return left;
  1827. }
  1828. // Functions for conformance of style.
  1829. function adjacent(left, right) {
  1830. left = left || token;
  1831. right = right || nexttoken;
  1832. if (option.white || xmode === 'styleproperty' || xmode === 'style') {
  1833. if (left.character !== right.from && left.line === right.line) {
  1834. warning("Unexpected space after '{a}'.", right, left.value);
  1835. }
  1836. }
  1837. }
  1838. function nospace(left, right) {
  1839. left = left || token;
  1840. right = right || nexttoken;
  1841. if (option.white && !left.comment) {
  1842. if (left.line === right.line) {
  1843. adjacent(left, right);
  1844. }
  1845. }
  1846. }
  1847. function nonadjacent(left, right) {
  1848. if (option.white) {
  1849. left = left || token;
  1850. right = right || nexttoken;
  1851. if (left.character === right.from) {
  1852. warning("Missing space after '{a}'.",
  1853. nexttoken, left.value);
  1854. }
  1855. }
  1856. }
  1857. function nobreaknonadjacent(left, right) {
  1858. left = left || token;
  1859. right = right || nexttoken;
  1860. if (!option.laxbreak && left.line !== right.line) {
  1861. warning("Bad line breaking before '{a}'.", right, right.id);
  1862. } else if (option.white) {
  1863. left = left || token;
  1864. right = right || nexttoken;
  1865. if (left.character === right.from) {
  1866. warning("Missing space after '{a}'.",
  1867. nexttoken, left.value);
  1868. }
  1869. }
  1870. }
  1871. function indentation(bias) {
  1872. var i;
  1873. if (option.white && nexttoken.id !== '(end)') {
  1874. i = indent + (bias || 0);
  1875. if (nexttoken.from !== i) {
  1876. warning("Expected '{a}' to have an indentation of {b} instead of {c}.",
  1877. nexttoken, nexttoken.value, i, nexttoken.from);
  1878. }
  1879. }
  1880. }
  1881. function nolinebreak(t) {
  1882. if (t.line !== nexttoken.line) {
  1883. warning("Line breaking error '{a}'.", t, t.value);
  1884. }
  1885. }
  1886. function comma() {
  1887. if (token.line !== nexttoken.line) {
  1888. if (!option.laxbreak) {
  1889. warning("Bad line breaking before '{a}'.", token, nexttoken.id);
  1890. }
  1891. } else if (token.character !== nexttoken.from && option.white) {
  1892. warning("Unexpected space after '{a}'.", nexttoken, token.value);
  1893. }
  1894. advance(',');
  1895. nonadjacent(token, nexttoken);
  1896. }
  1897. // Functional constructors for making the symbols that will be inherited by
  1898. // tokens.
  1899. function symbol(s, p) {
  1900. var x = syntax[s];
  1901. if (!x || typeof x !== 'object') {
  1902. syntax[s] = x = {
  1903. id: s,
  1904. lbp: p,
  1905. value: s
  1906. };
  1907. }
  1908. return x;
  1909. }
  1910. function delim(s) {
  1911. return symbol(s, 0);
  1912. }
  1913. function stmt(s, f) {
  1914. var x = delim(s);
  1915. x.identifier = x.reserved = true;
  1916. x.fud = f;
  1917. return x;
  1918. }
  1919. function blockstmt(s, f) {
  1920. var x = stmt(s, f);
  1921. x.block = true;
  1922. return x;
  1923. }
  1924. function reserveName(x) {
  1925. var c = x.id.charAt(0);
  1926. if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
  1927. x.identifier = x.reserved = true;
  1928. }
  1929. return x;
  1930. }
  1931. function prefix(s, f) {
  1932. var x = symbol(s, 150);
  1933. reserveName(x);
  1934. x.nud = (typeof f === 'function') ? f : function () {
  1935. this.right = parse(150);
  1936. this.arity = 'unary';
  1937. if (this.id === '++' || this.id === '--') {
  1938. if (option.plusplus) {
  1939. warning("Unexpected use of '{a}'.", this, this.id);
  1940. } else if ((!this.right.identifier || this.right.reserved) &&
  1941. this.right.id !== '.' && this.right.id !== '[') {
  1942. warning("Bad operand.", this);
  1943. }
  1944. }
  1945. return this;
  1946. };
  1947. return x;
  1948. }
  1949. function type(s, f) {
  1950. var x = delim(s);
  1951. x.type = s;
  1952. x.nud = f;
  1953. return x;
  1954. }
  1955. function reserve(s, f) {
  1956. var x = type(s, f);
  1957. x.identifier = x.reserved = true;
  1958. return x;
  1959. }
  1960. function reservevar(s, v) {
  1961. return reserve(s, function () {
  1962. if (option.safe &&
  1963. (this.id === 'this' || this.id === 'arguments')) {
  1964. warning("ADsafe violation.", this);
  1965. }
  1966. return this;
  1967. });
  1968. }
  1969. function infix(s, f, p, w) {
  1970. var x = symbol(s, p);
  1971. reserveName(x);
  1972. x.led = function (left) {
  1973. if (!w) {
  1974. nobreaknonadjacent(prevtoken, token);
  1975. nonadjacent(token, nexttoken);
  1976. }
  1977. if (typeof f === 'function') {
  1978. return f(left, this);
  1979. } else {
  1980. this.left = left;
  1981. this.right = parse(p);
  1982. return this;
  1983. }
  1984. };
  1985. return x;
  1986. }
  1987. function relation(s, f) {
  1988. var x = symbol(s, 100);
  1989. x.led = function (left) {
  1990. nobreaknonadjacent(prevtoken, token);
  1991. nonadjacent(token, nexttoken);
  1992. var right = parse(100);
  1993. if ((left && left.id === 'NaN') || (right && right.id === 'NaN')) {
  1994. warning("Use the isNaN function to compare with NaN.", this);
  1995. } else if (f) {
  1996. f.apply(this, [left, right]);
  1997. }
  1998. this.left = left;
  1999. this.right = right;
  2000. return this;
  2001. };
  2002. return x;
  2003. }
  2004. function isPoorRelation(node) {
  2005. return (node.type === '(number)' && !+node.value) ||
  2006. (node.type === '(string)' && !node.value) ||
  2007. node.type === 'true' ||
  2008. node.type === 'false' ||
  2009. node.type === 'undefined' ||
  2010. node.type === 'null';
  2011. }
  2012. function assignop(s, f) {
  2013. symbol(s, 20).exps = true;
  2014. return infix(s, function (left, that) {
  2015. var l;
  2016. that.left = left;
  2017. if (predefined[left.value] === false &&
  2018. scope[left.value]['(global)'] === true) {
  2019. warning('Read only.', left);
  2020. }
  2021. if (option.safe) {
  2022. l = left;
  2023. do {
  2024. if (typeof predefined[l.value] === 'boolean') {
  2025. warning('ADsafe violation.', l);
  2026. }
  2027. l = l.left;
  2028. } while (l);
  2029. }
  2030. if (left) {
  2031. if (left.id === '.' || left.id === '[') {
  2032. if (left.left.value === 'arguments') {
  2033. warning('Bad assignment.', that);
  2034. }
  2035. that.right = parse(19);
  2036. return that;
  2037. } else if (left.identifier && !left.reserved) {
  2038. if (funct[left.value] === 'exception') {
  2039. warning("Do not assign to the exception parameter.", left);
  2040. }
  2041. that.right = parse(19);
  2042. return that;
  2043. }
  2044. if (left === syntax['function']) {
  2045. warning(
  2046. "Expected an identifier in an assignment and instead saw a function invocation.",
  2047. token);
  2048. }
  2049. }
  2050. error("Bad assignment.", that);
  2051. }, 20);
  2052. }
  2053. function bitwise(s, f, p) {
  2054. var x = symbol(s, p);
  2055. reserveName(x);
  2056. x.led = (typeof f === 'function') ? f : function (left) {
  2057. if (option.bitwise) {
  2058. warning("Unexpected use of '{a}'.", this, this.id);
  2059. }
  2060. this.left = left;
  2061. this.right = parse(p);
  2062. return this;
  2063. };
  2064. return x;
  2065. }
  2066. function bitwiseassignop(s) {
  2067. symbol(s, 20).exps = true;
  2068. return infix(s, function (left, that) {
  2069. if (option.bitwise) {
  2070. warning("Unexpected use of '{a}'.", that, that.id);
  2071. }
  2072. nonadjacent(prevtoken, token);
  2073. nonadjacent(token, nexttoken);
  2074. if (left) {
  2075. if (left.id === '.' || left.id === '[' ||
  2076. (left.identifier && !left.reserved)) {
  2077. parse(19);
  2078. return left;
  2079. }
  2080. if (left === syntax['function']) {
  2081. warning(
  2082. "Expected an identifier in an assignment, and instead saw a function invocation.",
  2083. token);
  2084. }
  2085. }
  2086. error("Bad assignment.", that);
  2087. }, 20);
  2088. }
  2089. function suffix(s, f) {
  2090. var x = symbol(s, 150);
  2091. x.led = function (left) {
  2092. if (option.plusplus) {
  2093. warning("Unexpected use of '{a}'.", this, this.id);
  2094. } else if ((!left.identifier || left.reserved) && left.id !== '.' && left.id !== '[') {
  2095. warning("Bad operand.", this);
  2096. }
  2097. this.left = left;
  2098. return this;
  2099. };
  2100. return x;
  2101. }
  2102. function optionalidentifier() {
  2103. if (nexttoken.reserved) {
  2104. warning("Expected an identifier and instead saw '{a}' (a reserved word).",
  2105. nexttoken, nexttoken.id);
  2106. }
  2107. if (nexttoken.identifier) {
  2108. advance();
  2109. return token.value;
  2110. }
  2111. }
  2112. function identifier() {
  2113. var i = optionalidentifier();
  2114. if (i) {
  2115. return i;
  2116. }
  2117. if (token.id === 'function' && nexttoken.id === '(') {
  2118. warning("Missing name in function statement.");
  2119. } else {
  2120. error("Expected an identifier and instead saw '{a}'.",
  2121. nexttoken, nexttoken.value);
  2122. }
  2123. }
  2124. function reachable(s) {
  2125. var i = 0, t;
  2126. if (nexttoken.id !== ';' || noreach) {
  2127. return;
  2128. }
  2129. for (;;) {
  2130. t = peek(i);
  2131. if (t.reach) {
  2132. return;
  2133. }
  2134. if (t.id !== '(endline)') {
  2135. if (t.id === 'function') {
  2136. warning(
  2137. "Inner functions should be listed at the top of the outer function.", t);
  2138. break;
  2139. }
  2140. warning("Unreachable '{a}' after '{b}'.", t, t.value, s);
  2141. break;
  2142. }
  2143. i += 1;
  2144. }
  2145. }
  2146. function statement(noindent) {
  2147. var i = indent, r, s = scope, t = nexttoken;
  2148. // We don't like the empty statement.
  2149. if (t.id === ';') {
  2150. warning("Unnecessary semicolon.", t);
  2151. advance(';');
  2152. return;
  2153. }
  2154. // Is this a labelled statement?
  2155. if (t.identifier && !t.reserved && peek().id === ':') {
  2156. advance();
  2157. advance(':');
  2158. scope = Object.create(s);
  2159. addlabel(t.value, 'label');
  2160. if (!nexttoken.labelled) {
  2161. warning("Label '{a}' on {b} statement.",
  2162. nexttoken, t.value, nexttoken.value);
  2163. }
  2164. if (jx.test(t.value + ':')) {
  2165. warning("Label '{a}' looks like a javascript url.",
  2166. t, t.value);
  2167. }
  2168. nexttoken.label = t.value;
  2169. t = nexttoken;
  2170. }
  2171. // Parse the statement.
  2172. if (!noindent) {
  2173. indentation();
  2174. }
  2175. r = parse(0, true);
  2176. // Look for the final semicolon.
  2177. if (!t.block) {
  2178. if (nexttoken.id !== ';') {
  2179. warningAt("Missing semicolon.", token.line,
  2180. token.from + token.value.length);
  2181. } else {
  2182. adjacent(token, nexttoken);
  2183. advance(';');
  2184. nonadjacent(token, nexttoken);
  2185. }
  2186. }
  2187. // Restore the indentation.
  2188. indent = i;
  2189. scope = s;
  2190. return r;
  2191. }
  2192. function use_strict() {
  2193. if (nexttoken.value === 'use strict') {
  2194. advance();
  2195. advance(';');
  2196. return true;
  2197. } else {
  2198. return false;
  2199. }
  2200. }
  2201. function statements(begin) {
  2202. var a = [], f, p;
  2203. if (begin && !use_strict() && option.strict) {
  2204. warning('Missing "use strict" statement.', nexttoken);
  2205. }
  2206. if (option.adsafe) {
  2207. switch (begin) {
  2208. case 'script':
  2209. if (!adsafe_may) {
  2210. if (nexttoken.value !== 'ADSAFE' ||
  2211. peek(0).id !== '.' ||
  2212. (peek(1).value !== 'id' &&
  2213. peek(1).value !== 'go')) {
  2214. error('ADsafe violation: Missing ADSAFE.id or ADSAFE.go.',
  2215. nexttoken);
  2216. }
  2217. }
  2218. if (nexttoken.value === 'ADSAFE' &&
  2219. peek(0).id === '.' &&
  2220. peek(1).value === 'id') {
  2221. if (adsafe_may) {
  2222. error('ADsafe violation.', nexttoken);
  2223. }
  2224. advance('ADSAFE');
  2225. advance('.');
  2226. advance('id');
  2227. advance('(');
  2228. if (nexttoken.value !== adsafe_id) {
  2229. error('ADsafe violation: id does not match.', nexttoken);
  2230. }
  2231. advance('(string)');
  2232. advance(')');
  2233. advance(';');
  2234. adsafe_may = true;
  2235. }
  2236. break;
  2237. case 'lib':
  2238. if (nexttoken.value === 'ADSAFE') {
  2239. advance('ADSAFE');
  2240. advance('.');
  2241. advance('lib');
  2242. advance('(');
  2243. advance('(string)');
  2244. comma();
  2245. f = parse(0);
  2246. if (f.id !== 'function') {
  2247. error('The second argument to lib must be a function.', f);
  2248. }
  2249. p = f.funct['(params)'].join(', ');
  2250. if (p && p !== 'lib') {
  2251. error("Expected '{a}' and instead saw '{b}'.",
  2252. f, '(lib)', '(' + p + ')');
  2253. }
  2254. advance(')');
  2255. advance(';');
  2256. return a;
  2257. } else {
  2258. error("ADsafe lib violation.");
  2259. }
  2260. }
  2261. }
  2262. while (!nexttoken.reach && nexttoken.id !== '(end)') {
  2263. if (nexttoken.id === ';') {
  2264. warning("Unnecessary semicolon.");
  2265. advance(';');
  2266. } else {
  2267. a.push(statement());
  2268. }
  2269. }
  2270. return a;
  2271. }
  2272. function block(f) {
  2273. var a, b = inblock, s = scope, t;
  2274. inblock = f;
  2275. if (f) {
  2276. scope = Object.create(scope);
  2277. }
  2278. nonadjacent(token, nexttoken);
  2279. t = nexttoken;
  2280. if (nexttoken.id === '{') {
  2281. advance('{');
  2282. if (nexttoken.id !== '}' || token.line !== nexttoken.line) {
  2283. indent += option.indent;
  2284. if (!f && nexttoken.from === indent + option.indent) {
  2285. indent += option.indent;
  2286. }
  2287. if (!f) {
  2288. use_strict();
  2289. }
  2290. a = statements();
  2291. indent -= option.indent;
  2292. indentation();
  2293. }
  2294. advance('}', t);
  2295. } else {
  2296. warning("Expected '{a}' and instead saw '{b}'.",
  2297. nexttoken, '{', nexttoken.value);
  2298. noreach = true;
  2299. a = [statement()];
  2300. noreach = false;
  2301. }
  2302. funct['(verb)'] = null;
  2303. scope = s;
  2304. inblock = b;
  2305. return a;
  2306. }
  2307. // An identity function, used by string and number tokens.
  2308. function idValue() {
  2309. return this;
  2310. }
  2311. function countMember(m) {
  2312. if (membersOnly && typeof membersOnly[m] !== 'boolean') {
  2313. warning("Unexpected /*member '{a}'.", nexttoken, m);
  2314. }
  2315. if (typeof member[m] === 'number') {
  2316. member[m] += 1;
  2317. } else {
  2318. member[m] = 1;
  2319. }
  2320. }
  2321. function note_implied(token) {
  2322. var name = token.value, line = token.line, a = implied[name];
  2323. if (typeof a === 'function') {
  2324. a = false;
  2325. }
  2326. if (!a) {
  2327. a = [line];
  2328. implied[name] = a;
  2329. } else if (a[a.length - 1] !== line) {
  2330. a.push(line);
  2331. }
  2332. }
  2333. // CSS parsing.
  2334. function cssName() {
  2335. if (nexttoken.identifier) {
  2336. advance();
  2337. return true;
  2338. }
  2339. }
  2340. function cssNumber() {
  2341. if (nexttoken.id === '-') {
  2342. advance('-');
  2343. advance('(number)');
  2344. }
  2345. if (nexttoken.type === '(number)') {
  2346. advance();
  2347. return true;
  2348. }
  2349. }
  2350. function cssString() {
  2351. if (nexttoken.type === '(string)') {
  2352. advance();
  2353. return true;
  2354. }
  2355. }
  2356. function cssColor() {
  2357. var i, number;
  2358. if (nexttoken.identifier) {
  2359. if (nexttoken.value === 'rgb') {
  2360. advance();
  2361. advance('(');
  2362. for (i = 0; i < 3; i += 1) {
  2363. number = nexttoken.value;
  2364. if (nexttoken.type !== '(number)' || number < 0) {
  2365. warning("Expected a positive number and instead saw '{a}'",
  2366. nexttoken, number);
  2367. advance();
  2368. } else {
  2369. advance();
  2370. if (nexttoken.id === '%') {
  2371. advance('%');
  2372. if (number > 100) {
  2373. warning("Expected a percentage and instead saw '{a}'",
  2374. token, number);
  2375. }
  2376. } else {
  2377. if (number > 255) {
  2378. warning("Expected a small number and instead saw '{a}'",
  2379. token, number);
  2380. }
  2381. }
  2382. }
  2383. }
  2384. advance(')');
  2385. return true;
  2386. } else if (cssColorData[nexttoken.value] === true) {
  2387. advance();
  2388. return true;
  2389. }
  2390. } else if (nexttoken.type === '(color)') {
  2391. advance();
  2392. return true;
  2393. }
  2394. return false;
  2395. }
  2396. function cssLength() {
  2397. if (nexttoken.id === '-') {
  2398. advance('-');
  2399. adjacent();
  2400. }
  2401. if (nexttoken.type === '(number)') {
  2402. advance();
  2403. if (nexttoken.type !== '(string)' &&
  2404. cssLengthData[nexttoken.value] === true) {
  2405. adjacent();
  2406. advance();
  2407. } else if (+token.value !== 0) {
  2408. warning("Expected a linear unit and instead saw '{a}'.",
  2409. nexttoken, nexttoken.value);
  2410. }
  2411. return true;
  2412. }
  2413. return false;
  2414. }
  2415. function cssLineHeight() {
  2416. if (nexttoken.id === '-') {
  2417. advance('-');
  2418. adjacent();
  2419. }
  2420. if (nexttoken.type === '(number)') {
  2421. advance();
  2422. if (nexttoken.type !== '(string)' &&
  2423. cssLengthData[nexttoken.value] === true) {
  2424. adjacent();
  2425. advance();
  2426. }
  2427. return true;
  2428. }
  2429. return false;
  2430. }
  2431. function cssWidth() {
  2432. if (nexttoken.identifier) {
  2433. switch (nexttoken.value) {
  2434. case 'thin':
  2435. case 'medium':
  2436. case 'thick':
  2437. advance();
  2438. return true;
  2439. }
  2440. } else {
  2441. return cssLength();
  2442. }
  2443. }
  2444. function cssMargin() {
  2445. if (nexttoken.identifier) {
  2446. if (nexttoken.value === 'auto') {
  2447. advance();
  2448. return true;
  2449. }
  2450. } else {
  2451. return cssLength();
  2452. }
  2453. }
  2454. function cssAttr() {
  2455. if (nexttoken.identifier && nexttoken.value === 'attr') {
  2456. advance();
  2457. advance('(');
  2458. if (!nexttoken.identifier) {
  2459. warning("Expected a name and instead saw '{a}'.",
  2460. nexttoken, nexttoken.value);
  2461. }
  2462. advance();
  2463. advance(')');
  2464. return true;
  2465. }
  2466. return false;
  2467. }
  2468. function cssCommaList() {
  2469. while (nexttoken.id !== ';') {
  2470. if (!cssName() && !cssString()) {
  2471. warning("Expected a name and instead saw '{a}'.",
  2472. nexttoken, nexttoken.value);
  2473. }
  2474. if (nexttoken.id !== ',') {
  2475. return true;
  2476. }
  2477. comma();
  2478. }
  2479. }
  2480. function cssCounter() {
  2481. if (nexttoken.identifier && nexttoken.value === 'counter') {
  2482. advance();
  2483. advance('(');
  2484. if (!nexttoken.identifier) {
  2485. }
  2486. advance();
  2487. if (nexttoken.id === ',') {
  2488. comma();
  2489. if (nexttoken.type !== '(string)') {
  2490. warning("Expected a string and instead saw '{a}'.",
  2491. nexttoken, nexttoken.value);
  2492. }
  2493. advance();
  2494. }
  2495. advance(')');
  2496. return true;
  2497. }
  2498. if (nexttoken.identifier && nexttoken.value === 'counters') {
  2499. advance();
  2500. advance('(');
  2501. if (!nexttoken.identifier) {
  2502. warning("Expected a name and instead saw '{a}'.",
  2503. nexttoken, nexttoken.value);
  2504. }
  2505. advance();
  2506. if (nexttoken.id === ',') {
  2507. comma();
  2508. if (nexttoken.type !== '(string)') {
  2509. warning("Expected a string and instead saw '{a}'.",
  2510. nexttoken, nexttoken.value);
  2511. }
  2512. advance();
  2513. }
  2514. if (nexttoken.id === ',') {
  2515. comma();
  2516. if (nexttoken.type !== '(string)') {
  2517. warning("Expected a string and instead saw '{a}'.",
  2518. nexttoken, nexttoken.value);
  2519. }
  2520. advance();
  2521. }
  2522. advance(')');
  2523. return true;
  2524. }
  2525. return false;
  2526. }
  2527. function cssShape() {
  2528. var i;
  2529. if (nexttoken.identifier && nexttoken.value === 'rect') {
  2530. advance();
  2531. advance('(');
  2532. for (i = 0; i < 4; i += 1) {
  2533. if (!cssLength()) {
  2534. warning("Expected a number and instead saw '{a}'.",
  2535. nexttoken, nexttoken.value);
  2536. break;
  2537. }
  2538. }
  2539. advance(')');
  2540. return true;
  2541. }
  2542. return false;
  2543. }
  2544. function cssUrl() {
  2545. var url;
  2546. if (nexttoken.identifier && nexttoken.value === 'url') {
  2547. nexttoken = lex.range('(', ')');
  2548. url = nexttoken.value;
  2549. advance();
  2550. if (option.safe && ux.test(url)) {
  2551. error("ADsafe URL violation.");
  2552. }
  2553. urls.push(url);
  2554. return true;
  2555. }
  2556. return false;
  2557. }
  2558. cssAny = [cssUrl, function () {
  2559. for (;;) {
  2560. if (nexttoken.identifier) {
  2561. switch (nexttoken.value.toLowerCase()) {
  2562. case 'url':
  2563. cssUrl();
  2564. break;
  2565. case 'expression':
  2566. warning("Unexpected expression '{a}'.",
  2567. nexttoken, nexttoken.value);
  2568. advance();
  2569. break;
  2570. default:
  2571. advance();
  2572. }
  2573. } else {
  2574. if (nexttoken.id === ';' || nexttoken.id === '!' ||
  2575. nexttoken.id === '(end)' || nexttoken.id === '}') {
  2576. return true;
  2577. }
  2578. advance();
  2579. }
  2580. }
  2581. }];
  2582. cssBorderStyle = [
  2583. 'none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'ridge',
  2584. 'inset', 'outset'
  2585. ];
  2586. cssBreak = [
  2587. 'auto', 'always', 'avoid', 'left', 'right'
  2588. ];
  2589. cssAttributeData = {
  2590. background: [
  2591. true, 'background-attachment', 'background-color',
  2592. 'background-image', 'background-position', 'background-repeat'
  2593. ],
  2594. 'background-attachment': ['scroll', 'fixed'],
  2595. 'background-color': ['transparent', cssColor],
  2596. 'background-image': ['none', cssUrl],
  2597. 'background-position': [
  2598. 2, [cssLength, 'top', 'bottom', 'left', 'right', 'center']
  2599. ],
  2600. 'background-repeat': [
  2601. 'repeat', 'repeat-x', 'repeat-y', 'no-repeat'
  2602. ],
  2603. 'border': [true, 'border-color', 'border-style', 'border-width'],
  2604. 'border-bottom': [true, 'border-bottom-color', 'border-bottom-style', 'border-bottom-width'],
  2605. 'border-bottom-color': cssColor,
  2606. 'border-bottom-style': cssBorderStyle,
  2607. 'border-bottom-width': cssWidth,
  2608. 'border-collapse': ['collapse', 'separate'],
  2609. 'border-color': ['transparent', 4, cssColor],
  2610. 'border-left': [
  2611. true, 'border-left-color', 'border-left-style', 'border-left-width'
  2612. ],
  2613. 'border-left-color': cssColor,
  2614. 'border-left-style': cssBorderStyle,
  2615. 'border-left-width': cssWidth,
  2616. 'border-right': [
  2617. true, 'border-right-color', 'border-right-style', 'border-right-width'
  2618. ],
  2619. 'border-right-color': cssColor,
  2620. 'border-right-style': cssBorderStyle,
  2621. 'border-right-width': cssWidth,
  2622. 'border-spacing': [2, cssLength],
  2623. 'border-style': [4, cssBorderStyle],
  2624. 'border-top': [
  2625. true, 'border-top-color', 'border-top-style', 'border-top-width'
  2626. ],
  2627. 'border-top-color': cssColor,
  2628. 'border-top-style': cssBorderStyle,
  2629. 'border-top-width': cssWidth,
  2630. 'border-width': [4, cssWidth],
  2631. bottom: [cssLength, 'auto'],
  2632. 'caption-side' : ['bottom', 'left', 'right', 'top'],
  2633. clear: ['both', 'left', 'none', 'right'],
  2634. clip: [cssShape, 'auto'],
  2635. color: cssColor,
  2636. content: [
  2637. 'open-quote', 'close-quote', 'no-open-quote', 'no-close-quote',
  2638. cssString, cssUrl, cssCounter, cssAttr
  2639. ],
  2640. 'counter-increment': [
  2641. cssName, 'none'
  2642. ],
  2643. 'counter-reset': [
  2644. cssName, 'none'
  2645. ],
  2646. cursor: [
  2647. cssUrl, 'auto', 'crosshair', 'default', 'e-resize', 'help', 'move',
  2648. 'n-resize', 'ne-resize', 'nw-resize', 'pointer', 's-resize',
  2649. 'se-resize', 'sw-resize', 'w-resize', 'text', 'wait'
  2650. ],
  2651. direction: ['ltr', 'rtl'],
  2652. display: [
  2653. 'block', 'compact', 'inline', 'inline-block', 'inline-table',
  2654. 'list-item', 'marker', 'none', 'run-in', 'table', 'table-caption',
  2655. 'table-cell', 'table-column', 'table-column-group', 'table-footer-group',
  2656. 'table-header-group', 'table-row', 'table-row-group'
  2657. ],
  2658. 'empty-cells': ['show', 'hide'],
  2659. 'float': ['left', 'none', 'right'],
  2660. font: [
  2661. 'caption', 'icon', 'menu', 'message-box', 'small-caption', 'status-bar',
  2662. true, 'font-size', 'font-style', 'font-weight', 'font-family'
  2663. ],
  2664. 'font-family': cssCommaList,
  2665. 'font-size': [
  2666. 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',
  2667. 'xx-large', 'larger', 'smaller', cssLength
  2668. ],
  2669. 'font-size-adjust': ['none', cssNumber],
  2670. 'font-stretch': [
  2671. 'normal', 'wider', 'narrower', 'ultra-condensed',
  2672. 'extra-condensed', 'condensed', 'semi-condensed',
  2673. 'semi-expanded', 'expanded', 'extra-expanded'
  2674. ],
  2675. 'font-style': [
  2676. 'normal', 'italic', 'oblique'
  2677. ],
  2678. 'font-variant': [
  2679. 'normal', 'small-caps'
  2680. ],
  2681. 'font-weight': [
  2682. 'normal', 'bold', 'bolder', 'lighter', cssNumber
  2683. ],
  2684. height: [cssLength, 'auto'],
  2685. left: [cssLength, 'auto'],
  2686. 'letter-spacing': ['normal', cssLength],
  2687. 'line-height': ['normal', cssLineHeight],
  2688. 'list-style': [
  2689. true, 'list-style-image', 'list-style-position', 'list-style-type'
  2690. ],
  2691. 'list-style-image': ['none', cssUrl],
  2692. 'list-style-position': ['inside', 'outside'],
  2693. 'list-style-type': [
  2694. 'circle', 'disc', 'square', 'decimal', 'decimal-leading-zero',
  2695. 'lower-roman', 'upper-roman', 'lower-greek', 'lower-alpha',
  2696. 'lower-latin', 'upper-alpha', 'upper-latin', 'hebrew', 'katakana',
  2697. 'hiragana-iroha', 'katakana-oroha', 'none'
  2698. ],
  2699. margin: [4, cssMargin],
  2700. 'margin-bottom': cssMargin,
  2701. 'margin-left': cssMargin,
  2702. 'margin-right': cssMargin,
  2703. 'margin-top': cssMargin,
  2704. 'marker-offset': [cssLength, 'auto'],
  2705. 'max-height': [cssLength, 'none'],
  2706. 'max-width': [cssLength, 'none'],
  2707. 'min-height': cssLength,
  2708. 'min-width': cssLength,
  2709. opacity: cssNumber,
  2710. outline: [true, 'outline-color', 'outline-style', 'outline-width'],
  2711. 'outline-color': ['invert', cssColor],
  2712. 'outline-style': [
  2713. 'dashed', 'dotted', 'double', 'groove', 'inset', 'none',
  2714. 'outset', 'ridge', 'solid'
  2715. ],
  2716. 'outline-width': cssWidth,
  2717. overflow: ['auto', 'hidden', 'scroll', 'visible'],
  2718. padding: [4, cssLength],
  2719. 'padding-bottom': cssLength,
  2720. 'padding-left': cssLength,
  2721. 'padding-right': cssLength,
  2722. 'padding-top': cssLength,
  2723. 'page-break-after': cssBreak,
  2724. 'page-break-before': cssBreak,
  2725. position: ['absolute', 'fixed', 'relative', 'static'],
  2726. quotes: [8, cssString],
  2727. right: [cssLength, 'auto'],
  2728. 'table-layout': ['auto', 'fixed'],
  2729. 'text-align': ['center', 'justify', 'left', 'right'],
  2730. 'text-decoration': ['none', 'underline', 'overline', 'line-through', 'blink'],
  2731. 'text-indent': cssLength,
  2732. 'text-shadow': ['none', 4, [cssColor, cssLength]],
  2733. 'text-transform': ['capitalize', 'uppercase', 'lowercase', 'none'],
  2734. top: [cssLength, 'auto'],
  2735. 'unicode-bidi': ['normal', 'embed', 'bidi-override'],
  2736. 'vertical-align': [
  2737. 'baseline', 'bottom', 'sub', 'super', 'top', 'text-top', 'middle',
  2738. 'text-bottom', cssLength
  2739. ],
  2740. visibility: ['visible', 'hidden', 'collapse'],
  2741. 'white-space': ['normal', 'pre', 'nowrap'],
  2742. width: [cssLength, 'auto'],
  2743. 'word-spacing': ['normal', cssLength],
  2744. 'z-index': ['auto', cssNumber]
  2745. };
  2746. function styleAttribute() {
  2747. var v;
  2748. while (nexttoken.id === '*' || nexttoken.id === '#' || nexttoken.value === '_') {
  2749. if (!option.css) {
  2750. warning("Unexpected '{a}'.", nexttoken, nexttoken.value);
  2751. }
  2752. advance();
  2753. }
  2754. if (nexttoken.id === '-') {
  2755. if (!option.css) {
  2756. warning("Unexpected '{a}'.", nexttoken, nexttoken.value);
  2757. }
  2758. advance('-');
  2759. if (!nexttoken.identifier) {
  2760. warning("Expected a non-standard style attribute and instead saw '{a}'.",
  2761. nexttoken, nexttoken.value);
  2762. }
  2763. advance();
  2764. return cssAny;
  2765. } else {
  2766. if (!nexttoken.identifier) {
  2767. warning("Excepted a style attribute, and instead saw '{a}'.",
  2768. nexttoken, nexttoken.value);
  2769. } else {
  2770. if (is_own(cssAttributeData, nexttoken.value)) {
  2771. v = cssAttributeData[nexttoken.value];
  2772. } else {
  2773. v = cssAny;
  2774. if (!option.css) {
  2775. warning("Unrecognized style attribute '{a}'.",
  2776. nexttoken, nexttoken.value);
  2777. }
  2778. }
  2779. }
  2780. advance();
  2781. return v;
  2782. }
  2783. }
  2784. function styleValue(v) {
  2785. var i = 0,
  2786. n,
  2787. once,
  2788. match,
  2789. round,
  2790. start = 0,
  2791. vi;
  2792. switch (typeof v) {
  2793. case 'function':
  2794. return v();
  2795. case 'string':
  2796. if (nexttoken.identifier && nexttoken.value === v) {
  2797. advance();
  2798. return true;
  2799. }
  2800. return false;
  2801. }
  2802. for (;;) {
  2803. if (i >= v.length) {
  2804. return false;
  2805. }
  2806. vi = v[i];
  2807. i += 1;
  2808. if (vi === true) {
  2809. break;
  2810. } else if (typeof vi === 'number') {
  2811. n = vi;
  2812. vi = v[i];
  2813. i += 1;
  2814. } else {
  2815. n = 1;
  2816. }
  2817. match = false;
  2818. while (n > 0) {
  2819. if (styleValue(vi)) {
  2820. match = true;
  2821. n -= 1;
  2822. } else {
  2823. break;
  2824. }
  2825. }
  2826. if (match) {
  2827. return true;
  2828. }
  2829. }
  2830. start = i;
  2831. once = [];
  2832. for (;;) {
  2833. round = false;
  2834. for (i = start; i < v.length; i += 1) {
  2835. if (!once[i]) {
  2836. if (styleValue(cssAttributeData[v[i]])) {
  2837. match = true;
  2838. round = true;
  2839. once[i] = true;
  2840. break;
  2841. }
  2842. }
  2843. }
  2844. if (!round) {
  2845. return match;
  2846. }
  2847. }
  2848. }
  2849. function styleChild() {
  2850. if (nexttoken.id === '(number)') {
  2851. advance();
  2852. if (nexttoken.value === 'n' && nexttoken.identifier) {
  2853. adjacent();
  2854. advance();
  2855. if (nexttoken.id === '+') {
  2856. adjacent();
  2857. advance('+');
  2858. adjacent();
  2859. advance('(number)');
  2860. }
  2861. }
  2862. return;
  2863. } else {
  2864. switch (nexttoken.value) {
  2865. case 'odd':
  2866. case 'even':
  2867. if (nexttoken.identifier) {
  2868. advance();
  2869. return;
  2870. }
  2871. }
  2872. }
  2873. warning("Unexpected token '{a}'.", nexttoken, nexttoken.value);
  2874. }
  2875. function substyle() {
  2876. var v;
  2877. for (;;) {
  2878. if (nexttoken.id === '}' || nexttoken.id === '(end)' ||
  2879. xquote && nexttoken.id === xquote) {
  2880. return;
  2881. }
  2882. while (nexttoken.id === ';') {
  2883. warning("Misplaced ';'.");
  2884. advance(';');
  2885. }
  2886. v = styleAttribute();
  2887. advance(':');
  2888. if (nexttoken.identifier && nexttoken.value === 'inherit') {
  2889. advance();
  2890. } else {
  2891. styleValue(v);
  2892. }
  2893. while (nexttoken.id !== ';' && nexttoken.id !== '!' &&
  2894. nexttoken.id !== '}' && nexttoken.id !== '(end)' &&
  2895. nexttoken.id !== xquote) {
  2896. warning("Unexpected token '{a}'.", nexttoken, nexttoken.value);
  2897. advance();
  2898. }
  2899. if (nexttoken.id === '!') {
  2900. advance('!');
  2901. adjacent();
  2902. if (nexttoken.identifier && nexttoken.value === 'important') {
  2903. advance();
  2904. } else {
  2905. warning("Expected '{a}' and instead saw '{b}'.",
  2906. nexttoken, 'important', nexttoken.value);
  2907. }
  2908. }
  2909. if (nexttoken.id === '}' || nexttoken.id === xquote) {
  2910. warning("Missing '{a}'.", nexttoken, ';');
  2911. } else {
  2912. advance(';');
  2913. }
  2914. }
  2915. }
  2916. function styleSelector() {
  2917. if (nexttoken.identifier) {
  2918. if (!is_own(htmltag, nexttoken.value)) {
  2919. warning("Expected a tagName, and instead saw {a}.",
  2920. nexttoken, nexttoken.value);
  2921. }
  2922. advance();
  2923. } else {
  2924. switch (nexttoken.id) {
  2925. case '>':
  2926. case '+':
  2927. advance();
  2928. if (!nexttoken.identifier ||
  2929. !is_own(htmltag, nexttoken.value)) {
  2930. warning("Expected a tagName, and instead saw {a}.",
  2931. nexttoken, nexttoken.value);
  2932. }
  2933. advance();
  2934. break;
  2935. case ':':
  2936. advance(':');
  2937. switch (nexttoken.value) {
  2938. case 'active':
  2939. case 'after':
  2940. case 'before':
  2941. case 'checked':
  2942. case 'disabled':
  2943. case 'empty':
  2944. case 'enabled':
  2945. case 'first-child':
  2946. case 'first-letter':
  2947. case 'first-line':
  2948. case 'first-of-type':
  2949. case 'focus ':
  2950. case 'hover':
  2951. case 'last-of-type':
  2952. case 'link':
  2953. case 'only-of-type':
  2954. case 'root':
  2955. case 'target':
  2956. case 'visited':
  2957. advance();
  2958. break;
  2959. case 'lang':
  2960. advance();
  2961. advance('(');
  2962. if (!nexttoken.identifier) {
  2963. warning("Expected a lang code, and instead saw :{a}.",
  2964. nexttoken, nexttoken.value);
  2965. }
  2966. advance(')');
  2967. break;
  2968. case 'nth-child':
  2969. case 'nth-last-child':
  2970. case 'nth-last-of-type':
  2971. case 'nth-of-type':
  2972. advance();
  2973. advance('(');
  2974. styleChild();
  2975. advance(')');
  2976. break;
  2977. case 'not':
  2978. advance();
  2979. advance('(');
  2980. if (nexttoken.id === ':' && peek(0).value === 'not') {
  2981. warning("Nested not.");
  2982. }
  2983. styleSelector();
  2984. advance(')');
  2985. break;
  2986. default:
  2987. warning("Expected a pseudo, and instead saw :{a}.",
  2988. nexttoken, nexttoken.value);
  2989. }
  2990. break;
  2991. case '#':
  2992. advance('#');
  2993. if (!nexttoken.identifier) {
  2994. warning("Expected an id, and instead saw #{a}.",
  2995. nexttoken, nexttoken.value);
  2996. }
  2997. advance();
  2998. break;
  2999. case '*':
  3000. advance('*');
  3001. break;
  3002. case '.':
  3003. advance('.');
  3004. if (!nexttoken.identifier) {
  3005. warning("Expected a class, and instead saw #.{a}.",
  3006. nexttoken, nexttoken.value);
  3007. }
  3008. advance();
  3009. break;
  3010. case '[':
  3011. advance('[');
  3012. if (!nexttoken.identifier) {
  3013. warning("Expected an attribute, and instead saw [{a}].",
  3014. nexttoken, nexttoken.value);
  3015. }
  3016. advance();
  3017. if (nexttoken.id === '=' || nexttoken.value === '~=' ||
  3018. nexttoken.value === '$=' ||
  3019. nexttoken.value === '|=' ||
  3020. nexttoken.id === '*=' ||
  3021. nexttoken.id === '^=') {
  3022. advance();
  3023. if (nexttoken.type !== '(string)') {
  3024. warning("Expected a string, and instead saw {a}.",
  3025. nexttoken, nexttoken.value);
  3026. }
  3027. advance();
  3028. }
  3029. advance(']');
  3030. break;
  3031. default:
  3032. error("Expected a CSS selector, and instead saw {a}.",
  3033. nexttoken, nexttoken.value);
  3034. }
  3035. }
  3036. }
  3037. function stylePattern() {
  3038. var name;
  3039. if (nexttoken.id === '{') {
  3040. warning("Expected a style pattern, and instead saw '{a}'.", nexttoken,
  3041. nexttoken.id);
  3042. } else if (nexttoken.id === '@') {
  3043. advance('@');
  3044. name = nexttoken.value;
  3045. if (nexttoken.identifier && atrule[name] === true) {
  3046. advance();
  3047. return name;
  3048. }
  3049. warning("Expected an at-rule, and instead saw @{a}.", nexttoken, name);
  3050. }
  3051. for (;;) {
  3052. styleSelector();
  3053. if (nexttoken.id === '</' || nexttoken.id === '{' ||
  3054. nexttoken.id === '(end)') {
  3055. return '';
  3056. }
  3057. if (nexttoken.id === ',') {
  3058. comma();
  3059. }
  3060. }
  3061. }
  3062. function styles() {
  3063. while (nexttoken.id !== '</' && nexttoken.id !== '(end)') {
  3064. stylePattern();
  3065. xmode = 'styleproperty';
  3066. if (nexttoken.id === ';') {
  3067. advance(';');
  3068. } else {
  3069. advance('{');
  3070. substyle();
  3071. xmode = 'style';
  3072. advance('}');
  3073. }
  3074. }
  3075. }
  3076. // HTML parsing.
  3077. function doBegin(n) {
  3078. if (n !== 'html' && !option.fragment) {
  3079. if (n === 'div' && option.adsafe) {
  3080. error("ADSAFE: Use the fragment option.");
  3081. } else {
  3082. error("Expected '{a}' and instead saw '{b}'.",
  3083. token, 'html', n);
  3084. }
  3085. }
  3086. if (option.adsafe) {
  3087. if (n === 'html') {
  3088. error("Currently, ADsafe does not operate on whole HTML documents. It operates on <div> fragments and .js files.", token);
  3089. }
  3090. if (option.fragment) {
  3091. if (n !== 'div') {
  3092. error("ADsafe violation: Wrap the widget in a div.", token);
  3093. }
  3094. } else {
  3095. error("Use the fragment option.", token);
  3096. }
  3097. }
  3098. option.browser = true;
  3099. assume();
  3100. }
  3101. function doAttribute(n, a, v) {
  3102. var u, x;
  3103. if (a === 'id') {
  3104. u = typeof v === 'string' ? v.toUpperCase() : '';
  3105. if (ids[u] === true) {
  3106. warning("Duplicate id='{a}'.", nexttoken, v);
  3107. }
  3108. if (option.adsafe) {
  3109. if (adsafe_id) {
  3110. if (v.slice(0, adsafe_id.length) !== adsafe_id) {
  3111. warning("ADsafe violation: An id must have a '{a}' prefix",
  3112. nexttoken, adsafe_id);
  3113. } else if (!/^[A-Z]+_[A-Z]+$/.test(v)) {
  3114. warning("ADSAFE violation: bad id.");
  3115. }
  3116. } else {
  3117. adsafe_id = v;
  3118. if (!/^[A-Z]+_$/.test(v)) {
  3119. warning("ADSAFE violation: bad id.");
  3120. }
  3121. }
  3122. }
  3123. x = v.search(dx);
  3124. if (x >= 0) {
  3125. warning("Unexpected character '{a}' in {b}.", token, v.charAt(x), a);
  3126. }
  3127. ids[u] = true;
  3128. } else if (a === 'class' || a === 'type' || a === 'name') {
  3129. x = v.search(qx);
  3130. if (x >= 0) {
  3131. warning("Unexpected character '{a}' in {b}.", token, v.charAt(x), a);
  3132. }
  3133. ids[u] = true;
  3134. } else if (a === 'href' || a === 'background' ||
  3135. a === 'content' || a === 'data' ||
  3136. a.indexOf('src') >= 0 || a.indexOf('url') >= 0) {
  3137. if (option.safe && ux.test(v)) {
  3138. error("ADsafe URL violation.");
  3139. }
  3140. urls.push(v);
  3141. } else if (a === 'for') {
  3142. if (option.adsafe) {
  3143. if (adsafe_id) {
  3144. if (v.slice(0, adsafe_id.length) !== adsafe_id) {
  3145. warning("ADsafe violation: An id must have a '{a}' prefix",
  3146. nexttoken, adsafe_id);
  3147. } else if (!/^[A-Z]+_[A-Z]+$/.test(v)) {
  3148. warning("ADSAFE violation: bad id.");
  3149. }
  3150. } else {
  3151. warning("ADSAFE violation: bad id.");
  3152. }
  3153. }
  3154. } else if (a === 'name') {
  3155. if (option.adsafe && v.indexOf('_') >= 0) {
  3156. warning("ADsafe name violation.");
  3157. }
  3158. }
  3159. }
  3160. function doTag(n, a) {
  3161. var i, t = htmltag[n], x;
  3162. src = false;
  3163. if (!t) {
  3164. error("Unrecognized tag '<{a}>'.",
  3165. nexttoken,
  3166. n === n.toLowerCase() ? n :
  3167. n + ' (capitalization error)');
  3168. }
  3169. if (stack.length > 0) {
  3170. if (n === 'html') {
  3171. error("Too many <html> tags.", token);
  3172. }
  3173. x = t.parent;
  3174. if (x) {
  3175. if (x.indexOf(' ' + stack[stack.length - 1].name + ' ') < 0) {
  3176. error("A '<{a}>' must be within '<{b}>'.",
  3177. token, n, x);
  3178. }
  3179. } else if (!option.adsafe && !option.fragment) {
  3180. i = stack.length;
  3181. do {
  3182. if (i <= 0) {
  3183. error("A '<{a}>' must be within '<{b}>'.",
  3184. token, n, 'body');
  3185. }
  3186. i -= 1;
  3187. } while (stack[i].name !== 'body');
  3188. }
  3189. }
  3190. switch (n) {
  3191. case 'div':
  3192. if (option.adsafe && stack.length === 1 && !adsafe_id) {
  3193. warning("ADSAFE violation: missing ID_.");
  3194. }
  3195. break;
  3196. case 'script':
  3197. xmode = 'script';
  3198. advance('>');
  3199. indent = nexttoken.from;
  3200. if (a.lang) {
  3201. warning("lang is deprecated.", token);
  3202. }
  3203. if (option.adsafe && stack.length !== 1) {
  3204. warning("ADsafe script placement violation.", token);
  3205. }
  3206. if (a.src) {
  3207. if (option.adsafe && (!adsafe_may || !approved[a.src])) {
  3208. warning("ADsafe unapproved script source.", token);
  3209. }
  3210. if (a.type) {
  3211. warning("type is unnecessary.", token);
  3212. }
  3213. } else {
  3214. if (adsafe_went) {
  3215. error("ADsafe script violation.", token);
  3216. }
  3217. statements('script');
  3218. }
  3219. xmode = 'html';
  3220. advance('</');
  3221. if (!nexttoken.identifier && nexttoken.value !== 'script') {
  3222. warning("Expected '{a}' and instead saw '{b}'.",
  3223. nexttoken, 'script', nexttoken.value);
  3224. }
  3225. advance();
  3226. xmode = 'outer';
  3227. break;
  3228. case 'style':
  3229. xmode = 'style';
  3230. advance('>');
  3231. styles();
  3232. xmode = 'html';
  3233. advance('</');
  3234. if (!nexttoken.identifier && nexttoken.value !== 'style') {
  3235. warning("Expected '{a}' and instead saw '{b}'.",
  3236. nexttoken, 'style', nexttoken.value);
  3237. }
  3238. advance();
  3239. xmode = 'outer';
  3240. break;
  3241. case 'input':
  3242. switch (a.type) {
  3243. case 'radio':
  3244. case 'checkbox':
  3245. case 'text':
  3246. case 'button':
  3247. case 'file':
  3248. case 'reset':
  3249. case 'submit':
  3250. case 'password':
  3251. case 'file':
  3252. case 'hidden':
  3253. case 'image':
  3254. break;
  3255. default:
  3256. warning("Bad input type.");
  3257. }
  3258. if (option.adsafe && a.autocomplete !== 'off') {
  3259. warning("ADsafe autocomplete violation.");
  3260. }
  3261. break;
  3262. case 'applet':
  3263. case 'body':
  3264. case 'embed':
  3265. case 'frame':
  3266. case 'frameset':
  3267. case 'head':
  3268. case 'iframe':
  3269. case 'img':
  3270. case 'noembed':
  3271. case 'noframes':
  3272. case 'object':
  3273. case 'param':
  3274. if (option.adsafe) {
  3275. warning("ADsafe violation: Disallowed tag: " + n);
  3276. }
  3277. break;
  3278. }
  3279. }
  3280. function closetag(n) {
  3281. return '</' + n + '>';
  3282. }
  3283. function html() {
  3284. var a, attributes, e, n, q, t, v, w = option.white, wmode;
  3285. xmode = 'html';
  3286. xquote = '';
  3287. stack = null;
  3288. for (;;) {
  3289. switch (nexttoken.value) {
  3290. case '<':
  3291. xmode = 'html';
  3292. advance('<');
  3293. attributes = {};
  3294. t = nexttoken;
  3295. if (!t.identifier) {
  3296. warning("Bad identifier {a}.", t, t.value);
  3297. }
  3298. n = t.value;
  3299. if (option.cap) {
  3300. n = n.toLowerCase();
  3301. }
  3302. t.name = n;
  3303. advance();
  3304. if (!stack) {
  3305. stack = [];
  3306. doBegin(n);
  3307. }
  3308. v = htmltag[n];
  3309. if (typeof v !== 'object') {
  3310. error("Unrecognized tag '<{a}>'.", t, n);
  3311. }
  3312. e = v.empty;
  3313. t.type = n;
  3314. for (;;) {
  3315. if (nexttoken.id === '/') {
  3316. advance('/');
  3317. if (nexttoken.id !== '>') {
  3318. warning("Expected '{a}' and instead saw '{b}'.",
  3319. nexttoken, '>', nexttoken.value);
  3320. }
  3321. break;
  3322. }
  3323. if (nexttoken.id && nexttoken.id.substr(0, 1) === '>') {
  3324. break;
  3325. }
  3326. if (!nexttoken.identifier) {
  3327. if (nexttoken.id === '(end)' || nexttoken.id === '(error)') {
  3328. error("Missing '>'.", nexttoken);
  3329. }
  3330. warning("Bad identifier.");
  3331. }
  3332. option.white = true;
  3333. nonadjacent(token, nexttoken);
  3334. a = nexttoken.value;
  3335. option.white = w;
  3336. advance();
  3337. if (!option.cap && a !== a.toLowerCase()) {
  3338. warning("Attribute '{a}' not all lower case.", nexttoken, a);
  3339. }
  3340. a = a.toLowerCase();
  3341. xquote = '';
  3342. if (is_own(attributes, a)) {
  3343. warning("Attribute '{a}' repeated.", nexttoken, a);
  3344. }
  3345. if (a.slice(0, 2) === 'on') {
  3346. if (!option.on) {
  3347. warning("Avoid HTML event handlers.");
  3348. }
  3349. xmode = 'scriptstring';
  3350. advance('=');
  3351. q = nexttoken.id;
  3352. if (q !== '"' && q !== "'") {
  3353. error("Missing quote.");
  3354. }
  3355. xquote = q;
  3356. wmode = option.white;
  3357. option.white = false;
  3358. advance(q);
  3359. statements('on');
  3360. option.white = wmode;
  3361. if (nexttoken.id !== q) {
  3362. error("Missing close quote on script attribute.");
  3363. }
  3364. xmode = 'html';
  3365. xquote = '';
  3366. advance(q);
  3367. v = false;
  3368. } else if (a === 'style') {
  3369. xmode = 'scriptstring';
  3370. advance('=');
  3371. q = nexttoken.id;
  3372. if (q !== '"' && q !== "'") {
  3373. error("Missing quote.");
  3374. }
  3375. xmode = 'styleproperty';
  3376. xquote = q;
  3377. advance(q);
  3378. substyle();
  3379. xmode = 'html';
  3380. xquote = '';
  3381. advance(q);
  3382. v = false;
  3383. } else {
  3384. if (nexttoken.id === '=') {
  3385. advance('=');
  3386. v = nexttoken.value;
  3387. if (!nexttoken.identifier &&
  3388. nexttoken.id !== '"' &&
  3389. nexttoken.id !== '\'' &&
  3390. nexttoken.type !== '(string)' &&
  3391. nexttoken.type !== '(number)' &&
  3392. nexttoken.type !== '(color)') {
  3393. warning("Expected an attribute value and instead saw '{a}'.", token, a);
  3394. }
  3395. advance();
  3396. } else {
  3397. v = true;
  3398. }
  3399. }
  3400. attributes[a] = v;
  3401. doAttribute(n, a, v);
  3402. }
  3403. doTag(n, attributes);
  3404. if (!e) {
  3405. stack.push(t);
  3406. }
  3407. xmode = 'outer';
  3408. advance('>');
  3409. break;
  3410. case '</':
  3411. xmode = 'html';
  3412. advance('</');
  3413. if (!nexttoken.identifier) {
  3414. warning("Bad identifier.");
  3415. }
  3416. n = nexttoken.value;
  3417. if (option.cap) {
  3418. n = n.toLowerCase();
  3419. }
  3420. advance();
  3421. if (!stack) {
  3422. error("Unexpected '{a}'.", nexttoken, closetag(n));
  3423. }
  3424. t = stack.pop();
  3425. if (!t) {
  3426. error("Unexpected '{a}'.", nexttoken, closetag(n));
  3427. }
  3428. if (t.name !== n) {
  3429. error("Expected '{a}' and instead saw '{b}'.",
  3430. nexttoken, closetag(t.name), closetag(n));
  3431. }
  3432. if (nexttoken.id !== '>') {
  3433. error("Missing '{a}'.", nexttoken, '>');
  3434. }
  3435. xmode = 'outer';
  3436. advance('>');
  3437. break;
  3438. case '<!':
  3439. if (option.safe) {
  3440. warning("ADsafe HTML violation.");
  3441. }
  3442. xmode = 'html';
  3443. for (;;) {
  3444. advance();
  3445. if (nexttoken.id === '>' || nexttoken.id === '(end)') {
  3446. break;
  3447. }
  3448. if (nexttoken.value.indexOf('--') >= 0) {
  3449. warning("Unexpected --.");
  3450. }
  3451. if (nexttoken.value.indexOf('<') >= 0) {
  3452. warning("Unexpected <.");
  3453. }
  3454. if (nexttoken.value.indexOf('>') >= 0) {
  3455. warning("Unexpected >.");
  3456. }
  3457. }
  3458. xmode = 'outer';
  3459. advance('>');
  3460. break;
  3461. case '(end)':
  3462. return;
  3463. default:
  3464. if (nexttoken.id === '(end)') {
  3465. error("Missing '{a}'.", nexttoken,
  3466. '</' + stack[stack.length - 1].value + '>');
  3467. } else {
  3468. advance();
  3469. }
  3470. }
  3471. if (stack && stack.length === 0 && (option.adsafe ||
  3472. !option.fragment || nexttoken.id === '(end)')) {
  3473. break;
  3474. }
  3475. }
  3476. if (nexttoken.id !== '(end)') {
  3477. error("Unexpected material after the end.");
  3478. }
  3479. }
  3480. // Build the syntax table by declaring the syntactic elements of the language.
  3481. type('(number)', idValue);
  3482. type('(string)', idValue);
  3483. syntax['(identifier)'] = {
  3484. type: '(identifier)',
  3485. lbp: 0,
  3486. identifier: true,
  3487. nud: function () {
  3488. var v = this.value,
  3489. s = scope[v],
  3490. f;
  3491. if (typeof s === 'function') {
  3492. s = undefined;
  3493. } else if (typeof s === 'boolean') {
  3494. f = funct;
  3495. funct = functions[0];
  3496. addlabel(v, 'var');
  3497. s = funct;
  3498. funct = f;
  3499. }
  3500. // The name is in scope and defined in the current function.
  3501. if (funct === s) {
  3502. // Change 'unused' to 'var', and reject labels.
  3503. switch (funct[v]) {
  3504. case 'unused':
  3505. funct[v] = 'var';
  3506. break;
  3507. case 'label':
  3508. warning("'{a}' is a statement label.", token, v);
  3509. break;
  3510. }
  3511. // The name is not defined in the function. If we are in the global scope,
  3512. // then we have an undefined variable.
  3513. } else if (funct['(global)']) {
  3514. if (option.undef && predefined[v] !== 'boolean') {
  3515. warning("'{a}' is not defined.", token, v);
  3516. }
  3517. note_implied(token);
  3518. // If the name is already defined in the current
  3519. // function, but not as outer, then there is a scope error.
  3520. } else {
  3521. switch (funct[v]) {
  3522. case 'closure':
  3523. case 'function':
  3524. case 'var':
  3525. case 'unused':
  3526. warning("'{a}' used out of scope.", token, v);
  3527. break;
  3528. case 'label':
  3529. warning("'{a}' is a statement label.", token, v);
  3530. break;
  3531. case 'outer':
  3532. case 'global':
  3533. break;
  3534. default:
  3535. // If the name is defined in an outer function, make an outer entry, and if
  3536. // it was unused, make it var.
  3537. if (s === true) {
  3538. funct[v] = true;
  3539. } else if (typeof s !== 'object') {
  3540. if (option.undef) {
  3541. warning("'{a}' is not defined.", token, v);
  3542. } else {
  3543. funct[v] = true;
  3544. }
  3545. note_implied(token);
  3546. } else {
  3547. switch (s[v]) {
  3548. case 'function':
  3549. case 'var':
  3550. case 'unused':
  3551. s[v] = 'closure';
  3552. funct[v] = s['(global)'] ? 'global' : 'outer';
  3553. break;
  3554. case 'closure':
  3555. case 'parameter':
  3556. funct[v] = s['(global)'] ? 'global' : 'outer';
  3557. break;
  3558. case 'label':
  3559. warning("'{a}' is a statement label.", token, v);
  3560. }
  3561. }
  3562. }
  3563. }
  3564. return this;
  3565. },
  3566. led: function () {
  3567. error("Expected an operator and instead saw '{a}'.",
  3568. nexttoken, nexttoken.value);
  3569. }
  3570. };
  3571. type('(regexp)', function () {
  3572. return this;
  3573. });
  3574. delim('(endline)');
  3575. delim('(begin)');
  3576. delim('(end)').reach = true;
  3577. delim('</').reach = true;
  3578. delim('<!');
  3579. delim('<!--');
  3580. delim('-->');
  3581. delim('(error)').reach = true;
  3582. delim('}').reach = true;
  3583. delim(')');
  3584. delim(']');
  3585. delim('"').reach = true;
  3586. delim("'").reach = true;
  3587. delim(';');
  3588. delim(':').reach = true;
  3589. delim(',');
  3590. delim('#');
  3591. delim('@');
  3592. reserve('else');
  3593. reserve('case').reach = true;
  3594. reserve('catch');
  3595. reserve('default').reach = true;
  3596. reserve('finally');
  3597. reservevar('arguments');
  3598. reservevar('eval');
  3599. reservevar('false');
  3600. reservevar('Infinity');
  3601. reservevar('NaN');
  3602. reservevar('null');
  3603. reservevar('this');
  3604. reservevar('true');
  3605. reservevar('undefined');
  3606. assignop('=', 'assign', 20);
  3607. assignop('+=', 'assignadd', 20);
  3608. assignop('-=', 'assignsub', 20);
  3609. assignop('*=', 'assignmult', 20);
  3610. assignop('/=', 'assigndiv', 20).nud = function () {
  3611. error("A regular expression literal can be confused with '/='.");
  3612. };
  3613. assignop('%=', 'assignmod', 20);
  3614. bitwiseassignop('&=', 'assignbitand', 20);
  3615. bitwiseassignop('|=', 'assignbitor', 20);
  3616. bitwiseassignop('^=', 'assignbitxor', 20);
  3617. bitwiseassignop('<<=', 'assignshiftleft', 20);
  3618. bitwiseassignop('>>=', 'assignshiftright', 20);
  3619. bitwiseassignop('>>>=', 'assignshiftrightunsigned', 20);
  3620. infix('?', function (left, that) {
  3621. that.left = left;
  3622. that.right = parse(10);
  3623. advance(':');
  3624. that['else'] = parse(10);
  3625. return that;
  3626. }, 30);
  3627. infix('||', 'or', 40);
  3628. infix('&&', 'and', 50);
  3629. bitwise('|', 'bitor', 70);
  3630. bitwise('^', 'bitxor', 80);
  3631. bitwise('&', 'bitand', 90);
  3632. relation('==', function (left, right) {
  3633. if (option.eqeqeq) {
  3634. warning("Expected '{a}' and instead saw '{b}'.",
  3635. this, '===', '==');
  3636. } else if (isPoorRelation(left)) {
  3637. warning("Use '{a}' to compare with '{b}'.",
  3638. this, '===', left.value);
  3639. } else if (isPoorRelation(right)) {
  3640. warning("Use '{a}' to compare with '{b}'.",
  3641. this, '===', right.value);
  3642. }
  3643. return this;
  3644. });
  3645. relation('===');
  3646. relation('!=', function (left, right) {
  3647. if (option.eqeqeq) {
  3648. warning("Expected '{a}' and instead saw '{b}'.",
  3649. this, '!==', '!=');
  3650. } else if (isPoorRelation(left)) {
  3651. warning("Use '{a}' to compare with '{b}'.",
  3652. this, '!==', left.value);
  3653. } else if (isPoorRelation(right)) {
  3654. warning("Use '{a}' to compare with '{b}'.",
  3655. this, '!==', right.value);
  3656. }
  3657. return this;
  3658. });
  3659. relation('!==');
  3660. relation('<');
  3661. relation('>');
  3662. relation('<=');
  3663. relation('>=');
  3664. bitwise('<<', 'shiftleft', 120);
  3665. bitwise('>>', 'shiftright', 120);
  3666. bitwise('>>>', 'shiftrightunsigned', 120);
  3667. infix('in', 'in', 120);
  3668. infix('instanceof', 'instanceof', 120);
  3669. infix('+', function (left, that) {
  3670. var right = parse(130);
  3671. if (left && right && left.id === '(string)' && right.id === '(string)') {
  3672. left.value += right.value;
  3673. left.character = right.character;
  3674. if (jx.test(left.value)) {
  3675. warning("JavaScript URL.", left);
  3676. }
  3677. return left;
  3678. }
  3679. that.left = left;
  3680. that.right = right;
  3681. return that;
  3682. }, 130);
  3683. prefix('+', 'num');
  3684. infix('-', 'sub', 130);
  3685. prefix('-', 'neg');
  3686. infix('*', 'mult', 140);
  3687. infix('/', 'div', 140);
  3688. infix('%', 'mod', 140);
  3689. suffix('++', 'postinc');
  3690. prefix('++', 'preinc');
  3691. syntax['++'].exps = true;
  3692. suffix('--', 'postdec');
  3693. prefix('--', 'predec');
  3694. syntax['--'].exps = true;
  3695. prefix('delete', function () {
  3696. var p = parse(0);
  3697. if (!p || (p.id !== '.' && p.id !== '[')) {
  3698. warning("Expected '{a}' and instead saw '{b}'.",
  3699. nexttoken, '.', nexttoken.value);
  3700. }
  3701. }).exps = true;
  3702. prefix('~', function () {
  3703. if (option.bitwise) {
  3704. warning("Unexpected '{a}'.", this, '~');
  3705. }
  3706. parse(150);
  3707. return this;
  3708. });
  3709. prefix('!', 'not');
  3710. prefix('typeof', 'typeof');
  3711. prefix('new', function () {
  3712. var c = parse(155), i;
  3713. if (c && c.id !== 'function') {
  3714. if (c.identifier) {
  3715. c['new'] = true;
  3716. switch (c.value) {
  3717. case 'Object':
  3718. warning("Use the object literal notation {}.", token);
  3719. break;
  3720. case 'Array':
  3721. if (nexttoken.id !== '(') {
  3722. warning("Use the array literal notation [].", token);
  3723. } else {
  3724. advance('(');
  3725. if (nexttoken.id === ')') {
  3726. warning("Use the array literal notation [].", token);
  3727. } else {
  3728. i = parse(0);
  3729. c.dimension = i;
  3730. if ((i.id === '(number)' && /[.+\-Ee]/.test(i.value)) ||
  3731. (i.id === '-' && !i.right) ||
  3732. i.id === '(string)' || i.id === '[' ||
  3733. i.id === '{' || i.id === 'true' ||
  3734. i.id === 'false' ||
  3735. i.id === 'null' || i.id === 'undefined' ||
  3736. i.id === 'Infinity') {
  3737. warning("Use the array literal notation [].", token);
  3738. }
  3739. if (nexttoken.id !== ')') {
  3740. error("Use the array literal notation [].", token);
  3741. }
  3742. }
  3743. advance(')');
  3744. }
  3745. this.first = c;
  3746. return this;
  3747. case 'Number':
  3748. case 'String':
  3749. case 'Boolean':
  3750. case 'Math':
  3751. warning("Do not use {a} as a constructor.", token, c.value);
  3752. break;
  3753. case 'Function':
  3754. if (!option.evil) {
  3755. warning("The Function constructor is eval.");
  3756. }
  3757. break;
  3758. case 'Date':
  3759. case 'RegExp':
  3760. break;
  3761. default:
  3762. if (c.id !== 'function') {
  3763. i = c.value.substr(0, 1);
  3764. if (option.newcap && (i < 'A' || i > 'Z')) {
  3765. warning(
  3766. "A constructor name should start with an uppercase letter.",
  3767. token);
  3768. }
  3769. }
  3770. }
  3771. } else {
  3772. if (c.id !== '.' && c.id !== '[' && c.id !== '(') {
  3773. warning("Bad constructor.", token);
  3774. }
  3775. }
  3776. } else {
  3777. warning("Weird construction. Delete 'new'.", this);
  3778. }
  3779. adjacent(token, nexttoken);
  3780. if (nexttoken.id !== '(') {
  3781. warning("Missing '()' invoking a constructor.");
  3782. }
  3783. this.first = c;
  3784. return this;
  3785. });
  3786. syntax['new'].exps = true;
  3787. infix('.', function (left, that) {
  3788. adjacent(prevtoken, token);
  3789. var m = identifier();
  3790. if (typeof m === 'string') {
  3791. countMember(m);
  3792. }
  3793. that.left = left;
  3794. that.right = m;
  3795. if (!option.evil && left && left.value === 'document' &&
  3796. (m === 'write' || m === 'writeln')) {
  3797. warning("document.write can be a form of eval.", left);
  3798. } else if (option.adsafe) {
  3799. if (left && left.value === 'ADSAFE') {
  3800. if (m === 'id' || m === 'lib') {
  3801. warning("ADsafe violation.", that);
  3802. } else if (m === 'go') {
  3803. if (xmode !== 'script') {
  3804. warning("ADsafe violation.", that);
  3805. } else if (adsafe_went || nexttoken.id !== '(' ||
  3806. peek(0).id !== '(string)' ||
  3807. peek(0).value !== adsafe_id ||
  3808. peek(1).id !== ',') {
  3809. error("ADsafe violation: go.", that);
  3810. }
  3811. adsafe_went = true;
  3812. adsafe_may = false;
  3813. }
  3814. }
  3815. }
  3816. if (!option.evil && (m === 'eval' || m === 'execScript')) {
  3817. warning('eval is evil.');
  3818. } else if (option.safe) {
  3819. for (;;) {
  3820. if (banned[m] === true) {
  3821. warning("ADsafe restricted word '{a}'.", token, m);
  3822. }
  3823. if (typeof predefined[left.value] !== 'boolean' ||
  3824. nexttoken.id === '(') {
  3825. break;
  3826. }
  3827. if (standard_member[m] === true) {
  3828. if (nexttoken.id === '.') {
  3829. warning("ADsafe violation.", that);
  3830. }
  3831. break;
  3832. }
  3833. if (nexttoken.id !== '.') {
  3834. warning("ADsafe violation.", that);
  3835. break;
  3836. }
  3837. advance('.');
  3838. token.left = that;
  3839. token.right = m;
  3840. that = token;
  3841. m = identifier();
  3842. if (typeof m === 'string') {
  3843. countMember(m);
  3844. }
  3845. }
  3846. }
  3847. return that;
  3848. }, 160, true);
  3849. infix('(', function (left, that) {
  3850. adjacent(prevtoken, token);
  3851. nospace();
  3852. var n = 0,
  3853. p = [];
  3854. if (left) {
  3855. if (left.type === '(identifier)') {
  3856. if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) {
  3857. if (left.value !== 'Number' && left.value !== 'String' &&
  3858. left.value !== 'Boolean' &&
  3859. left.value !== 'Date') {
  3860. if (left.value === 'Math') {
  3861. warning("Math is not a function.", left);
  3862. } else if (option.newcap) {
  3863. warning(
  3864. "Missing 'new' prefix when invoking a constructor.", left);
  3865. }
  3866. }
  3867. }
  3868. } else if (left.id === '.') {
  3869. if (option.safe && left.left.value === 'Math' &&
  3870. left.right === 'random') {
  3871. warning("ADsafe violation.", left);
  3872. }
  3873. }
  3874. }
  3875. if (nexttoken.id !== ')') {
  3876. for (;;) {
  3877. p[p.length] = parse(10);
  3878. n += 1;
  3879. if (nexttoken.id !== ',') {
  3880. break;
  3881. }
  3882. comma();
  3883. }
  3884. }
  3885. advance(')');
  3886. if (option.immed && left.id === 'function' && nexttoken.id !== ')') {
  3887. warning("Wrap the entire immediate function invocation in parens.",
  3888. that);
  3889. }
  3890. nospace(prevtoken, token);
  3891. if (typeof left === 'object') {
  3892. if (left.value === 'parseInt' && n === 1) {
  3893. warning("Missing radix parameter.", left);
  3894. }
  3895. if (!option.evil) {
  3896. if (left.value === 'eval' || left.value === 'Function' ||
  3897. left.value === 'execScript') {
  3898. warning("eval is evil.", left);
  3899. } else if (p[0] && p[0].id === '(string)' &&
  3900. (left.value === 'setTimeout' ||
  3901. left.value === 'setInterval')) {
  3902. warning(
  3903. "Implied eval is evil. Pass a function instead of a string.", left);
  3904. }
  3905. }
  3906. if (!left.identifier && left.id !== '.' && left.id !== '[' &&
  3907. left.id !== '(' && left.id !== '&&' && left.id !== '||' &&
  3908. left.id !== '?') {
  3909. warning("Bad invocation.", left);
  3910. }
  3911. }
  3912. that.left = left;
  3913. return that;
  3914. }, 155, true).exps = true;
  3915. prefix('(', function () {
  3916. nospace();
  3917. var v = parse(0);
  3918. advance(')', this);
  3919. nospace(prevtoken, token);
  3920. if (option.immed && v.id === 'function') {
  3921. if (nexttoken.id === '(') {
  3922. warning(
  3923. "Move the invocation into the parens that contain the function.", nexttoken);
  3924. } else {
  3925. warning(
  3926. "Do not wrap function literals in parens unless they are to be immediately invoked.",
  3927. this);
  3928. }
  3929. }
  3930. return v;
  3931. });
  3932. infix('[', function (left, that) {
  3933. nospace();
  3934. var e = parse(0), s;
  3935. if (e && e.type === '(string)') {
  3936. if (option.safe && banned[e.value] === true) {
  3937. warning("ADsafe restricted word '{a}'.", that, e.value);
  3938. } else if (!option.evil &&
  3939. (e.value === 'eval' || e.value === 'execScript')) {
  3940. warning("eval is evil.", that);
  3941. } else if (option.safe &&
  3942. (e.value.charAt(0) === '_' || e.value.charAt(0) === '-')) {
  3943. warning("ADsafe restricted subscript '{a}'.", that, e.value);
  3944. }
  3945. countMember(e.value);
  3946. if (!option.sub && ix.test(e.value)) {
  3947. s = syntax[e.value];
  3948. if (!s || !s.reserved) {
  3949. warning("['{a}'] is better written in dot notation.",
  3950. e, e.value);
  3951. }
  3952. }
  3953. } else if (!e || e.type !== '(number)' || e.value < 0) {
  3954. if (option.safe) {
  3955. warning('ADsafe subscripting.');
  3956. }
  3957. }
  3958. advance(']', that);
  3959. nospace(prevtoken, token);
  3960. that.left = left;
  3961. that.right = e;
  3962. return that;
  3963. }, 160, true);
  3964. prefix('[', function () {
  3965. this.first = [];
  3966. if (nexttoken.id === ']') {
  3967. advance(']');
  3968. return this;
  3969. }
  3970. var b = token.line !== nexttoken.line;
  3971. if (b) {
  3972. indent += option.indent;
  3973. if (nexttoken.from === indent + option.indent) {
  3974. indent += option.indent;
  3975. }
  3976. }
  3977. for (;;) {
  3978. if (b && token.line !== nexttoken.line) {
  3979. indentation();
  3980. }
  3981. parse(10);
  3982. if (nexttoken.id === ',') {
  3983. comma();
  3984. if (nexttoken.id === ',') {
  3985. warning("Extra comma.", token);
  3986. } else if (nexttoken.id === ']') {
  3987. warning("Extra comma.", token);
  3988. break;
  3989. }
  3990. } else {
  3991. if (b) {
  3992. indent -= option.indent;
  3993. indentation();
  3994. }
  3995. break;
  3996. }
  3997. }
  3998. advance(']', this);
  3999. return this;
  4000. }, 160);
  4001. (function (x) {
  4002. x.nud = function () {
  4003. var b, i, s, seen = {};
  4004. b = token.line !== nexttoken.line;
  4005. if (b) {
  4006. indent += option.indent;
  4007. if (nexttoken.from === indent + option.indent) {
  4008. indent += option.indent;
  4009. }
  4010. }
  4011. for (;;) {
  4012. if (nexttoken.id === '}') {
  4013. break;
  4014. }
  4015. if (b) {
  4016. indentation();
  4017. }
  4018. i = optionalidentifier(true);
  4019. if (!i) {
  4020. if (nexttoken.id === '(string)') {
  4021. i = nexttoken.value;
  4022. if (ix.test(i)) {
  4023. s = syntax[i];
  4024. }
  4025. advance();
  4026. } else if (nexttoken.id === '(number)') {
  4027. i = nexttoken.value.toString();
  4028. advance();
  4029. } else {
  4030. error("Expected '{a}' and instead saw '{b}'.",
  4031. nexttoken, '}', nexttoken.value);
  4032. }
  4033. }
  4034. if (seen[i] === true) {
  4035. warning("Duplicate member '{a}'.", nexttoken, i);
  4036. }
  4037. seen[i] = true;
  4038. countMember(i);
  4039. advance(':');
  4040. nonadjacent(token, nexttoken);
  4041. parse(10);
  4042. if (nexttoken.id === ',') {
  4043. comma();
  4044. if (nexttoken.id === ',' || nexttoken.id === '}') {
  4045. warning("Extra comma.", token);
  4046. }
  4047. } else {
  4048. break;
  4049. }
  4050. }
  4051. if (b) {
  4052. indent -= option.indent;
  4053. indentation();
  4054. }
  4055. advance('}', this);
  4056. return this;
  4057. };
  4058. x.fud = function () {
  4059. error("Expected to see a statement and instead saw a block.", token);
  4060. };
  4061. }(delim('{')));
  4062. function varstatement(prefix) {
  4063. // JavaScript does not have block scope. It only has function scope. So,
  4064. // declaring a variable in a block can have unexpected consequences.
  4065. var id, name, value;
  4066. if (funct['(onevar)'] && option.onevar) {
  4067. warning("Too many var statements.");
  4068. } else if (!funct['(global)']) {
  4069. funct['(onevar)'] = true;
  4070. }
  4071. this.first = [];
  4072. for (;;) {
  4073. nonadjacent(token, nexttoken);
  4074. id = identifier();
  4075. if (funct['(global)'] && predefined[id] === false) {
  4076. warning("Redefinition of '{a}'.", token, id);
  4077. }
  4078. addlabel(id, 'unused');
  4079. if (prefix) {
  4080. break;
  4081. }
  4082. name = token;
  4083. this.first.push(token);
  4084. if (nexttoken.id === '=') {
  4085. nonadjacent(token, nexttoken);
  4086. advance('=');
  4087. nonadjacent(token, nexttoken);
  4088. if (peek(0).id === '=' && nexttoken.identifier) {
  4089. error("Variable {a} was not declared correctly.",
  4090. nexttoken, nexttoken.value);
  4091. }
  4092. value = parse(0);
  4093. name.first = value;
  4094. }
  4095. if (nexttoken.id !== ',') {
  4096. break;
  4097. }
  4098. comma();
  4099. }
  4100. return this;
  4101. }
  4102. stmt('var', varstatement);
  4103. stmt('new', function () {
  4104. warning("'new' should not be used as a statement.");
  4105. });
  4106. function functionparams() {
  4107. var i, t = nexttoken, p = [];
  4108. advance('(');
  4109. nospace();
  4110. if (nexttoken.id === ')') {
  4111. advance(')');
  4112. nospace(prevtoken, token);
  4113. return;
  4114. }
  4115. for (;;) {
  4116. i = identifier();
  4117. p.push(i);
  4118. addlabel(i, 'parameter');
  4119. if (nexttoken.id === ',') {
  4120. comma();
  4121. } else {
  4122. advance(')', t);
  4123. nospace(prevtoken, token);
  4124. return p;
  4125. }
  4126. }
  4127. }
  4128. function doFunction(i) {
  4129. var s = scope;
  4130. scope = Object.create(s);
  4131. funct = {
  4132. '(name)' : i || '"' + anonname + '"',
  4133. '(line)' : nexttoken.line,
  4134. '(context)' : funct,
  4135. '(breakage)': 0,
  4136. '(loopage)' : 0,
  4137. '(scope)' : scope
  4138. };
  4139. token.funct = funct;
  4140. functions.push(funct);
  4141. if (i) {
  4142. addlabel(i, 'function');
  4143. }
  4144. funct['(params)'] = functionparams();
  4145. block(false);
  4146. scope = s;
  4147. funct['(last)'] = token.line;
  4148. funct = funct['(context)'];
  4149. }
  4150. blockstmt('function', function () {
  4151. if (inblock) {
  4152. warning(
  4153. "Function statements cannot be placed in blocks. Use a function expression or move the statement to the top of the outer function.", token);
  4154. }
  4155. var i = identifier();
  4156. adjacent(token, nexttoken);
  4157. addlabel(i, 'unused');
  4158. doFunction(i);
  4159. if (nexttoken.id === '(' && nexttoken.line === token.line) {
  4160. error(
  4161. "Function statements are not invocable. Wrap the whole function invocation in parens.");
  4162. }
  4163. });
  4164. prefix('function', function () {
  4165. var i = optionalidentifier();
  4166. if (i) {
  4167. adjacent(token, nexttoken);
  4168. } else {
  4169. nonadjacent(token, nexttoken);
  4170. }
  4171. doFunction(i);
  4172. if (funct['(loopage)'] && nexttoken.id !== '(') {
  4173. warning("Be careful when making functions within a loop. Consider putting the function in a closure.");
  4174. }
  4175. return this;
  4176. });
  4177. blockstmt('if', function () {
  4178. var t = nexttoken;
  4179. advance('(');
  4180. nonadjacent(this, t);
  4181. nospace();
  4182. parse(20);
  4183. if (nexttoken.id === '=') {
  4184. warning("Expected a conditional expression and instead saw an assignment.");
  4185. advance('=');
  4186. parse(20);
  4187. }
  4188. advance(')', t);
  4189. nospace(prevtoken, token);
  4190. block(true);
  4191. if (nexttoken.id === 'else') {
  4192. nonadjacent(token, nexttoken);
  4193. advance('else');
  4194. if (nexttoken.id === 'if' || nexttoken.id === 'switch') {
  4195. statement(true);
  4196. } else {
  4197. block(true);
  4198. }
  4199. }
  4200. return this;
  4201. });
  4202. blockstmt('try', function () {
  4203. var b, e, s;
  4204. if (option.adsafe) {
  4205. warning("ADsafe try violation.", this);
  4206. }
  4207. block(false);
  4208. if (nexttoken.id === 'catch') {
  4209. advance('catch');
  4210. nonadjacent(token, nexttoken);
  4211. advance('(');
  4212. s = scope;
  4213. scope = Object.create(s);
  4214. e = nexttoken.value;
  4215. if (nexttoken.type !== '(identifier)') {
  4216. warning("Expected an identifier and instead saw '{a}'.",
  4217. nexttoken, e);
  4218. } else {
  4219. addlabel(e, 'exception');
  4220. }
  4221. advance();
  4222. advance(')');
  4223. block(false);
  4224. b = true;
  4225. scope = s;
  4226. }
  4227. if (nexttoken.id === 'finally') {
  4228. advance('finally');
  4229. block(false);
  4230. return;
  4231. } else if (!b) {
  4232. error("Expected '{a}' and instead saw '{b}'.",
  4233. nexttoken, 'catch', nexttoken.value);
  4234. }
  4235. });
  4236. blockstmt('while', function () {
  4237. var t = nexttoken;
  4238. funct['(breakage)'] += 1;
  4239. funct['(loopage)'] += 1;
  4240. advance('(');
  4241. nonadjacent(this, t);
  4242. nospace();
  4243. parse(20);
  4244. if (nexttoken.id === '=') {
  4245. warning("Expected a conditional expression and instead saw an assignment.");
  4246. advance('=');
  4247. parse(20);
  4248. }
  4249. advance(')', t);
  4250. nospace(prevtoken, token);
  4251. block(true);
  4252. funct['(breakage)'] -= 1;
  4253. funct['(loopage)'] -= 1;
  4254. }).labelled = true;
  4255. reserve('with');
  4256. blockstmt('switch', function () {
  4257. var t = nexttoken,
  4258. g = false;
  4259. funct['(breakage)'] += 1;
  4260. advance('(');
  4261. nonadjacent(this, t);
  4262. nospace();
  4263. this.condition = parse(20);
  4264. advance(')', t);
  4265. nospace(prevtoken, token);
  4266. nonadjacent(token, nexttoken);
  4267. t = nexttoken;
  4268. advance('{');
  4269. nonadjacent(token, nexttoken);
  4270. indent += option.indent;
  4271. this.cases = [];
  4272. for (;;) {
  4273. switch (nexttoken.id) {
  4274. case 'case':
  4275. switch (funct['(verb)']) {
  4276. case 'break':
  4277. case 'case':
  4278. case 'continue':
  4279. case 'return':
  4280. case 'switch':
  4281. case 'throw':
  4282. break;
  4283. default:
  4284. warning(
  4285. "Expected a 'break' statement before 'case'.",
  4286. token);
  4287. }
  4288. indentation(-option.indent);
  4289. advance('case');
  4290. this.cases.push(parse(20));
  4291. g = true;
  4292. advance(':');
  4293. funct['(verb)'] = 'case';
  4294. break;
  4295. case 'default':
  4296. switch (funct['(verb)']) {
  4297. case 'break':
  4298. case 'continue':
  4299. case 'return':
  4300. case 'throw':
  4301. break;
  4302. default:
  4303. warning(
  4304. "Expected a 'break' statement before 'default'.",
  4305. token);
  4306. }
  4307. indentation(-option.indent);
  4308. advance('default');
  4309. g = true;
  4310. advance(':');
  4311. break;
  4312. case '}':
  4313. indent -= option.indent;
  4314. indentation();
  4315. advance('}', t);
  4316. if (this.cases.length === 1 || this.condition.id === 'true' ||
  4317. this.condition.id === 'false') {
  4318. warning("This 'switch' should be an 'if'.", this);
  4319. }
  4320. funct['(breakage)'] -= 1;
  4321. funct['(verb)'] = undefined;
  4322. return;
  4323. case '(end)':
  4324. error("Missing '{a}'.", nexttoken, '}');
  4325. return;
  4326. default:
  4327. if (g) {
  4328. switch (token.id) {
  4329. case ',':
  4330. error("Each value should have its own case label.");
  4331. return;
  4332. case ':':
  4333. statements();
  4334. break;
  4335. default:
  4336. error("Missing ':' on a case clause.", token);
  4337. }
  4338. } else {
  4339. error("Expected '{a}' and instead saw '{b}'.",
  4340. nexttoken, 'case', nexttoken.value);
  4341. }
  4342. }
  4343. }
  4344. }).labelled = true;
  4345. stmt('debugger', function () {
  4346. if (!option.debug) {
  4347. warning("All 'debugger' statements should be removed.");
  4348. }
  4349. });
  4350. stmt('do', function () {
  4351. funct['(breakage)'] += 1;
  4352. funct['(loopage)'] += 1;
  4353. block(true);
  4354. advance('while');
  4355. var t = nexttoken;
  4356. nonadjacent(token, t);
  4357. advance('(');
  4358. nospace();
  4359. parse(20);
  4360. if (nexttoken.id === '=') {
  4361. warning("Expected a conditional expression and instead saw an assignment.");
  4362. advance('=');
  4363. parse(20);
  4364. }
  4365. advance(')', t);
  4366. nospace(prevtoken, token);
  4367. funct['(breakage)'] -= 1;
  4368. funct['(loopage)'] -= 1;
  4369. }).labelled = true;
  4370. blockstmt('for', function () {
  4371. var s, t = nexttoken;
  4372. funct['(breakage)'] += 1;
  4373. funct['(loopage)'] += 1;
  4374. advance('(');
  4375. nonadjacent(this, t);
  4376. nospace();
  4377. if (peek(nexttoken.id === 'var' ? 1 : 0).id === 'in') {
  4378. if (nexttoken.id === 'var') {
  4379. advance('var');
  4380. varstatement(true);
  4381. } else {
  4382. switch (funct[nexttoken.value]) {
  4383. case 'unused':
  4384. funct[nexttoken.value] = 'var';
  4385. break;
  4386. case 'var':
  4387. break;
  4388. default:
  4389. warning("Bad for in variable '{a}'.",
  4390. nexttoken, nexttoken.value);
  4391. }
  4392. advance();
  4393. }
  4394. advance('in');
  4395. parse(20);
  4396. advance(')', t);
  4397. s = block(true);
  4398. if (!option.forin && (s.length > 1 || typeof s[0] !== 'object' ||
  4399. s[0].value !== 'if')) {
  4400. warning("The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.", this);
  4401. }
  4402. funct['(breakage)'] -= 1;
  4403. funct['(loopage)'] -= 1;
  4404. return this;
  4405. } else {
  4406. if (nexttoken.id !== ';') {
  4407. if (nexttoken.id === 'var') {
  4408. advance('var');
  4409. varstatement();
  4410. } else {
  4411. for (;;) {
  4412. parse(0, 'for');
  4413. if (nexttoken.id !== ',') {
  4414. break;
  4415. }
  4416. comma();
  4417. }
  4418. }
  4419. }
  4420. nolinebreak(token);
  4421. advance(';');
  4422. if (nexttoken.id !== ';') {
  4423. parse(20);
  4424. if (nexttoken.id === '=') {
  4425. warning("Expected a conditional expression and instead saw an assignment.");
  4426. advance('=');
  4427. parse(20);
  4428. }
  4429. }
  4430. nolinebreak(token);
  4431. advance(';');
  4432. if (nexttoken.id === ';') {
  4433. error("Expected '{a}' and instead saw '{b}'.",
  4434. nexttoken, ')', ';');
  4435. }
  4436. if (nexttoken.id !== ')') {
  4437. for (;;) {
  4438. parse(0, 'for');
  4439. if (nexttoken.id !== ',') {
  4440. break;
  4441. }
  4442. comma();
  4443. }
  4444. }
  4445. advance(')', t);
  4446. nospace(prevtoken, token);
  4447. block(true);
  4448. funct['(breakage)'] -= 1;
  4449. funct['(loopage)'] -= 1;
  4450. }
  4451. }).labelled = true;
  4452. stmt('break', function () {
  4453. var v = nexttoken.value;
  4454. if (funct['(breakage)'] === 0) {
  4455. warning("Unexpected '{a}'.", nexttoken, this.value);
  4456. }
  4457. nolinebreak(this);
  4458. if (nexttoken.id !== ';') {
  4459. if (token.line === nexttoken.line) {
  4460. if (funct[v] !== 'label') {
  4461. warning("'{a}' is not a statement label.", nexttoken, v);
  4462. } else if (scope[v] !== funct) {
  4463. warning("'{a}' is out of scope.", nexttoken, v);
  4464. }
  4465. advance();
  4466. }
  4467. }
  4468. reachable('break');
  4469. });
  4470. stmt('continue', function () {
  4471. var v = nexttoken.value;
  4472. if (funct['(breakage)'] === 0) {
  4473. warning("Unexpected '{a}'.", nexttoken, this.value);
  4474. }
  4475. nolinebreak(this);
  4476. if (nexttoken.id !== ';') {
  4477. if (token.line === nexttoken.line) {
  4478. if (funct[v] !== 'label') {
  4479. warning("'{a}' is not a statement label.", nexttoken, v);
  4480. } else if (scope[v] !== funct) {
  4481. warning("'{a}' is out of scope.", nexttoken, v);
  4482. }
  4483. advance();
  4484. }
  4485. }
  4486. reachable('continue');
  4487. });
  4488. stmt('return', function () {
  4489. nolinebreak(this);
  4490. if (nexttoken.id === '(regexp)') {
  4491. warning("Wrap the /regexp/ literal in parens to disambiguate the slash operator.");
  4492. }
  4493. if (nexttoken.id !== ';' && !nexttoken.reach) {
  4494. nonadjacent(token, nexttoken);
  4495. parse(20);
  4496. }
  4497. reachable('return');
  4498. });
  4499. stmt('throw', function () {
  4500. nolinebreak(this);
  4501. nonadjacent(token, nexttoken);
  4502. parse(20);
  4503. reachable('throw');
  4504. });
  4505. reserve('void');
  4506. // Superfluous reserved words
  4507. reserve('class');
  4508. reserve('const');
  4509. reserve('enum');
  4510. reserve('export');
  4511. reserve('extends');
  4512. reserve('import');
  4513. reserve('super');
  4514. reserve('let');
  4515. reserve('yield');
  4516. reserve('implements');
  4517. reserve('interface');
  4518. reserve('package');
  4519. reserve('private');
  4520. reserve('protected');
  4521. reserve('public');
  4522. reserve('static');
  4523. function jsonValue() {
  4524. function jsonObject() {
  4525. var o = {}, t = nexttoken;
  4526. advance('{');
  4527. if (nexttoken.id !== '}') {
  4528. for (;;) {
  4529. if (nexttoken.id === '(end)') {
  4530. error("Missing '}' to match '{' from line {a}.",
  4531. nexttoken, t.line);
  4532. } else if (nexttoken.id === '}') {
  4533. warning("Unexpected comma.", token);
  4534. break;
  4535. } else if (nexttoken.id === ',') {
  4536. error("Unexpected comma.", nexttoken);
  4537. } else if (nexttoken.id !== '(string)') {
  4538. warning("Expected a string and instead saw {a}.",
  4539. nexttoken, nexttoken.value);
  4540. }
  4541. if (o[nexttoken.value] === true) {
  4542. warning("Duplicate key '{a}'.",
  4543. nexttoken, nexttoken.value);
  4544. } else if (nexttoken.value === '__proto__') {
  4545. warning("Stupid key '{a}'.",
  4546. nexttoken, nexttoken.value);
  4547. } else {
  4548. o[nexttoken.value] = true;
  4549. }
  4550. advance();
  4551. advance(':');
  4552. jsonValue();
  4553. if (nexttoken.id !== ',') {
  4554. break;
  4555. }
  4556. advance(',');
  4557. }
  4558. }
  4559. advance('}');
  4560. }
  4561. function jsonArray() {
  4562. var t = nexttoken;
  4563. advance('[');
  4564. if (nexttoken.id !== ']') {
  4565. for (;;) {
  4566. if (nexttoken.id === '(end)') {
  4567. error("Missing ']' to match '[' from line {a}.",
  4568. nexttoken, t.line);
  4569. } else if (nexttoken.id === ']') {
  4570. warning("Unexpected comma.", token);
  4571. break;
  4572. } else if (nexttoken.id === ',') {
  4573. error("Unexpected comma.", nexttoken);
  4574. }
  4575. jsonValue();
  4576. if (nexttoken.id !== ',') {
  4577. break;
  4578. }
  4579. advance(',');
  4580. }
  4581. }
  4582. advance(']');
  4583. }
  4584. switch (nexttoken.id) {
  4585. case '{':
  4586. jsonObject();
  4587. break;
  4588. case '[':
  4589. jsonArray();
  4590. break;
  4591. case 'true':
  4592. case 'false':
  4593. case 'null':
  4594. case '(number)':
  4595. case '(string)':
  4596. advance();
  4597. break;
  4598. case '-':
  4599. advance('-');
  4600. if (token.character !== nexttoken.from) {
  4601. warning("Unexpected space after '-'.", token);
  4602. }
  4603. adjacent(token, nexttoken);
  4604. advance('(number)');
  4605. break;
  4606. default:
  4607. error("Expected a JSON value.", nexttoken);
  4608. }
  4609. }
  4610. // The actual JSLINT function itself.
  4611. var itself = function (s, o) {
  4612. var a, i;
  4613. JSLINT.errors = [];
  4614. predefined = Object.create(standard);
  4615. if (o) {
  4616. a = o.predef;
  4617. if (a instanceof Array) {
  4618. for (i = 0; i < a.length; i += 1) {
  4619. predefined[a[i]] = true;
  4620. }
  4621. }
  4622. if (o.adsafe) {
  4623. o.safe = true;
  4624. }
  4625. if (o.safe) {
  4626. o.browser = false;
  4627. o.css = false;
  4628. o.debug = false;
  4629. o.eqeqeq = true;
  4630. o.evil = false;
  4631. o.forin = false;
  4632. o.nomen = true;
  4633. o.on = false;
  4634. o.rhino = false;
  4635. o.safe = true;
  4636. o.sidebar = false;
  4637. o.strict = true;
  4638. o.sub = false;
  4639. o.undef = true;
  4640. o.widget = false;
  4641. predefined.Date = null;
  4642. predefined['eval'] = null;
  4643. predefined.Function = null;
  4644. predefined.Object = null;
  4645. predefined.ADSAFE = false;
  4646. predefined.lib = false;
  4647. }
  4648. option = o;
  4649. } else {
  4650. option = {};
  4651. }
  4652. option.indent = option.indent || 4;
  4653. adsafe_id = '';
  4654. adsafe_may = false;
  4655. adsafe_went = false;
  4656. approved = {};
  4657. if (option.approved) {
  4658. for (i = 0; i < option.approved.length; i += 1) {
  4659. approved[option.approved[i]] = option.approved[i];
  4660. }
  4661. } else {
  4662. approved.test = 'test';
  4663. }
  4664. tab = '';
  4665. for (i = 0; i < option.indent; i += 1) {
  4666. tab += ' ';
  4667. }
  4668. indent = 1;
  4669. global = Object.create(predefined);
  4670. scope = global;
  4671. funct = {
  4672. '(global)': true,
  4673. '(name)': '(global)',
  4674. '(scope)': scope,
  4675. '(breakage)': 0,
  4676. '(loopage)': 0
  4677. };
  4678. functions = [funct];
  4679. ids = {};
  4680. urls = [];
  4681. src = false;
  4682. xmode = false;
  4683. stack = null;
  4684. member = {};
  4685. membersOnly = null;
  4686. implied = {};
  4687. inblock = false;
  4688. lookahead = [];
  4689. jsonmode = false;
  4690. warnings = 0;
  4691. lex.init(s);
  4692. prereg = true;
  4693. prevtoken = token = nexttoken = syntax['(begin)'];
  4694. assume();
  4695. try {
  4696. advance();
  4697. if (nexttoken.value.charAt(0) === '<') {
  4698. html();
  4699. if (option.adsafe && !adsafe_went) {
  4700. warning("ADsafe violation: Missing ADSAFE.go.", this);
  4701. }
  4702. } else {
  4703. switch (nexttoken.id) {
  4704. case '{':
  4705. case '[':
  4706. option.laxbreak = true;
  4707. jsonmode = true;
  4708. jsonValue();
  4709. break;
  4710. case '@':
  4711. case '*':
  4712. case '#':
  4713. case '.':
  4714. case ':':
  4715. xmode = 'style';
  4716. advance();
  4717. if (token.id !== '@' || !nexttoken.identifier ||
  4718. nexttoken.value !== 'charset') {
  4719. error('A css file should begin with @charset "UTF-8";');
  4720. }
  4721. advance();
  4722. if (nexttoken.type !== '(string)' &&
  4723. nexttoken.value !== 'UTF-8') {
  4724. error('A css file should begin with @charset "UTF-8";');
  4725. }
  4726. advance();
  4727. advance(';');
  4728. styles();
  4729. break;
  4730. default:
  4731. if (option.adsafe && option.fragment) {
  4732. error("Expected '{a}' and instead saw '{b}'.",
  4733. nexttoken, '<div>', nexttoken.value);
  4734. }
  4735. statements('lib');
  4736. }
  4737. }
  4738. advance('(end)');
  4739. } catch (e) {
  4740. if (e) {
  4741. JSLINT.errors.push({
  4742. reason : e.message,
  4743. line : e.line || nexttoken.line,
  4744. character : e.character || nexttoken.from
  4745. }, null);
  4746. }
  4747. }
  4748. return JSLINT.errors.length === 0;
  4749. };
  4750. function is_array(o) {
  4751. return Object.prototype.toString.apply(o) === '[object Array]';
  4752. }
  4753. function to_array(o) {
  4754. var a = [], k;
  4755. for (k in o) {
  4756. if (is_own(o, k)) {
  4757. a.push(k);
  4758. }
  4759. }
  4760. return a;
  4761. }
  4762. // Data summary.
  4763. itself.data = function () {
  4764. var data = {functions: []}, fu, globals, implieds = [], f, i, j,
  4765. members = [], n, unused = [], v;
  4766. if (itself.errors.length) {
  4767. data.errors = itself.errors;
  4768. }
  4769. if (jsonmode) {
  4770. data.json = true;
  4771. }
  4772. for (n in implied) {
  4773. if (is_own(implied, n)) {
  4774. implieds.push({
  4775. name: n,
  4776. line: implied[n]
  4777. });
  4778. }
  4779. }
  4780. if (implieds.length > 0) {
  4781. data.implieds = implieds;
  4782. }
  4783. if (urls.length > 0) {
  4784. data.urls = urls;
  4785. }
  4786. globals = to_array(scope);
  4787. if (globals.length > 0) {
  4788. data.globals = globals;
  4789. }
  4790. for (i = 1; i < functions.length; i += 1) {
  4791. f = functions[i];
  4792. fu = {};
  4793. for (j = 0; j < functionicity.length; j += 1) {
  4794. fu[functionicity[j]] = [];
  4795. }
  4796. for (n in f) {
  4797. if (is_own(f, n) && n.charAt(0) !== '(') {
  4798. v = f[n];
  4799. if (is_array(fu[v])) {
  4800. fu[v].push(n);
  4801. if (v === 'unused') {
  4802. unused.push({
  4803. name: n,
  4804. line: f['(line)'],
  4805. 'function': f['(name)']
  4806. });
  4807. }
  4808. }
  4809. }
  4810. }
  4811. for (j = 0; j < functionicity.length; j += 1) {
  4812. if (fu[functionicity[j]].length === 0) {
  4813. delete fu[functionicity[j]];
  4814. }
  4815. }
  4816. fu.name = f['(name)'];
  4817. fu.param = f['(params)'];
  4818. fu.line = f['(line)'];
  4819. fu.last = f['(last)'];
  4820. data.functions.push(fu);
  4821. }
  4822. if (unused.length > 0) {
  4823. data.unused = unused;
  4824. }
  4825. members = [];
  4826. for (n in member) {
  4827. if (typeof member[n] === 'number') {
  4828. data.member = member;
  4829. break;
  4830. }
  4831. }
  4832. return data;
  4833. };
  4834. itself.report = function (option) {
  4835. var data = itself.data();
  4836. var a = [], c, e, err, f, i, k, l, m = '', n, o = [], s;
  4837. function detail(h, s) {
  4838. if (s) {
  4839. o.push('<div><i>' + h + '</i> ' +
  4840. s.sort().join(', ') + '</div>');
  4841. }
  4842. }
  4843. if (data.errors || data.implieds || data.unused) {
  4844. err = true;
  4845. o.push('<div id=errors><i>Error:</i>');
  4846. if (data.errors) {
  4847. for (i = 0; i < data.errors.length; i += 1) {
  4848. c = data.errors[i];
  4849. if (c) {
  4850. e = c.evidence || '';
  4851. o.push('<p>Problem' + (isFinite(c.line) ? ' at line ' +
  4852. c.line + ' character ' + c.character : '') +
  4853. ': ' + c.reason.entityify() +
  4854. '</p><p class=evidence>' +
  4855. (e && (e.length > 80 ? e.slice(0, 77) + '...' :
  4856. e).entityify()) + '</p>');
  4857. }
  4858. }
  4859. }
  4860. if (data.implieds) {
  4861. s = [];
  4862. for (i = 0; i < data.implieds.length; i += 1) {
  4863. s[i] = '<code>' + data.implieds[i].name + '</code>&nbsp;<i>' +
  4864. data.implieds[i].line + '</i>';
  4865. }
  4866. o.push('<p><i>Implied global:</i> ' + s.join(', ') + '</p>');
  4867. }
  4868. if (data.unused) {
  4869. s = [];
  4870. for (i = 0; i < data.unused.length; i += 1) {
  4871. s[i] = '<code>' + data.unused[i].name + '</code>&nbsp;<i>' +
  4872. data.unused[i].line + '</i> <code>' +
  4873. data.unused[i]['function'] + '</code>';
  4874. }
  4875. o.push('<p><i>Unused variable:</i> ' + s.join(', ') + '</p>');
  4876. }
  4877. if (data.json) {
  4878. o.push('<p>JSON: bad.</p>');
  4879. }
  4880. o.push('</div>');
  4881. }
  4882. if (!option) {
  4883. o.push('<br><div id=functions>');
  4884. if (data.urls) {
  4885. detail("URLs<br>", data.urls, '<br>');
  4886. }
  4887. if (data.json && !err) {
  4888. o.push('<p>JSON: good.</p>');
  4889. } else if (data.globals) {
  4890. o.push('<div><i>Global</i> ' +
  4891. data.globals.sort().join(', ') + '</div>');
  4892. } else {
  4893. o.push('<div><i>No new global variables introduced.</i></div>');
  4894. }
  4895. for (i = 0; i < data.functions.length; i += 1) {
  4896. f = data.functions[i];
  4897. o.push('<br><div class=function><i>' + f.line + '-' +
  4898. f.last + '</i> ' + (f.name || '') + '(' +
  4899. (f.param ? f.param.join(', ') : '') + ')</div>');
  4900. detail('<big><b>Unused</b></big>', f.unused);
  4901. detail('Closure', f.closure);
  4902. detail('Variable', f['var']);
  4903. detail('Exception', f.exception);
  4904. detail('Outer', f.outer);
  4905. detail('Global', f.global);
  4906. detail('Label', f.label);
  4907. }
  4908. if (data.member) {
  4909. a = to_array(data.member);
  4910. if (a.length) {
  4911. a = a.sort();
  4912. m = '<br><pre id=members>/*members ';
  4913. l = 10;
  4914. for (i = 0; i < a.length; i += 1) {
  4915. k = a[i];
  4916. n = k.name();
  4917. if (l + n.length > 72) {
  4918. o.push(m + '<br>');
  4919. m = ' ';
  4920. l = 1;
  4921. }
  4922. l += n.length + 2;
  4923. if (data.member[k] === 1) {
  4924. n = '<i>' + n + '</i>';
  4925. }
  4926. if (i < a.length - 1) {
  4927. n += ', ';
  4928. }
  4929. m += n;
  4930. }
  4931. o.push(m + '<br>*/</pre>');
  4932. }
  4933. o.push('</div>');
  4934. }
  4935. }
  4936. return o.join('');
  4937. };
  4938. itself.edition = '2009-08-01';
  4939. return itself;
  4940. }());