Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/ebaqo (28-Jul @ 10:24)

Syntax Highlighted Code

  1. // jslint.js
  2. // 2008-07-25
  3. /*
  4. Copyright (c) 2002 Douglas Crockford  (www.JSLint.com)
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. this software and associated documentation files (the "Software"), to deal in
  8. the Software without restriction, including without limitation the rights to
  9. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  10. of the Software, and to permit persons to whom the Software is furnished to do
  11. so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15.  
  16. The Software shall be used for Good, not Evil.
  17.  
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. SOFTWARE.
  25. */
  26.  
  27. /*
  28.     JSLINT is a global function. It takes two parameters.
  29.  
  30.         var myResult = JSLINT(source, option);
  31.  
  32.     The first parameter is either a string or an array of strings. If it is a
  33.     string, it will be split on '\n' or '\r'. If it is an array of strings, it
  34.     is assumed that each string represents one line. The source can be a
  35.     JavaScript text, or HTML text, or a Konfabulator text.
  36.  
  37.     The second parameter is an optional object of options which control the
  38.     operation of JSLINT. Most of the options are booleans: They are all are
  39.     optional and have a default value of false.
  40.  
  41.     If it checks out, JSLINT returns true. Otherwise, it returns false.
  42.  
  43.     If false, you can inspect JSLINT.errors to find out the problems.
  44.     JSLINT.errors is an array of objects containing these members:
  45.  
  46.     {
  47.         line      : The line (relative to 0) at which the lint was found
  48.         character : The character (relative to 0) at which the lint was found
  49.         reason    : The problem
  50.         evidence  : The text line in which the problem occurred
  51.         raw       : The raw message before the details were inserted
  52.         a         : The first detail
  53.         b         : The second detail
  54.         c         : The third detail
  55.         d         : The fourth detail
  56.     }
  57.  
  58.     If a fatal error was found, a null will be the last element of the
  59.     JSLINT.errors array.
  60.  
  61.     You can request a Function Report, which shows all of the functions
  62.     and the parameters and vars that they use. This can be used to find
  63.     implied global variables and other problems. The report is in HTML and
  64.     can be inserted in an HTML <body>.
  65.  
  66.         var myReport = JSLINT.report(limited);
  67.  
  68.     If limited is true, then the report will be limited to only errors.
  69. */
  70.  
  71. /*jslint evil: true, nomen: false */
  72.  
  73. /*members "\b", "\t", "\n", "\f", "\r", "\"", "(begin)", "(breakage)",
  74.     "(context)", "(end)", "(global)", "(identifier)", "(line)", "(loopage)",
  75.     "(name)", "(params)", "(scope)", "(verb)", ")", "++", "--", "\/",
  76.     ADSAFE, Array, Boolean, COM, Canvas, CustomAnimation, Date, Debug, E,
  77.     Error, EvalError, FadeAnimation, FormField, Frame, Function, HotKey,
  78.     Image, JSON, LN10, LN2, LOG10E, LOG2E, MAX_VALUE, MIN_VALUE, Math,
  79.     MenuItem, MoveAnimation, NEGATIVE_INFINITY, Number, Object, Option, PI,
  80.     POSITIVE_INFINITY, Point, RangeError, ReferenceError, RegExp,
  81.     RotateAnimation, SQRT1_2, SQRT2, ScrollBar, String, SyntaxError, System,
  82.     Text, TextArea, Timer, TypeError, URIError, URL, Window, XMLDOM,
  83.     XMLHttpRequest, "\\", "]", a, abbr, "about-box", "about-image",
  84.     "about-text", "about-version", acronym, action, address, adsafe, alert,
  85.     alignment, anchorstyle, animator, appleScript, applet, apply, approved,
  86.     area, arguments, author, autohide, b, background, base, bdo, beep,
  87.     create, bgcolor, bgcolour, bgopacity, big, bitwise, block, blockquote,
  88.     blur, body, br, browser, button, bytesToUIString, c, call, callee,
  89.     caller, canvas, cap, caption, cases, center, charAt, charCodeAt,
  90.     character, charset, checked, chooseColor, chooseFile, chooseFolder,
  91.     cite, clearInterval, clearTimeout, cliprect, close, closeWidget, closed,
  92.     code, col, colgroup, color, colorize, colour, columns, comment, company,
  93.     condition, confirm, console, constructor, content, contextmenuitems,
  94.     convertPathToHFS, convertPathToPlatform, copyright, d, data, dd, debug,
  95.     decodeURI, decodeURIComponent, defaultStatus, defaulttracking,
  96.     defaultvalue, defineClass, del, description, deserialize, dfn, dir,
  97.     directory, div, dl, doAttribute, doBegin, doIt, doTagName, document, dt,
  98.     dynsrc, editable, em, embed, empty, enabled, encodeURI,
  99.     encodeURIComponent, entityify, eqeqeq, errors, escape, eval, event,
  100.     evidence, evil, exec, exps, extension, fieldset, file, filesystem,
  101.     fillmode, first, floor, focus, focusWidget, font, fontstyle, forin,
  102.     form, fragment, frame, frames, frameset, from, fromCharCode, fud,
  103.     function, g, gc, getComputedStyle, group, h1, h2, h3, h4, h5,
  104.     h6, halign, handlelinks, hasOwnProperty, head, height, help, hidden,
  105.     history, hlinesize, hoffset, hotkey, hr, href, hregistrationpoint,
  106.     hscrollbar, hsladjustment, hsltinting, html, i, iTunes, icon, id,
  107.     identifier, iframe, image, img, include, indent, indexOf, init, input,
  108.     ins, interval, isAlpha, isApplicationRunning, isDigit, isFinite, isNaN,
  109.     join, kbd, key, kind, konfabulatorVersion, label, labelled, laxbreak,
  110.     lbp, led, left, legend, length, level, li, line, lines, link, load,
  111.     loadClass, loadingsrc, location, locked, log, lowsrc, m, map, match,
  112.     max, maxlength, menu, menuitem, message, meta, min, minimumversion,
  113.     minlength, missingsrc, modifier, moveBy, moveTo, name, navigator, new,
  114.     noframes, nomen, noscript, notsaved, nud, object, ol, on, onblur,
  115.     onclick, oncontextmenu, ondragdrop, ondragenter, ondragexit, onerror,
  116.     onfirstdisplay, onfocus, ongainfocus, onimageloaded, onkeydown,
  117.     onkeypress, onkeyup, onload, onlosefocus, onmousedown, onmousedrag,
  118.     onmouseenter, onmouseexit, onmousemove, onmouseup, onmousewheel,
  119.     onmulticlick, onresize, onselect, ontextinput, ontimerfired, onunload,
  120.     onvaluechanged, opacity, open, openURL, opener, opera, optgroup, option,
  121.     optionvalue, order, orientation, p, pagesize, param, parent, parseFloat,
  122.     parseInt, passfail, play, plusplus, pop, popupMenu, pre, predef,
  123.     preference, preferenceGroups, preferencegroup, preferences, print,
  124.     prompt, prototype, push, q, quit, random, raw, reach, readFile, readUrl,
  125.     reason, regexp, reloadWidget, remoteasync, replace, report,
  126.     requiredplatform, reserved, resizeBy, resizeTo, resolvePath,
  127.     resumeUpdates, rhino, right, root, rotation, runCommand, runCommandInBg,
  128.     safe, samp, saveAs, savePreferences, screen, script, scroll, scrollBy,
  129.     scrollTo, scrollbar, scrolling, scrollx, scrolly, seal, search, secure,
  130.     select, self, serialize, setInterval, setTimeout, setting, settings,
  131.     shadow, shift, showWidgetPreferences, sidebar, size, skip, sleep, slice,
  132.     small, sort, span, spawn, speak, special, spellcheck, split, src,
  133.     srcheight, srcwidth, status, strong, style, sub, substr, subviews, sup,
  134.     superview, supplant, suppressUpdates, sync, system, table, tag, tbody,
  135.     td, tellWidget, test, text, textarea, tfoot, th, thead, thumbcolor,
  136.     ticking, ticklabel, ticks, tileorigin, timer, title, toLowerCase,
  137.     toString, toUpperCase, toint32, token, tooltip, top, tr, tracking,
  138.     trigger, truncation, tt, type, u, ul, undef, unescape, union, unwatch,
  139.     updateNow, url, usefileicon, valign, value, valueOf, var, version,
  140.     visible, vlinesize, voffset, vregistrationpoint, vscrollbar, watch,
  141.     white, widget, width, window, wrap, yahooCheckLogin, yahooLogin,
  142.     yahooLogout, zorder
  143. */
  144.  
  145. /*global JSLINT*/
  146.  
  147. // We build the application inside a function so that we produce only a single
  148. // global variable. The function will be invoked, its return value is the JSLINT
  149. // application itself.
  150.  
  151. "use strict";
  152.  
  153. JSLINT = function () {
  154.     var adsafe_id,      // The widget's ADsafe id.
  155.         adsafe_may,     // The widget may load approved scripts.
  156.         adsafe_went,    // ADSAFE.go has been called.
  157.         anonname,       // The guessed name for anonymous functions.
  158.         approved,       // ADsafe approved urls.
  159.  
  160. // These are members that should not be permitted in third party ads.
  161.  
  162.         banned = {              // the member names that ADsafe prohibits.
  163.             apply           : true,
  164.             'arguments'     : true,
  165.             call            : true,
  166.             callee          : true,
  167.             caller          : true,
  168.             constructor     : true,
  169.             'eval'          : true,
  170.             prototype       : true,
  171.             unwatch         : true,
  172.             valueOf         : true,
  173.             watch           : true
  174.         },
  175.  
  176.  
  177. // These are the JSLint boolean options.
  178.  
  179.         boolOptions = {
  180.             adsafe     : true, // if ADsafe should be enforced
  181.             bitwise    : true, // if bitwise operators should not be allowed
  182.             browser    : true, // if the standard browser globals should be predefined
  183.             cap        : true, // if upper case HTML should be allowed
  184.             debug      : true, // if debugger statements should be allowed
  185.             eqeqeq     : true, // if === should be required
  186.             evil       : true, // if eval should be allowed
  187.             forin      : true, // if for in statements must filter
  188.             fragment   : true, // if HTML fragments should be allowed
  189.             laxbreak   : true, // if line breaks should not be checked
  190.             nomen      : true, // if names should be checked
  191.             on         : true, // if HTML event handlers should be allowed
  192.             passfail   : true, // if the scan should stop on first error
  193.             plusplus   : true, // if increment/decrement should not be allowed
  194.             regexp     : true, // if the . should not be allowed in regexp literals
  195.             rhino      : true, // if the Rhino environment globals should be predefined
  196.             undef      : true, // if variables should be declared before used
  197.             safe       : true, // if use of some browser features should be restricted
  198.             sidebar    : true, // if the System object should be predefined
  199.             sub        : true, // if all forms of subscript notation are tolerated
  200.             white      : true, // if strict whitespace rules apply
  201.             widget     : true  // if the Yahoo Widgets globals should be predefined
  202.         },
  203.  
  204. // browser contains a set of global names which are commonly provided by a
  205. // web browser environment.
  206.  
  207.         browser = {
  208.             alert           : true,
  209.             blur            : true,
  210.             clearInterval   : true,
  211.             clearTimeout    : true,
  212.             close           : true,
  213.             closed          : true,
  214.             confirm         : true,
  215.             console         : true,
  216.             Debug           : true,
  217.             defaultStatus   : true,
  218.             document        : true,
  219.             event           : true,
  220.             focus           : true,
  221.             frames          : true,
  222.             getComputedStyle: true,
  223.             history         : true,
  224.             Image           : true,
  225.             length          : true,
  226.             location        : true,
  227.             moveBy          : true,
  228.             moveTo          : true,
  229.             name            : true,
  230.             navigator       : true,
  231.             onblur          : true,
  232.             onerror         : true,
  233.             onfocus         : true,
  234.             onload          : true,
  235.             onresize        : true,
  236.             onunload        : true,
  237.             open            : true,
  238.             opener          : true,
  239.             opera           : true,
  240.             Option          : true,
  241.             parent          : true,
  242.             print           : true,
  243.             prompt          : true,
  244.             resizeBy        : true,
  245.             resizeTo        : true,
  246.             screen          : true,
  247.             scroll          : true,
  248.             scrollBy        : true,
  249.             scrollTo        : true,
  250.             self            : true,
  251.             setInterval     : true,
  252.             setTimeout      : true,
  253.             status          : true,
  254.             top             : true,
  255.             window          : true,
  256.             XMLHttpRequest  : true
  257.         },
  258.  
  259.         escapes = {
  260.             '\b': '\\b',
  261.             '\t': '\\t',
  262.             '\n': '\\n',
  263.             '\f': '\\f',
  264.             '\r': '\\r',
  265.             '"' : '\\"',
  266.             '/' : '\\/',
  267.             '\\': '\\\\'
  268.         },
  269.  
  270.         funct,          // The current function
  271.         functions,      // All of the functions
  272.  
  273.         href = {
  274.             background  : true,
  275.             content     : true,
  276.             data        : true,
  277.             dynsrc      : true,
  278.             href        : true,
  279.             lowsrc      : true,
  280.             src         : true
  281.         },
  282.  
  283.         global,         // The global scope
  284.         ids,            // HTML ids
  285.         implied,        // Implied globals
  286.         inblock,
  287.         indent,
  288.         jsonmode,
  289.         lines,
  290.         lookahead,
  291.         member,
  292.         membersOnly,
  293.         nexttoken,
  294.         noreach,
  295.         option,
  296.         predefined,     // Global variables defined by option
  297.         prereg,
  298.         prevtoken,
  299.  
  300.         rhino = {
  301.             defineClass : true,
  302.             deserialize : true,
  303.             gc          : true,
  304.             help        : true,
  305.             load        : true,
  306.             loadClass   : true,
  307.             print       : true,
  308.             quit        : true,
  309.             readFile    : true,
  310.             readUrl     : true,
  311.             runCommand  : true,
  312.             seal        : true,
  313.             serialize   : true,
  314.             spawn       : true,
  315.             sync        : true,
  316.             toint32     : true,
  317.             version     : true
  318.         },
  319.  
  320.         scope,      // The current scope
  321.  
  322.         sidebar = {
  323.             System      : true
  324.         },
  325.  
  326.         src,
  327.         stack,
  328.  
  329. // standard contains the global names that are provided by the
  330. // ECMAScript standard.
  331.  
  332.         standard = {
  333.             Array               : true,
  334.             Boolean             : true,
  335.             Date                : true,
  336.             decodeURI           : true,
  337.             decodeURIComponent  : true,
  338.             encodeURI           : true,
  339.             encodeURIComponent  : true,
  340.             Error               : true,
  341.             'eval'              : true,
  342.             EvalError           : true,
  343.             Function            : true,
  344.             isFinite            : true,
  345.             isNaN               : true,
  346.             JSON                : true,
  347.             Math                : true,
  348.             Number              : true,
  349.             Object              : true,
  350.             parseInt            : true,
  351.             parseFloat          : true,
  352.             RangeError          : true,
  353.             ReferenceError      : true,
  354.             RegExp              : true,
  355.             String              : true,
  356.             SyntaxError         : true,
  357.             TypeError           : true,
  358.             URIError            : true
  359.         },
  360.  
  361.         standard_member = {
  362.             E                   : true,
  363.             LN2                 : true,
  364.             LN10                : true,
  365.             LOG2E               : true,
  366.             LOG10E              : true,
  367.             PI                  : true,
  368.             SQRT1_2             : true,
  369.             SQRT2               : true,
  370.             MAX_VALUE           : true,
  371.             MIN_VALUE           : true,
  372.             NEGATIVE_INFINITY   : true,
  373.             POSITIVE_INFINITY   : true
  374.         },
  375.  
  376.         syntax = {},
  377.         tab,
  378.         token,
  379.         urls,
  380.         warnings,
  381.  
  382. // widget contains the global names which are provided to a Yahoo
  383. // (fna Konfabulator) widget.
  384.  
  385.         widget = {
  386.             alert                   : true,
  387.             appleScript             : true,
  388.             animator                : true,
  389.             appleScript             : true,
  390.             beep                    : true,
  391.             bytesToUIString         : true,
  392.             Canvas                  : true,
  393.             chooseColor             : true,
  394.             chooseFile              : true,
  395.             chooseFolder            : true,
  396.             closeWidget             : true,
  397.             COM                     : true,
  398.             convertPathToHFS        : true,
  399.             convertPathToPlatform   : true,
  400.             CustomAnimation         : true,
  401.             escape                  : true,
  402.             FadeAnimation           : true,
  403.             filesystem              : true,
  404.             focusWidget             : true,
  405.             form                    : true,
  406.             FormField               : true,
  407.             Frame                   : true,
  408.             HotKey                  : true,
  409.             Image                   : true,
  410.             include                 : true,
  411.             isApplicationRunning    : true,
  412.             iTunes                  : true,
  413.             konfabulatorVersion     : true,
  414.             log                     : true,
  415.             MenuItem                : true,
  416.             MoveAnimation           : true,
  417.             openURL                 : true,
  418.             play                    : true,
  419.             Point                   : true,
  420.             popupMenu               : true,
  421.             preferenceGroups        : true,
  422.             preferences             : true,
  423.             print                   : true,
  424.             prompt                  : true,
  425.             random                  : true,
  426.             reloadWidget            : true,
  427.             resolvePath             : true,
  428.             resumeUpdates           : true,
  429.             RotateAnimation         : true,
  430.             runCommand              : true,
  431.             runCommandInBg          : true,
  432.             saveAs                  : true,
  433.             savePreferences         : true,
  434.             screen                  : true,
  435.             ScrollBar               : true,
  436.             showWidgetPreferences   : true,
  437.             sleep                   : true,
  438.             speak                   : true,
  439.             suppressUpdates         : true,
  440.             system                  : true,
  441.             tellWidget              : true,
  442.             Text                    : true,
  443.             TextArea                : true,
  444.             Timer                   : true,
  445.             unescape                : true,
  446.             updateNow               : true,
  447.             URL                     : true,
  448.             widget                  : true,
  449.             Window                  : true,
  450.             XMLDOM                  : true,
  451.             XMLHttpRequest          : true,
  452.             yahooCheckLogin         : true,
  453.             yahooLogin              : true,
  454.             yahooLogout             : true
  455.         },
  456.  
  457. //  xmode is used to adapt to the exceptions in XML parsing.
  458. //  It can have these states:
  459. //      false   .js script file
  460. //      "       A " attribute
  461. //      '       A ' attribute
  462. //      content The content of a script tag
  463. //      CDATA   A CDATA block
  464.  
  465.         xmode,
  466.  
  467. //  xtype identifies the type of document being analyzed.
  468. //  It can have these states:
  469. //      false   .js script file
  470. //      html    .html file
  471. //      widget  .kon Konfabulator file
  472.  
  473.         xtype,
  474.  
  475. // unsafe comment or string
  476.         ax = /@cc|<\/?script|\]\]|<!|&lt/i,
  477. // unsafe character
  478.         cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,
  479. // token
  480.         tx = /^\s*([(){}\[.,:;'"~]|\](\]>)?|\?>?|==?=?|\/(\*(global|extern|jslint|member|members)?|=|\/)?|\*[\/=]?|\+[+=]?|-[\-=]?|%[=>]?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=%\?]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/,
  481. // star slash
  482.        lx = /\*\/|\/\*/,
  483. // identifier
  484.        ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/,
  485. // javascript url
  486.        jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i,
  487. // url badness
  488.        ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto/i;
  489.  
  490.    function F() {}
  491.  
  492.    if (typeof Object.create !== 'function') {
  493.        Object.create = function (o) {
  494.            F.prototype = o;
  495.            return new F();
  496.        };
  497.    }
  498.    Object.prototype.union = function (o) {
  499.        var n;
  500.        for (n in o) {
  501.            if (o.hasOwnProperty(n)) {
  502.                this[n] = o[n];
  503.            }
  504.        }
  505.    };
  506.  
  507.    String.prototype.entityify = function () {
  508.        return this.
  509.            replace(/&/g, '&amp;').
  510.            replace(/</g, '&lt;').
  511.            replace(/>/g, '&gt;');
  512.    };
  513.  
  514.    String.prototype.isAlpha = function () {
  515.        return (this >= 'a' && this <= 'z\uffff') ||
  516.            (this >= 'A' && this <= 'Z\uffff');
  517.    };
  518.  
  519.  
  520.    String.prototype.isDigit = function () {
  521.        return (this >= '0' && this <= '9');
  522.    };
  523.  
  524.  
  525.    String.prototype.supplant = function (o) {
  526.        return this.replace(/\{([^{}]*)\}/g, function (a, b) {
  527.            var r = o[b];
  528.            return typeof r === 'string' || typeof r === 'number' ? r : a;
  529.        });
  530.    };
  531.  
  532.    String.prototype.name = function () {
  533.  
  534. // If the string looks like an identifier, then we can return it as is.
  535. // If the string contains no control characters, no quote characters, and no
  536. // backslash characters, then we can simply slap some quotes around it.
  537. // Otherwise we must also replace the offending characters with safe
  538. // sequences.
  539.  
  540.  
  541.        if (ix.test(this)) {
  542.            return this;
  543.        }
  544.        if (/[&<"\/\\\x00-\x1f]/.test(this)) {
  545.            return '"' + this.replace(/[&<"\/\\\x00-\x1f]/g, function (a) {
  546.                 var c = escapes[a];
  547.                 if (c) {
  548.                     return c;
  549.                 }
  550.                 c = a.charCodeAt();
  551.                 return '\\u00' +
  552.                     Math.floor(c / 16).toString(16) +
  553.                     (c % 16).toString(16);
  554.             }) + '"';
  555.         }
  556.         return '"' + this + '"';
  557.     };
  558.  
  559.  
  560.     function assume() {
  561.         if (!option.safe) {
  562.             if (option.rhino) {
  563.                 predefined.union(rhino);
  564.             }
  565.             if (option.browser || option.sidebar) {
  566.                 predefined.union(browser);
  567.             }
  568.             if (option.sidebar) {
  569.                 predefined.union(sidebar);
  570.             }
  571.             if (option.widget) {
  572.                 predefined.union(widget);
  573.             }
  574.         }
  575.     }
  576.  
  577.  
  578. // Produce an error warning.
  579.  
  580.     function quit(m, l, ch) {
  581.         throw {
  582.             name: 'JSLintError',
  583.             line: l,
  584.             character: ch,
  585.             message: m + " (" + Math.floor((l / lines.length) * 100) +
  586.                     "% scanned)."
  587.         };
  588.     }
  589.  
  590.     function warning(m, t, a, b, c, d) {
  591.         var ch, l, w;
  592.         t = t || nexttoken;
  593.         if (t.id === '(end)') {
  594.             t = token;
  595.         }
  596.         l = t.line || 0;
  597.         ch = t.from || 0;
  598.         w = {
  599.             id: '(error)',
  600.             raw: m,
  601.             evidence: lines[l] || '',
  602.             line: l,
  603.             character: ch,
  604.             a: a,
  605.             b: b,
  606.             c: c,
  607.             d: d
  608.         };
  609.         w.reason = m.supplant(w);
  610.         JSLINT.errors.push(w);
  611.         if (option.passfail) {
  612.             quit('Stopping. ', l, ch);
  613.         }
  614.         warnings += 1;
  615.         if (warnings === 50) {
  616.             quit("Too many errors.", l, ch);
  617.         }
  618.         return w;
  619.     }
  620.  
  621.     function warningAt(m, l, ch, a, b, c, d) {
  622.         return warning(m, {
  623.             line: l,
  624.             from: ch
  625.         }, a, b, c, d);
  626.     }
  627.  
  628.     function error(m, t, a, b, c, d) {
  629.         var w = warning(m, t, a, b, c, d);
  630.         quit("Stopping, unable to continue.", w.line, w.character);
  631.     }
  632.  
  633.     function errorAt(m, l, ch, a, b, c, d) {
  634.         return error(m, {
  635.             line: l,
  636.             from: ch
  637.         }, a, b, c, d);
  638.     }
  639.  
  640.  
  641.  
  642. // lexical analysis
  643.  
  644.     var lex = function () {
  645.         var character, from, line, s;
  646.  
  647. // Private lex methods
  648.  
  649.         function nextLine() {
  650.             var at;
  651.             line += 1;
  652.             if (line >= lines.length) {
  653.                 return false;
  654.             }
  655.             character = 0;
  656.             s = lines[line].replace(/\t/g, tab);
  657.             at = s.search(cx);
  658.             if (at >= 0) {
  659.                 warningAt("Unsafe character.", line, at);
  660.             }
  661.             return true;
  662.         }
  663.  
  664. // Produce a token object.  The token inherits from a syntax symbol.
  665.  
  666.         function it(type, value) {
  667.             var i, t;
  668.             if (type === '(punctuator)' ||
  669.                     (type === '(identifier)' && syntax.hasOwnProperty(value))) {
  670.                 t = syntax[value];
  671.  
  672. // Mozilla bug workaround.
  673.  
  674.                 if (!t.id) {
  675.                     t = syntax[type];
  676.                 }
  677.             } else {
  678.                 t = syntax[type];
  679.             }
  680.             t = Object.create(t);
  681.             if (type === '(string)') {
  682.                 if (jx.test(value)) {
  683.                     warningAt("Script URL.", line, from);
  684.                 }
  685.             } else if (type === '(identifier)') {
  686.                 if (option.nomen && (value.charAt(0) === '_' ||
  687.                                      value.charAt(value.length - 1) === '_')) {
  688.                     warningAt("Unexpected '_' in '{a}'.", line, from, value);
  689.                 }
  690.             }
  691.             t.value = value;
  692.             t.line = line;
  693.             t.character = character;
  694.             t.from = from;
  695.             i = t.id;
  696.             if (i !== '(endline)') {
  697.                 prereg = i &&
  698.                         (('(,=:[!&|?{};'.indexOf(i.charAt(i.length - 1)) >= 0) ||
  699.                         i === 'return');
  700.             }
  701.             return t;
  702.         }
  703.  
  704. // Public lex methods
  705.  
  706.         return {
  707.             init: function (source) {
  708.                 if (typeof source === 'string') {
  709.                     lines = source.
  710.                         replace(/\r\n/g, '\n').
  711.                         replace(/\r/g, '\n').
  712.                         split('\n');
  713.                 } else {
  714.                     lines = source;
  715.                 }
  716.                 line = -1;
  717.                 nextLine();
  718.                 from = 0;
  719.             },
  720.  
  721. // token -- this is called by advance to get the next token.
  722.  
  723.             token: function () {
  724.                 var b, c, captures, d, depth, high, i, l, low, q, t;
  725.  
  726.                 function match(x) {
  727.                     var r = x.exec(s), r1;
  728.                     if (r) {
  729.                         l = r[0].length;
  730.                         r1 = r[1];
  731.                         c = r1.charAt(0);
  732.                         s = s.substr(l);
  733.                         character += l;
  734.                         from = character - r1.length;
  735.                         return r1;
  736.                     }
  737.                 }
  738.  
  739.                 function string(x) {
  740.                     var c, j, r = '';
  741.  
  742.                     if (jsonmode && x !== '"') {
  743.                         warningAt("Strings must use doublequote.",
  744.                                 line, character);
  745.                     }
  746.  
  747.                     if (xmode === x || xmode === 'string') {
  748.                         if (xmode && xmode !== 'CDATA' && ax.test(x)) {
  749.                             warning("ADsafe string violation.", line, character);
  750.                         }
  751.                         return it('(punctuator)', x);
  752.                     }
  753.  
  754.                     function esc(n) {
  755.                         var i = parseInt(s.substr(j + 1, n), 16);
  756.                         j += n;
  757.                         if (i >= 32 && i <= 127 &&
  758.                                 i !== 34 && i !== 92 && i !== 39) {
  759.                             warningAt("Unnecessary escapement.", line, character);
  760.                         }
  761.                         character += n;
  762.                         c = String.fromCharCode(i);
  763.                     }
  764.                     j = 0;
  765.                     for (;;) {
  766.                         while (j >= s.length) {
  767.                             j = 0;
  768.                             if (xmode !== 'xml' || !nextLine()) {
  769.                                 errorAt("Unclosed string.", line, from);
  770.                             }
  771.                         }
  772.                         c = s.charAt(j);
  773.                         if (c === x) {
  774.                             character += 1;
  775.                             s = s.substr(j + 1);
  776.                             return it('(string)', r, x);
  777.                         }
  778.                         if (c < ' ') {
  779.                             if (c === '\n' || c === '\r') {
  780.                                 break;
  781.                             }
  782.                             warningAt("Control character in string: {a}.",
  783.                                     line, character + j, s.slice(0, j));
  784.                         } else if (c === '<') {
  785.                             if (option.safe && xmode === 'xml') {
  786.                                 warningAt("ADsafe string violation.",
  787.                                         line, character + j);
  788.                             } else if (s.charAt(j + 1) === '/' && ((xmode && xmode !== 'CDATA') || option.safe)) {
  789.                                 warningAt("Expected '<\\/' and instead saw '</'.", line, character);
  790.                             } else if (s.charAt(j + 1) === '!' && ((xmode && xmode !== 'CDATA') || option.safe)) {
  791.                                 warningAt("Unexpected '<!' in a string.", line, character);
  792.                             }
  793.                         } else if (c === '\\') {
  794.                             if (option.safe && xmode === 'xml') {
  795.                                 warningAt("ADsafe string violation.",
  796.                                         line, character + j);
  797.                             }
  798.                             j += 1;
  799.                             character += 1;
  800.                             c = s.charAt(j);
  801.                             switch (c) {
  802.                             case '\\':
  803.                             case '\'':
  804.                             case '"':
  805.                             case '/':
  806.                                 break;
  807.                             case 'b':
  808.                                 c = '\b';
  809.                                 break;
  810.                             case 'f':
  811.                                 c = '\f';
  812.                                 break;