jslint_rhino.js 196 KB

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