diff --git a/.gitignore b/.gitignore index 94c9e2aa..7cb20102 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ tags Gemfile.lock pkg/* .sass-cache/* -src/html/.sass-cache/* \ No newline at end of file +src/html/.sass-cache/* +node_modules/ \ No newline at end of file diff --git a/Contribute.markdown b/Contribute.markdown index 5360d36d..8c0ffd18 100644 --- a/Contribute.markdown +++ b/Contribute.markdown @@ -41,5 +41,4 @@ There are Thor tasks to help with getting green - run `thor list` to see them al * `thor jasmine_dev:execute_specs` outputs the expected number of specs that should be run and attempts to run in browser and Node * `thor jasmine_dev:execute_specs_in_browser` opens `spec/runner.html` in the default browser on MacOS. Please run this in at least Firefox and Chrome before committing * `thor jasmine_dev:execute_specs_in_node` runs all the Jasmine specs in Node.js - it will complain if Node is not installed -* `thor jasmine_dev:js_hint` runs all the files through JSHint and will complain about potential viable issues with your code. Fix them. diff --git a/GOALS_2.0.md b/GOALS_2.0.md index e6e9a45a..68eaa5d7 100644 --- a/GOALS_2.0.md +++ b/GOALS_2.0.md @@ -44,3 +44,13 @@ * Docs * JsDoc is a pain to host and RubyMine is pretty good at navigating. I say we kill it officially * Docco has gone over well. Should we annotate all the sources and then have Pages be more complex, having tutorials and annotated source like Backbone? Are we small enough? + +# Build + +* lib -> generated +* + + + + + diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 00000000..0e1d64e2 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,24 @@ +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + jshint: { + options: { + /* While it's possible that we could be considering unwanted prototype methods, mostly + * we're doing this because the objects are being used as maps. + */ + forin: false, + + /* We're fine with functions defined inside loops (setTimeout functions, etc) */ + loopfunc: true + }, + all: ['src/**/*.js'] + } + }); + + grunt.loadNpmTasks('grunt-contrib-jshint'); + + // Default task(s). + grunt.registerTask('default', ['jshint']); +}; \ No newline at end of file diff --git a/README.markdown b/README.markdown index a7eefb17..579d583f 100644 --- a/README.markdown +++ b/README.markdown @@ -7,6 +7,11 @@ Jasmine is a Behavior Driven Development testing framework for JavaScript. It do Documentation & guides live here: [http://pivotal.github.com/jasmine/](http://pivotal.github.com/jasmine/) +# DEV GUIDE + +Dependencies for this repo +* Ruby > 1.9, Rubygems, Bundler +* Node.js, npm ## Support diff --git a/jshint/jshint.js b/jshint/jshint.js deleted file mode 100755 index 013950c6..00000000 --- a/jshint/jshint.js +++ /dev/null @@ -1,5919 +0,0 @@ -/* - * JSHint, by JSHint Community. - * - * Licensed under the same slightly modified MIT license that JSLint is. - * It stops evil-doers everywhere. - * - * JSHint is a derivative work of JSLint: - * - * Copyright (c) 2002 Douglas Crockford (www.JSLint.com) - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * The Software shall be used for Good, not Evil. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * JSHint was forked from 2010-12-16 edition of JSLint. - * - */ - -/* - JSHINT is a global function. It takes two parameters. - - var myResult = JSHINT(source, option); - - The first parameter is either a string or an array of strings. If it is a - string, it will be split on '\n' or '\r'. If it is an array of strings, it - is assumed that each string represents one line. The source can be a - JavaScript text, or HTML text, or a JSON text, or a CSS text. - - The second parameter is an optional object of options which control the - operation of JSHINT. Most of the options are booleans: They are all - optional and have a default value of false. One of the options, predef, - can be an array of names, which will be used to declare global variables, - or an object whose keys are used as global names, with a boolean value - that determines if they are assignable. - - If it checks out, JSHINT returns true. Otherwise, it returns false. - - If false, you can inspect JSHINT.errors to find out the problems. - JSHINT.errors is an array of objects containing these members: - - { - line : The line (relative to 0) at which the lint was found - character : The character (relative to 0) at which the lint was found - reason : The problem - evidence : The text line in which the problem occurred - raw : The raw message before the details were inserted - a : The first detail - b : The second detail - c : The third detail - d : The fourth detail - } - - If a fatal error was found, a null will be the last element of the - JSHINT.errors array. - - You can request a Function Report, which shows all of the functions - and the parameters and vars that they use. This can be used to find - implied global variables and other problems. The report is in HTML and - can be inserted in an HTML
. - - var myReport = JSHINT.report(limited); - - If limited is true, then the report will be limited to only errors. - - You can request a data structure which contains JSHint's results. - - var myData = JSHINT.data(); - - It returns a structure with this form: - - { - errors: [ - { - line: NUMBER, - character: NUMBER, - reason: STRING, - evidence: STRING - } - ], - functions: [ - name: STRING, - line: NUMBER, - last: NUMBER, - param: [ - STRING - ], - closure: [ - STRING - ], - var: [ - STRING - ], - exception: [ - STRING - ], - outer: [ - STRING - ], - unused: [ - STRING - ], - global: [ - STRING - ], - label: [ - STRING - ] - ], - globals: [ - STRING - ], - member: { - STRING: NUMBER - }, - unuseds: [ - { - name: STRING, - line: NUMBER - } - ], - implieds: [ - { - name: STRING, - line: NUMBER - } - ], - urls: [ - STRING - ], - json: BOOLEAN - } - - Empty arrays will not be included. - -*/ - -/*jshint - evil: true, nomen: false, onevar: false, regexp: false, strict: true, boss: true -*/ - -/*members "\b", "\t", "\n", "\f", "\r", "!=", "!==", "\"", "%", - "(begin)", "(breakage)", "(context)", "(error)", "(global)", - "(identifier)", "(last)", "(line)", "(loopage)", "(name)", "(onevar)", - "(params)", "(scope)", "(statement)", "(verb)", "*", "+", "++", "-", - "--", "\/", "<", "<=", "==", "===", ">", ">=", $, ADSAFE, __filename, __dirname, - ActiveXObject, Array, Boolean, Buffer, COM, CScript, Canvas, CustomAnimation, - Date, Debug, E, Enumerator, Error, EvalError, FadeAnimation, Flash, - FormField, Frame, Function, HotKey, Image, JSON, LN10, LN2, LOG10E, - LOG2E, MAX_VALUE, MIN_VALUE, Math, MenuItem, MoveAnimation, - NEGATIVE_INFINITY, Number, Object, Option, PI, POSITIVE_INFINITY, Point, - RangeError, Rectangle, ReferenceError, RegExp, ResizeAnimation, - RotateAnimation, SQRT1_2, SQRT2, ScrollBar, String, Style, SyntaxError, - System, Text, TextArea, Timer, TypeError, URIError, URL, VBArray, - WScript, Web, Window, XMLDOM, XMLHttpRequest, "\\", a, abbr, acronym, - activeborder, activecaption, addEventListener, address, adsafe, alert, - aliceblue, all, animator, antiquewhite, appleScript, applet, apply, - approved, appworkspace, applicationCache, aqua, aquamarine, area, arguments, - arity, article, asi, aside, audio, autocomplete, azure, b, background, - "background-attachment", "background-color", "background-image", - "background-position", "background-repeat", base, bdo, beep, beige, big, - bisque, bitwise, black, blanchedalmond, block, blockquote, blue, - blueviolet, blur, body, border, "border-bottom", "border-bottom-color", - "border-bottom-style", "border-bottom-width", "border-collapse", - "border-color", "border-left", "border-left-color", "border-left-style", - "border-left-width", "border-right", "border-right-color", - "border-right-style", "border-right-width", "border-spacing", - "border-style", "border-top", "border-top-color", "border-top-style", - "border-top-width", "border-width", bottom, boss, br, braille, brown, browser, - burlywood, button, buttonface, buttonhighlight, buttonshadow, - buttontext, bytesToUIString, c, cadetblue, call, callee, caller, canvas, - cap, caption, "caption-side", captiontext, cases, center, charAt, - charCodeAt, character, chartreuse, chocolate, chooseColor, chooseFile, - chooseFolder, cite, clear, clearInterval, clearTimeout, clip, close, - closeWidget, closed, closure, cm, code, col, colgroup, color, command, - comment, condition, confirm, console, constructor, content, - convertPathToHFS, convertPathToPlatform, coral, cornflowerblue, - cornsilk, couch, "counter-increment", "counter-reset", create, crimson, - css, curly, cursor, cyan, d, darkblue, darkcyan, darkgoldenrod, darkgray, - darkgreen, darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, - darkred, darksalmon, darkseagreen, darkslateblue, darkslategray, darkturquoise, - darkviolet, data, datalist, dd, debug, decodeURI, decodeURIComponent, - deeppink, deepskyblue, defaultStatus, defineClass, del, deserialize, - details, devel, dfn, dialog, dimgray, dir, direction, display, div, dl, - document, dodgerblue, dt, edition, else, em, embed, embossed, emit, empty, - "empty-cells", encodeURI, encodeURIComponent, entityify, eqeqeq, errors, - es5, escape, eval, event, evidence, evil, ex, exception, exec, exps, exports, - fieldset, figure, filesystem, FileReader, firebrick, first, float, floor, - floralwhite, focus, focusWidget, font, "font-family", "font-size", - "font-size-adjust", "font-stretch", "font-style", "font-variant", - "font-weight", footer, forestgreen, forin, form, fragment, frame, - frames, frameset, from, fromCharCode, fuchsia, fud, funct, function, - functions, g, gainsboro, gc, getComputedStyle, getRow, ghostwhite, GLOBAL, global, - globals, gold, goldenrod, gray, graytext, green, greenyellow, h1, h2, - h3, h4, h5, h6, handheld, hasOwnProperty, head, header, height, help, - hgroup, highlight, highlighttext, history, honeydew, hotpink, hr, - "hta:application", html, i, iTunes, id, identifier, iframe, img, immed, - implieds, in, inactiveborder, inactivecaption, inactivecaptiontext, - include, indent, indexOf, indianred, indigo, infobackground, infotext, - init, input, ins, isAlpha, isApplicationRunning, isArray, isDigit, - isFinite, isNaN, ivory, join, jshint, JSHINT, json, jquery, jQuery, kbd, - keygen, keys, khaki, konfabulatorVersion, label, labelled, lang, last, - lavender, lavenderblush, lawngreen, laxbreak, lbp, led, left, legend, - lemonchiffon, length, "letter-spacing", li, lib, lightblue, lightcoral, - lightcyan, lightgoldenrodyellow, lightgreen, lightpink, lightsalmon, - lightseagreen, lightskyblue, lightslategray, lightsteelblue, - lightyellow, lime, limegreen, line, "line-height", linen, link, - "list-style", "list-style-image", "list-style-position", - "list-style-type", load, loadClass, localStorage, location, log, loopfunc, m, magenta, - map, margin, "margin-bottom", "margin-left", "margin-right", "margin-top", - mark, "marker-offset", maroon, match, "max-height", "max-width", maxerr, - maxlen, md5, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, - mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, - mediumvioletred, member, menu, menutext, message, meta, meter, - midnightblue, "min-height", "min-width", mintcream, mistyrose, mm, - moccasin, module, moveBy, moveTo, name, nav, navajowhite, navigator, navy, new, - newcap, noarg, node, noempty, noframes, nomen, nonew, noscript, nud, object, ol, - oldlace, olive, olivedrab, on, onbeforeunload, onblur, onerror, onevar, - onfocus, onload, onresize, onunload, opacity, open, openDatabase, openURL, opener, - opera, optgroup, option, orange, orangered, orchid, outer, outline, "outline-color", - "outline-style", "outline-width", output, overflow, "overflow-x", - "overflow-y", p, padding, "padding-bottom", "padding-left", - "padding-right", "padding-top", "page-break-after", "page-break-before", - palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, - param, parent, parseFloat, parseInt, passfail, pc, peachpuff, peru, - pink, play, plum, plusplus, pop, popupMenu, position, powderblue, pre, - predef, preferenceGroups, preferences, print, process, progress, projection, - prompt, prototype, pt, purple, push, px, q, quit, quotes, random, range, - raw, reach, readFile, readUrl, reason, red, regexp, reloadWidget, - removeEventListener, replace, report, require, reserved, resizeBy, resizeTo, - resolvePath, resumeUpdates, respond, rhino, right, rosybrown, royalblue, - rp, rt, ruby, runCommand, runCommandInBg, saddlebrown, safe, salmon, samp, - sandybrown, saveAs, savePreferences, screen, script, scroll, scrollBy, - scrollTo, scrollbar, seagreen, seal, search, seashell, section, send, select, - serialize, setInterval, setTimeout, shift, showWidgetPreferences, - sienna, silver, skyblue, slateblue, slategray, sleep, slice, small, - snow, sort, source, span, spawn, speak, speech, split, springgreen, src, - stack, status, start, steelblue, strict, strong, style, styleproperty, sub, - substr, sum, sup, supplant, suppressUpdates, sync, system, table, - "table-layout", tan, tbody, td, teal, tellWidget, test, "text-align", - "text-decoration", "text-indent", "text-shadow", "text-transform", - textarea, tfoot, th, thead, thistle, threeddarkshadow, threedface, - threedhighlight, threedlightshadow, threedshadow, time, title, - toLowerCase, toString, toUpperCase, toint32, token, tomato, top, tr, tt, - tty, turquoise, tv, type, u, ul, undef, unescape, "unicode-bidi", - unused, unwatch, updateNow, urls, value, valueOf, var, version, - "vertical-align", video, violet, visibility, watch, WebSocket, wheat, white, - "white-space", whitesmoke, widget, width, window, windowframe, windows, - windowtext, Worker, "word-spacing", "word-wrap", yahooCheckLogin, - yahooLogin, yahooLogout, yellow, yellowgreen, "z-index" -*/ - -/*global exports: false */ - -// We build the application inside a function so that we produce only a single -// global variable. That function will be invoked immediately, and its return -// value is the JSHINT function itself. - -var JSHINT = (function () { - "use strict"; - - var adsafe_id, // The widget's ADsafe id. - adsafe_may, // The widget may load approved scripts. - adsafe_went, // ADSAFE.go has been called. - anonname, // The guessed name for anonymous functions. - approved, // ADsafe approved urls. - -// These are operators that should not be used with the ! operator. - - bang = { - '<' : true, - '<=' : true, - '==' : true, - '===': true, - '!==': true, - '!=' : true, - '>' : true, - '>=' : true, - '+' : true, - '-' : true, - '*' : true, - '/' : true, - '%' : true - }, - -// These are property names that should not be permitted in the safe subset. - - banned = { // the member names that ADsafe prohibits. - 'arguments' : true, - callee : true, - caller : true, - constructor : true, - 'eval' : true, - prototype : true, - stack : true, - unwatch : true, - valueOf : true, - watch : true - }, - - -// These are the JSHint boolean options. - - boolOptions = { - adsafe : true, // if ADsafe should be enforced - asi : true, // if automatic semicolon insertion should be tolerated - bitwise : true, // if bitwise operators should not be allowed - boss : true, // if advanced usage of assignments and == should be allowed - browser : true, // if the standard browser globals should be predefined - cap : true, // if upper case HTML should be allowed - couch : true, // if CouchDB globals should be predefined - css : true, // if CSS workarounds should be tolerated - curly : true, // if curly braces around blocks should be required (even in if/for/while) - debug : true, // if debugger statements should be allowed - devel : true, // if logging should be allowed (console, alert, etc.) - eqeqeq : true, // if === should be required - es5 : true, // if ES5 syntax should be allowed - evil : true, // if eval should be allowed - forin : true, // if for in statements must filter - fragment : true, // if HTML fragments should be allowed - immed : true, // if immediate invocations must be wrapped in parens - jquery : true, // if jQuery globals should be predefined - laxbreak : true, // if line breaks should not be checked - loopfunc : true, // if functions should be allowed to be defined within loops - newcap : true, // if constructor names must be capitalized - noarg : true, // if arguments.caller and arguments.callee should be disallowed - node : true, // if the Node.js environment globals should be predefined - noempty : true, // if empty blocks should be disallowed - nonew : true, // if using `new` for side-effects should be disallowed - nomen : true, // if names should be checked - on : true, // if HTML event handlers should be allowed - onevar : true, // if only one var statement per function should be allowed - passfail : true, // if the scan should stop on first error - plusplus : true, // if increment/decrement should not be allowed - regexp : true, // if the . should not be allowed in regexp literals - rhino : true, // if the Rhino environment globals should be predefined - undef : true, // if variables should be declared before used - safe : true, // if use of some browser features should be restricted - windows : true, // if MS Windows-specigic globals should be predefined - strict : true, // require the "use strict"; pragma - sub : true, // if all forms of subscript notation are tolerated - white : true, // if strict whitespace rules apply - widget : true // if the Yahoo Widgets globals should be predefined - }, - -// browser contains a set of global names which are commonly provided by a -// web browser environment. - - browser = { - addEventListener: false, - applicationCache: false, - blur : false, - clearInterval : false, - clearTimeout : false, - close : false, - closed : false, - defaultStatus : false, - document : false, - event : false, - FileReader : false, - focus : false, - frames : false, - getComputedStyle: false, - history : false, - Image : false, - length : false, - localStorage : false, - location : false, - moveBy : false, - moveTo : false, - name : false, - navigator : false, - onbeforeunload : true, - onblur : true, - onerror : true, - onfocus : true, - onload : true, - onresize : true, - onunload : true, - open : false, - openDatabase : false, - opener : false, - Option : false, - parent : false, - print : false, - removeEventListener: false, - resizeBy : false, - resizeTo : false, - screen : false, - scroll : false, - scrollBy : false, - scrollTo : false, - setInterval : false, - setTimeout : false, - status : false, - top : false, - WebSocket : false, - window : false, - Worker : false, - XMLHttpRequest : false - }, - - couch = { - "require" : false, - respond : false, - getRow : false, - emit : false, - send : false, - start : false, - sum : false, - log : false, - exports : false, - module : false - }, - - cssAttributeData, - cssAny, - - cssColorData = { - "aliceblue" : true, - "antiquewhite" : true, - "aqua" : true, - "aquamarine" : true, - "azure" : true, - "beige" : true, - "bisque" : true, - "black" : true, - "blanchedalmond" : true, - "blue" : true, - "blueviolet" : true, - "brown" : true, - "burlywood" : true, - "cadetblue" : true, - "chartreuse" : true, - "chocolate" : true, - "coral" : true, - "cornflowerblue" : true, - "cornsilk" : true, - "crimson" : true, - "cyan" : true, - "darkblue" : true, - "darkcyan" : true, - "darkgoldenrod" : true, - "darkgray" : true, - "darkgreen" : true, - "darkkhaki" : true, - "darkmagenta" : true, - "darkolivegreen" : true, - "darkorange" : true, - "darkorchid" : true, - "darkred" : true, - "darksalmon" : true, - "darkseagreen" : true, - "darkslateblue" : true, - "darkslategray" : true, - "darkturquoise" : true, - "darkviolet" : true, - "deeppink" : true, - "deepskyblue" : true, - "dimgray" : true, - "dodgerblue" : true, - "firebrick" : true, - "floralwhite" : true, - "forestgreen" : true, - "fuchsia" : true, - "gainsboro" : true, - "ghostwhite" : true, - "gold" : true, - "goldenrod" : true, - "gray" : true, - "green" : true, - "greenyellow" : true, - "honeydew" : true, - "hotpink" : true, - "indianred" : true, - "indigo" : true, - "ivory" : true, - "khaki" : true, - "lavender" : true, - "lavenderblush" : true, - "lawngreen" : true, - "lemonchiffon" : true, - "lightblue" : true, - "lightcoral" : true, - "lightcyan" : true, - "lightgoldenrodyellow" : true, - "lightgreen" : true, - "lightpink" : true, - "lightsalmon" : true, - "lightseagreen" : true, - "lightskyblue" : true, - "lightslategray" : true, - "lightsteelblue" : true, - "lightyellow" : true, - "lime" : true, - "limegreen" : true, - "linen" : true, - "magenta" : true, - "maroon" : true, - "mediumaquamarine" : true, - "mediumblue" : true, - "mediumorchid" : true, - "mediumpurple" : true, - "mediumseagreen" : true, - "mediumslateblue" : true, - "mediumspringgreen" : true, - "mediumturquoise" : true, - "mediumvioletred" : true, - "midnightblue" : true, - "mintcream" : true, - "mistyrose" : true, - "moccasin" : true, - "navajowhite" : true, - "navy" : true, - "oldlace" : true, - "olive" : true, - "olivedrab" : true, - "orange" : true, - "orangered" : true, - "orchid" : true, - "palegoldenrod" : true, - "palegreen" : true, - "paleturquoise" : true, - "palevioletred" : true, - "papayawhip" : true, - "peachpuff" : true, - "peru" : true, - "pink" : true, - "plum" : true, - "powderblue" : true, - "purple" : true, - "red" : true, - "rosybrown" : true, - "royalblue" : true, - "saddlebrown" : true, - "salmon" : true, - "sandybrown" : true, - "seagreen" : true, - "seashell" : true, - "sienna" : true, - "silver" : true, - "skyblue" : true, - "slateblue" : true, - "slategray" : true, - "snow" : true, - "springgreen" : true, - "steelblue" : true, - "tan" : true, - "teal" : true, - "thistle" : true, - "tomato" : true, - "turquoise" : true, - "violet" : true, - "wheat" : true, - "white" : true, - "whitesmoke" : true, - "yellow" : true, - "yellowgreen" : true, - - "activeborder" : true, - "activecaption" : true, - "appworkspace" : true, - "background" : true, - "buttonface" : true, - "buttonhighlight" : true, - "buttonshadow" : true, - "buttontext" : true, - "captiontext" : true, - "graytext" : true, - "highlight" : true, - "highlighttext" : true, - "inactiveborder" : true, - "inactivecaption" : true, - "inactivecaptiontext" : true, - "infobackground" : true, - "infotext" : true, - "menu" : true, - "menutext" : true, - "scrollbar" : true, - "threeddarkshadow" : true, - "threedface" : true, - "threedhighlight" : true, - "threedlightshadow" : true, - "threedshadow" : true, - "window" : true, - "windowframe" : true, - "windowtext" : true - }, - - cssBorderStyle, - cssBreak, - - cssLengthData = { - '%': true, - 'cm': true, - 'em': true, - 'ex': true, - 'in': true, - 'mm': true, - 'pc': true, - 'pt': true, - 'px': true - }, - - cssMedia, - cssOverflow, - - devel = { - alert : false, - confirm : false, - console : false, - Debug : false, - opera : false, - prompt : false - }, - - escapes = { - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '/' : '\\/', - '\\': '\\\\' - }, - - funct, // The current function - - functionicity = [ - 'closure', 'exception', 'global', 'label', - 'outer', 'unused', 'var' - ], - - functions, // All of the functions - - global, // The global scope - htmltag = { - a: {}, - abbr: {}, - acronym: {}, - address: {}, - applet: {}, - area: {empty: true, parent: ' map '}, - article: {}, - aside: {}, - audio: {}, - b: {}, - base: {empty: true, parent: ' head '}, - bdo: {}, - big: {}, - blockquote: {}, - body: {parent: ' html noframes '}, - br: {empty: true}, - button: {}, - canvas: {parent: ' body p div th td '}, - caption: {parent: ' table '}, - center: {}, - cite: {}, - code: {}, - col: {empty: true, parent: ' table colgroup '}, - colgroup: {parent: ' table '}, - command: {parent: ' menu '}, - datalist: {}, - dd: {parent: ' dl '}, - del: {}, - details: {}, - dialog: {}, - dfn: {}, - dir: {}, - div: {}, - dl: {}, - dt: {parent: ' dl '}, - em: {}, - embed: {}, - fieldset: {}, - figure: {}, - font: {}, - footer: {}, - form: {}, - frame: {empty: true, parent: ' frameset '}, - frameset: {parent: ' html frameset '}, - h1: {}, - h2: {}, - h3: {}, - h4: {}, - h5: {}, - h6: {}, - head: {parent: ' html '}, - header: {}, - hgroup: {}, - hr: {empty: true}, - 'hta:application': - {empty: true, parent: ' head '}, - html: {parent: '*'}, - i: {}, - iframe: {}, - img: {empty: true}, - input: {empty: true}, - ins: {}, - kbd: {}, - keygen: {}, - label: {}, - legend: {parent: ' details fieldset figure '}, - li: {parent: ' dir menu ol ul '}, - link: {empty: true, parent: ' head '}, - map: {}, - mark: {}, - menu: {}, - meta: {empty: true, parent: ' head noframes noscript '}, - meter: {}, - nav: {}, - noframes: {parent: ' html body '}, - noscript: {parent: ' body head noframes '}, - object: {}, - ol: {}, - optgroup: {parent: ' select '}, - option: {parent: ' optgroup select '}, - output: {}, - p: {}, - param: {empty: true, parent: ' applet object '}, - pre: {}, - progress: {}, - q: {}, - rp: {}, - rt: {}, - ruby: {}, - samp: {}, - script: {empty: true, parent: ' body div frame head iframe p pre span '}, - section: {}, - select: {}, - small: {}, - span: {}, - source: {}, - strong: {}, - style: {parent: ' head ', empty: true}, - sub: {}, - sup: {}, - table: {}, - tbody: {parent: ' table '}, - td: {parent: ' tr '}, - textarea: {}, - tfoot: {parent: ' table '}, - th: {parent: ' tr '}, - thead: {parent: ' table '}, - time: {}, - title: {parent: ' head '}, - tr: {parent: ' table tbody thead tfoot '}, - tt: {}, - u: {}, - ul: {}, - 'var': {}, - video: {} - }, - - ids, // HTML ids - implied, // Implied globals - inblock, - indent, - jsonmode, - - jquery = { - '$' : false, - jQuery : false - }, - - lines, - lookahead, - member, - membersOnly, - nexttoken, - - node = { - __filename : false, - __dirname : false, - Buffer : false, - GLOBAL : false, - global : false, - module : false, - process : false, - require : false - }, - - noreach, - option, - predefined, // Global variables defined by option - prereg, - prevtoken, - - rhino = { - defineClass : false, - deserialize : false, - gc : false, - help : false, - load : false, - loadClass : false, - print : false, - quit : false, - readFile : false, - readUrl : false, - runCommand : false, - seal : false, - serialize : false, - spawn : false, - sync : false, - toint32 : false, - version : false - }, - - scope, // The current scope - src, - stack, - -// standard contains the global names that are provided by the -// ECMAScript standard. - - standard = { - Array : false, - Boolean : false, - Date : false, - decodeURI : false, - decodeURIComponent : false, - encodeURI : false, - encodeURIComponent : false, - Error : false, - 'eval' : false, - EvalError : false, - Function : false, - hasOwnProperty : false, - isFinite : false, - isNaN : false, - JSON : false, - Math : false, - Number : false, - Object : false, - parseInt : false, - parseFloat : false, - RangeError : false, - ReferenceError : false, - RegExp : false, - String : false, - SyntaxError : false, - TypeError : false, - URIError : false - }, - - standard_member = { - E : true, - LN2 : true, - LN10 : true, - LOG2E : true, - LOG10E : true, - MAX_VALUE : true, - MIN_VALUE : true, - NEGATIVE_INFINITY : true, - PI : true, - POSITIVE_INFINITY : true, - SQRT1_2 : true, - SQRT2 : true - }, - - strict_mode, - syntax = {}, - tab, - token, - urls, - warnings, - -// widget contains the global names which are provided to a Yahoo -// (fna Konfabulator) widget. - - widget = { - alert : true, - animator : true, - appleScript : true, - beep : true, - bytesToUIString : true, - Canvas : true, - chooseColor : true, - chooseFile : true, - chooseFolder : true, - closeWidget : true, - COM : true, - convertPathToHFS : true, - convertPathToPlatform : true, - CustomAnimation : true, - escape : true, - FadeAnimation : true, - filesystem : true, - Flash : true, - focusWidget : true, - form : true, - FormField : true, - Frame : true, - HotKey : true, - Image : true, - include : true, - isApplicationRunning : true, - iTunes : true, - konfabulatorVersion : true, - log : true, - md5 : true, - MenuItem : true, - MoveAnimation : true, - openURL : true, - play : true, - Point : true, - popupMenu : true, - preferenceGroups : true, - preferences : true, - print : true, - prompt : true, - random : true, - Rectangle : true, - reloadWidget : true, - ResizeAnimation : true, - resolvePath : true, - resumeUpdates : true, - RotateAnimation : true, - runCommand : true, - runCommandInBg : true, - saveAs : true, - savePreferences : true, - screen : true, - ScrollBar : true, - showWidgetPreferences : true, - sleep : true, - speak : true, - Style : true, - suppressUpdates : true, - system : true, - tellWidget : true, - Text : true, - TextArea : true, - Timer : true, - unescape : true, - updateNow : true, - URL : true, - Web : true, - widget : true, - Window : true, - XMLDOM : true, - XMLHttpRequest : true, - yahooCheckLogin : true, - yahooLogin : true, - yahooLogout : true - }, - - windows = { - ActiveXObject: false, - CScript : false, - Debug : false, - Enumerator : false, - System : false, - VBArray : false, - WScript : false - }, - -// xmode is used to adapt to the exceptions in html parsing. -// It can have these states: -// false .js script file -// html -// outer -// script -// style -// scriptstring -// styleproperty - - xmode, - xquote, - -// Regular expressions. Some of these are stupidly long. - -// unsafe comment or string - ax = /@cc|<\/?|script|\]\s*\]|<\s*!|</i, -// unsafe characters that are silently deleted by one or more browsers - cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/, -// token - tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/(\*(jshint|members?|global)?|=|\/)?|\*[\/=]?|\+(?:=|\++)?|-(?:=|-+)?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=!]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/, -// html token - hx = /^\s*(['"=>\/]|<(?:\/|\!(?:--)?)?|[a-zA-Z][a-zA-Z0-9_\-:]*|[0-9]+|--)/, -// characters in strings that need escapement - nx = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/, - nxg = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, -// outer html token - ox = /[>&]|<[\/!]?|--/, -// star slash - lx = /\*\/|\/\*/, -// identifier - ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/, -// javascript url - jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i, -// url badness - ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto/i, -// style - sx = /^\s*([{:#%.=,>+\[\]@()"';]|\*=?|\$=|\|=|\^=|~=|[a-zA-Z_][a-zA-Z0-9_\-]*|[0-9]+|<\/|\/\*)/, - ssx = /^\s*([@#!"'};:\-%.=,+\[\]()*_]|[a-zA-Z][a-zA-Z0-9._\-]*|\/\*?|\d+(?:\.\d+)?|<\/)/, -// attributes characters - qx = /[^a-zA-Z0-9+\-_\/ ]/, -// query characters for ids - dx = /[\[\]\/\\"'*<>.&:(){}+=#]/, -// catches /* falls through */ comments - ft = /^\s*\/\*\s*falls\sthrough\s*\*\/\s*$/, - - rx = { - outer: hx, - html: hx, - style: sx, - styleproperty: ssx - }; - - - function F() {} // Used by Object.create - - function is_own(object, name) { - -// The object.hasOwnProperty method fails when the property under consideration -// is named 'hasOwnProperty'. So we have to use this more convoluted form. - - return Object.prototype.hasOwnProperty.call(object, name); - } - -// Provide critical ES5 functions to ES3. - - if (typeof Array.isArray !== 'function') { - Array.isArray = function (o) { - return Object.prototype.toString.apply(o) === '[object Array]'; - }; - } - - if (typeof Object.create !== 'function') { - Object.create = function (o) { - F.prototype = o; - return new F(); - }; - } - - if (typeof Object.keys !== 'function') { - Object.keys = function (o) { - var a = [], k; - for (k in o) { - if (is_own(o, k)) { - a.push(k); - } - } - return a; - }; - } - -// Non standard methods - - if (typeof String.prototype.entityify !== 'function') { - String.prototype.entityify = function () { - return this - .replace(/&/g, '&') - .replace(//g, '>'); - }; - } - - if (typeof String.prototype.isAlpha !== 'function') { - String.prototype.isAlpha = function () { - return (this >= 'a' && this <= 'z\uffff') || - (this >= 'A' && this <= 'Z\uffff'); - }; - } - - if (typeof String.prototype.isDigit !== 'function') { - String.prototype.isDigit = function () { - return (this >= '0' && this <= '9'); - }; - } - - if (typeof String.prototype.supplant !== 'function') { - String.prototype.supplant = function (o) { - return this.replace(/\{([^{}]*)\}/g, function (a, b) { - var r = o[b]; - return typeof r === 'string' || typeof r === 'number' ? r : a; - }); - }; - } - - if (typeof String.prototype.name !== 'function') { - String.prototype.name = function () { - -// If the string looks like an identifier, then we can return it as is. -// If the string contains no control characters, no quote characters, and no -// backslash characters, then we can simply slap some quotes around it. -// Otherwise we must also replace the offending characters with safe -// sequences. - - if (ix.test(this)) { - return this; - } - if (nx.test(this)) { - return '"' + this.replace(nxg, function (a) { - var c = escapes[a]; - if (c) { - return c; - } - return '\\u' + ('0000' + a.charCodeAt().toString(16)).slice(-4); - }) + '"'; - } - return '"' + this + '"'; - }; - } - - - function combine(t, o) { - var n; - for (n in o) { - if (is_own(o, n)) { - t[n] = o[n]; - } - } - } - - function assume() { - if (option.safe) - return; - - if (option.couch) - combine(predefined, couch); - - if (option.rhino) - combine(predefined, rhino); - - if (option.node) - combine(predefined, node); - - if (option.devel) - combine(predefined, devel); - - if (option.browser) - combine(predefined, browser); - - if (option.jquery) - combine(predefined, jquery); - - if (option.windows) - combine(predefined, windows); - - if (option.widget) - combine(predefined, widget); - } - - -// Produce an error warning. - - function quit(m, l, ch) { - throw { - name: 'JSHintError', - line: l, - character: ch, - message: m + " (" + Math.floor((l / lines.length) * 100) + - "% scanned)." - }; - } - - function warning(m, t, a, b, c, d) { - var ch, l, w; - t = t || nexttoken; - if (t.id === '(end)') { // `~ - t = token; - } - l = t.line || 0; - ch = t.from || 0; - w = { - id: '(error)', - raw: m, - evidence: lines[l - 1] || '', - line: l, - character: ch, - a: a, - b: b, - c: c, - d: d - }; - w.reason = m.supplant(w); - JSHINT.errors.push(w); - if (option.passfail) { - quit('Stopping. ', l, ch); - } - warnings += 1; - if (warnings >= option.maxerr) { - quit("Too many errors.", l, ch); - } - return w; - } - - function warningAt(m, l, ch, a, b, c, d) { - return warning(m, { - line: l, - from: ch - }, a, b, c, d); - } - - function error(m, t, a, b, c, d) { - var w = warning(m, t, a, b, c, d); - quit("Stopping, unable to continue.", w.line, w.character); - } - - function errorAt(m, l, ch, a, b, c, d) { - return error(m, { - line: l, - from: ch - }, a, b, c, d); - } - - - -// lexical analysis and token construction - - var lex = (function lex() { - var character, from, line, s; - -// Private lex methods - - function nextLine() { - var at; - if (line >= lines.length) { - return false; - } - character = 1; - s = lines[line]; - line += 1; - at = s.search(/ \t/); - if (at >= 0) { - warningAt("Mixed spaces and tabs.", line, at + 1); - } - s = s.replace(/\t/g, tab); - at = s.search(cx); - if (at >= 0) { - warningAt("Unsafe character.", line, at); - } - if (option.maxlen && option.maxlen < s.length) { - warningAt("Line too long.", line, s.length); - } - return true; - } - -// Produce a token object. The token inherits from a syntax symbol. - - function it(type, value) { - var i, t; - if (type === '(color)' || type === '(range)') { - t = {type: type}; - } else if (type === '(punctuator)' || - (type === '(identifier)' && is_own(syntax, value))) { - t = syntax[value] || syntax['(error)']; - } else { - t = syntax[type]; - } - t = Object.create(t); - if (type === '(string)' || type === '(range)') { - if (jx.test(value)) { - warningAt("Script URL.", line, from); - } - } - if (type === '(identifier)') { - t.identifier = true; - if (value === '__iterator__' || value === '__proto__') { - errorAt("Reserved name '{a}'.", - line, from, value); - } else if (option.nomen && - (value.charAt(0) === '_' || - value.charAt(value.length - 1) === '_')) { - warningAt("Unexpected {a} in '{b}'.", line, from, - "dangling '_'", value); - } - } - t.value = value; - t.line = line; - t.character = character; - t.from = from; - i = t.id; - if (i !== '(endline)') { - prereg = i && - (('(,=:[!&|?{};'.indexOf(i.charAt(i.length - 1)) >= 0) || - i === 'return'); - } - return t; - } - -// Public lex methods - - return { - init: function (source) { - if (typeof source === 'string') { - lines = source - .replace(/\r\n/g, '\n') - .replace(/\r/g, '\n') - .split('\n'); - } else { - lines = source; - } - line = 0; - nextLine(); - from = 1; - }, - - range: function (begin, end) { - var c, value = ''; - from = character; - if (s.charAt(0) !== begin) { - errorAt("Expected '{a}' and instead saw '{b}'.", - line, character, begin, s.charAt(0)); - } - for (;;) { - s = s.slice(1); - character += 1; - c = s.charAt(0); - switch (c) { - case '': - errorAt("Missing '{a}'.", line, character, c); - break; - case end: - s = s.slice(1); - character += 1; - return it('(range)', value); - case xquote: - case '\\': - warningAt("Unexpected '{a}'.", line, character, c); - } - value += c; - } - - }, - -// token -- this is called by advance to get the next token. - - token: function () { - var b, c, captures, d, depth, high, i, l, low, q, t; - - function match(x) { - var r = x.exec(s), r1; - if (r) { - l = r[0].length; - r1 = r[1]; - c = r1.charAt(0); - s = s.substr(l); - from = character + l - r1.length; - character += l; - return r1; - } - } - - function string(x) { - var c, j, r = ''; - - if (jsonmode && x !== '"') { - warningAt("Strings must use doublequote.", - line, character); - } - - if (xquote === x || (xmode === 'scriptstring' && !xquote)) { - return it('(punctuator)', x); - } - - function esc(n) { - var i = parseInt(s.substr(j + 1, n), 16); - j += n; - if (i >= 32 && i <= 126 && - i !== 34 && i !== 92 && i !== 39) { - warningAt("Unnecessary escapement.", line, character); - } - character += n; - c = String.fromCharCode(i); - } - j = 0; - for (;;) { - while (j >= s.length) { - j = 0; - if (xmode !== 'html' || !nextLine()) { - errorAt("Unclosed string.", line, from); - } - } - c = s.charAt(j); - if (c === x) { - character += 1; - s = s.substr(j + 1); - return it('(string)', r, x); - } - if (c < ' ') { - if (c === '\n' || c === '\r') { - break; - } - warningAt("Control character in string: {a}.", - line, character + j, s.slice(0, j)); - } else if (c === xquote) { - warningAt("Bad HTML string", line, character + j); - } else if (c === '<') { - if (option.safe && xmode === 'html') { - warningAt("ADsafe string violation.", - line, character + j); - } else if (s.charAt(j + 1) === '/' && (xmode || option.safe)) { - warningAt("Expected '<\\/' and instead saw ''.", line, character); - } else if (s.charAt(j + 1) === '!' && (xmode || option.safe)) { - warningAt("Unexpected ' 0) { - character += 1; - s = s.slice(i); - break; - } else { - if (!nextLine()) { - return it('(end)', ''); - } - } - } - t = match(rx[xmode] || tx); - if (!t) { - t = ''; - c = ''; - while (s && s < '!') { - s = s.substr(1); - } - if (s) { - if (xmode === 'html') { - return it('(error)', s.charAt(0)); - } else { - errorAt("Unexpected '{a}'.", - line, character, s.substr(0, 1)); - } - } - } else { - - // identifier - - if (c.isAlpha() || c === '_' || c === '$') { - return it('(identifier)', t); - } - - // number - - if (c.isDigit()) { - if (xmode !== 'style' && !isFinite(Number(t))) { - warningAt("Bad number '{a}'.", - line, character, t); - } - if (xmode !== 'style' && - xmode !== 'styleproperty' && - s.substr(0, 1).isAlpha()) { - warningAt("Missing space after '{a}'.", - line, character, t); - } - if (c === '0') { - d = t.substr(1, 1); - if (d.isDigit()) { - if (token.id !== '.' && xmode !== 'styleproperty') { - warningAt("Don't use extra leading zeros '{a}'.", - line, character, t); - } - } else if (jsonmode && (d === 'x' || d === 'X')) { - warningAt("Avoid 0x-. '{a}'.", - line, character, t); - } - } - if (t.substr(t.length - 1) === '.') { - warningAt( -"A trailing decimal point can be confused with a dot '{a}'.", line, character, t); - } - return it('(number)', t); - } - switch (t) { - - // string - - case '"': - case "'": - return string(t); - - // // comment - - case '//': - if (src || (xmode && xmode !== 'script')) { - warningAt("Unexpected comment.", line, character); - } else if (xmode === 'script' && /<\s*\//i.test(s)) { - warningAt("Unexpected <\/ in comment.", line, character); - } else if ((option.safe || xmode === 'script') && ax.test(s)) { - warningAt("Dangerous comment.", line, character); - } - s = ''; - token.comment = true; - break; - - // /* comment - - case '/*': - if (src || (xmode && xmode !== 'script' && xmode !== 'style' && xmode !== 'styleproperty')) { - warningAt("Unexpected comment.", line, character); - } - if (option.safe && ax.test(s)) { - warningAt("ADsafe comment violation.", line, character); - } - for (;;) { - i = s.search(lx); - if (i >= 0) { - break; - } - if (!nextLine()) { - errorAt("Unclosed comment.", line, character); - } else { - if (option.safe && ax.test(s)) { - warningAt("ADsafe comment violation.", - line, character); - } - } - } - character += i + 2; - if (s.substr(i, 1) === '/') { - errorAt("Nested comment.", line, character); - } - s = s.substr(i + 2); - token.comment = true; - break; - - // /*members /*jshint /*global - - case '/*members': - case '/*member': - case '/*jshint': - case '/*global': - case '*/': - return { - value: t, - type: 'special', - line: line, - character: character, - from: from - }; - - case '': - break; - // / - case '/': - if (token.id === '/=') { - errorAt( -"A regular expression literal can be confused with '/='.", line, from); - } - if (prereg) { - depth = 0; - captures = 0; - l = 0; - for (;;) { - b = true; - c = s.charAt(l); - l += 1; - switch (c) { - case '': - errorAt("Unclosed regular expression.", - line, from); - return; - case '/': - if (depth > 0) { - warningAt("Unescaped '{a}'.", - line, from + l, '/'); - } - c = s.substr(0, l - 1); - q = { - g: true, - i: true, - m: true - }; - while (q[s.charAt(l)] === true) { - q[s.charAt(l)] = false; - l += 1; - } - character += l; - s = s.substr(l); - q = s.charAt(0); - if (q === '/' || q === '*') { - errorAt("Confusing regular expression.", - line, from); - } - return it('(regexp)', c); - case '\\': - c = s.charAt(l); - if (c < ' ') { - warningAt( -"Unexpected control character in regular expression.", line, from + l); - } else if (c === '<') { - warningAt( -"Unexpected escaped character '{a}' in regular expression.", line, from + l, c); - } - l += 1; - break; - case '(': - depth += 1; - b = false; - if (s.charAt(l) === '?') { - l += 1; - switch (s.charAt(l)) { - case ':': - case '=': - case '!': - l += 1; - break; - default: - warningAt( -"Expected '{a}' and instead saw '{b}'.", line, from + l, ':', s.charAt(l)); - } - } else { - captures += 1; - } - break; - case '|': - b = false; - break; - case ')': - if (depth === 0) { - warningAt("Unescaped '{a}'.", - line, from + l, ')'); - } else { - depth -= 1; - } - break; - case ' ': - q = 1; - while (s.charAt(l) === ' ') { - l += 1; - q += 1; - } - if (q > 1) { - warningAt( -"Spaces are hard to count. Use {{a}}.", line, from + l, q); - } - break; - case '[': - c = s.charAt(l); - if (c === '^') { - l += 1; - if (option.regexp) { - warningAt("Insecure '{a}'.", - line, from + l, c); - } else if (s.charAt(l) === ']') { - errorAt("Unescaped '{a}'.", - line, from + l, '^'); - } - } - q = false; - if (c === ']') { - warningAt("Empty class.", line, - from + l - 1); - q = true; - } -klass: do { - c = s.charAt(l); - l += 1; - switch (c) { - case '[': - case '^': - warningAt("Unescaped '{a}'.", - line, from + l, c); - q = true; - break; - case '-': - if (q) { - q = false; - } else { - warningAt("Unescaped '{a}'.", - line, from + l, '-'); - q = true; - } - break; - case ']': - if (!q) { - warningAt("Unescaped '{a}'.", - line, from + l - 1, '-'); - } - break klass; - case '\\': - c = s.charAt(l); - if (c < ' ') { - warningAt( -"Unexpected control character in regular expression.", line, from + l); - } else if (c === '<') { - warningAt( -"Unexpected escaped character '{a}' in regular expression.", line, from + l, c); - } - l += 1; - q = true; - break; - case '/': - warningAt("Unescaped '{a}'.", - line, from + l - 1, '/'); - q = true; - break; - case '<': - if (xmode === 'script') { - c = s.charAt(l); - if (c === '!' || c === '/') { - warningAt( -"HTML confusion in regular expression '<{a}'.", line, from + l, c); - } - } - q = true; - break; - default: - q = true; - } - } while (c); - break; - case '.': - if (option.regexp) { - warningAt("Insecure '{a}'.", line, - from + l, c); - } - break; - case ']': - case '?': - case '{': - case '}': - case '+': - case '*': - warningAt("Unescaped '{a}'.", line, - from + l, c); - break; - case '<': - if (xmode === 'script') { - c = s.charAt(l); - if (c === '!' || c === '/') { - warningAt( -"HTML confusion in regular expression '<{a}'.", line, from + l, c); - } - } - } - if (b) { - switch (s.charAt(l)) { - case '?': - case '+': - case '*': - l += 1; - if (s.charAt(l) === '?') { - l += 1; - } - break; - case '{': - l += 1; - c = s.charAt(l); - if (c < '0' || c > '9') { - warningAt( -"Expected a number and instead saw '{a}'.", line, from + l, c); - } - l += 1; - low = +c; - for (;;) { - c = s.charAt(l); - if (c < '0' || c > '9') { - break; - } - l += 1; - low = +c + (low * 10); - } - high = low; - if (c === ',') { - l += 1; - high = Infinity; - c = s.charAt(l); - if (c >= '0' && c <= '9') { - l += 1; - high = +c; - for (;;) { - c = s.charAt(l); - if (c < '0' || c > '9') { - break; - } - l += 1; - high = +c + (high * 10); - } - } - } - if (s.charAt(l) !== '}') { - warningAt( -"Expected '{a}' and instead saw '{b}'.", line, from + l, '}', c); - } else { - l += 1; - } - if (s.charAt(l) === '?') { - l += 1; - } - if (low > high) { - warningAt( -"'{a}' should not be greater than '{b}'.", line, from + l, low, high); - } - } - } - } - c = s.substr(0, l - 1); - character += l; - s = s.substr(l); - return it('(regexp)', c); - } - return it('(punctuator)', t); - - // punctuator - - case '.", line, character); - } - character += 3; - s = s.slice(i + 3); - break; - case '#': - if (xmode === 'html' || xmode === 'styleproperty') { - for (;;) { - c = s.charAt(0); - if ((c < '0' || c > '9') && - (c < 'a' || c > 'f') && - (c < 'A' || c > 'F')) { - break; - } - character += 1; - s = s.substr(1); - t += c; - } - if (t.length !== 4 && t.length !== 7) { - warningAt("Bad hex color '{a}'.", line, - from + l, t); - } - return it('(color)', t); - } - return it('(punctuator)', t); - default: - if (xmode === 'outer' && c === '&') { - character += 1; - s = s.substr(1); - for (;;) { - c = s.charAt(0); - character += 1; - s = s.substr(1); - if (c === ';') { - break; - } - if (!((c >= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - c === '#')) { - errorAt("Bad entity", line, from + l, - character); - } - } - break; - } - return it('(punctuator)', t); - } - } - } - } - }; - }()); - - - function addlabel(t, type) { - - if (option.safe && funct['(global)'] && - typeof predefined[t] !== 'boolean') { - warning('ADsafe global: ' + t + '.', token); - } else if (t === 'hasOwnProperty') { - warning("'hasOwnProperty' is a really bad name."); - } - -// Define t in the current function in the current scope. - - if (is_own(funct, t) && !funct['(global)']) { - warning(funct[t] === true ? - "'{a}' was used before it was defined." : - "'{a}' is already defined.", - nexttoken, t); - } - funct[t] = type; - if (funct['(global)']) { - global[t] = funct; - if (is_own(implied, t)) { - warning("'{a}' was used before it was defined.", nexttoken, t); - delete implied[t]; - } - } else { - scope[t] = funct; - } - } - - - function doOption() { - var b, obj, filter, o = nexttoken.value, t, v; - switch (o) { - case '*/': - error("Unbegun comment."); - break; - case '/*members': - case '/*member': - o = '/*members'; - if (!membersOnly) { - membersOnly = {}; - } - obj = membersOnly; - break; - case '/*jshint': - if (option.safe) { - warning("ADsafe restriction."); - } - obj = option; - filter = boolOptions; - break; - case '/*global': - if (option.safe) { - warning("ADsafe restriction."); - } - obj = predefined; - break; - default: - error("What?"); - } - t = lex.token(); -loop: for (;;) { - for (;;) { - if (t.type === 'special' && t.value === '*/') { - break loop; - } - if (t.id !== '(endline)' && t.id !== ',') { - break; - } - t = lex.token(); - } - if (t.type !== '(string)' && t.type !== '(identifier)' && - o !== '/*members') { - error("Bad option.", t); - } - v = lex.token(); - if (v.id === ':') { - v = lex.token(); - if (obj === membersOnly) { - error("Expected '{a}' and instead saw '{b}'.", - t, '*/', ':'); - } - if (t.value === 'indent' && o === '/*jshint') { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.white = true; - obj.indent = b; - } else if (t.value === 'maxerr' && o === '/*jshint') { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.maxerr = b; - } else if (t.value === 'maxlen' && o === '/*jshint') { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.maxlen = b; - } else if (v.value === 'true') { - obj[t.value] = true; - } else if (v.value === 'false') { - obj[t.value] = false; - } else { - error("Bad option value.", v); - } - t = lex.token(); - } else { - if (o === '/*jshint') { - error("Missing option value.", t); - } - obj[t.value] = false; - t = v; - } - } - if (filter) { - assume(); - } - } - - -// We need a peek function. If it has an argument, it peeks that much farther -// ahead. It is used to distinguish -// for ( var i in ... -// from -// for ( var i = ... - - function peek(p) { - var i = p || 0, j = 0, t; - - while (j <= i) { - t = lookahead[j]; - if (!t) { - t = lookahead[j] = lex.token(); - } - j += 1; - } - return t; - } - - - -// Produce the next token. It looks for programming errors. - - function advance(id, t) { - switch (token.id) { - case '(number)': - if (nexttoken.id === '.') { - warning( -"A dot following a number can be confused with a decimal point.", token); - } - break; - case '-': - if (nexttoken.id === '-' || nexttoken.id === '--') { - warning("Confusing minusses."); - } - break; - case '+': - if (nexttoken.id === '+' || nexttoken.id === '++') { - warning("Confusing plusses."); - } - break; - } - if (token.type === '(string)' || token.identifier) { - anonname = token.value; - } - - if (id && nexttoken.id !== id) { - if (t) { - if (nexttoken.id === '(end)') { - warning("Unmatched '{a}'.", t, t.id); - } else { - warning( -"Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.", - nexttoken, id, t.id, t.line, nexttoken.value); - } - } else if (nexttoken.type !== '(identifier)' || - nexttoken.value !== id) { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, id, nexttoken.value); - } - } - prevtoken = token; - token = nexttoken; - for (;;) { - nexttoken = lookahead.shift() || lex.token(); - if (nexttoken.id === '(end)' || nexttoken.id === '(error)') { - return; - } - if (nexttoken.type === 'special') { - doOption(); - } else { - if (nexttoken.id !== '(endline)') { - break; - } - } - } - } - - -// This is the heart of JSHINT, the Pratt parser. In addition to parsing, it -// is looking for ad hoc lint patterns. We add .fud to Pratt's model, which is -// like .nud except that it is only used on the first token of a statement. -// Having .fud makes it much easier to define statement-oriented languages like -// JavaScript. I retained Pratt's nomenclature. - -// .nud Null denotation -// .fud First null denotation -// .led Left denotation -// lbp Left binding power -// rbp Right binding power - -// They are elements of the parsing method called Top Down Operator Precedence. - - function expression(rbp, initial) { - var left; - if (nexttoken.id === '(end)') { - error("Unexpected early end of program.", token); - } - advance(); - if (option.safe && typeof predefined[token.value] === 'boolean' && - (nexttoken.id !== '(' && nexttoken.id !== '.')) { - warning('ADsafe violation.', token); - } - if (initial) { - anonname = 'anonymous'; - funct['(verb)'] = token.value; - } - if (initial === true && token.fud) { - left = token.fud(); - } else { - if (token.nud) { - left = token.nud(); - } else { - if (nexttoken.type === '(number)' && token.id === '.') { - warning( -"A leading decimal point can be confused with a dot: '.{a}'.", - token, nexttoken.value); - advance(); - return token; - } else { - error("Expected an identifier and instead saw '{a}'.", - token, token.id); - } - } - while (rbp < nexttoken.lbp) { - advance(); - if (token.led) { - left = token.led(left); - } else { - error("Expected an operator and instead saw '{a}'.", - token, token.id); - } - } - } - return left; - } - - -// Functions for conformance of style. - - function adjacent(left, right) { - left = left || token; - right = right || nexttoken; - if (option.white || xmode === 'styleproperty' || xmode === 'style') { - if (left.character !== right.from && left.line === right.line) { - warning("Unexpected space after '{a}'.", right, left.value); - } - } - } - - function nobreak(left, right) { - left = left || token; - right = right || nexttoken; - if (option.white && (left.character !== right.from || left.line !== right.line)) { - warning("Unexpected space before '{a}'.", right, right.value); - } - } - - function nospace(left, right) { - left = left || token; - right = right || nexttoken; - if (option.white && !left.comment) { - if (left.line === right.line) { - adjacent(left, right); - } - } - } - - function nonadjacent(left, right) { - if (option.white) { - left = left || token; - right = right || nexttoken; - if (left.line === right.line && left.character === right.from) { - warning("Missing space after '{a}'.", - nexttoken, left.value); - } - } - } - - function nobreaknonadjacent(left, right) { - left = left || token; - right = right || nexttoken; - if (!option.laxbreak && left.line !== right.line) { - warning("Bad line breaking before '{a}'.", right, right.id); - } else if (option.white) { - left = left || token; - right = right || nexttoken; - if (left.character === right.from) { - warning("Missing space after '{a}'.", - nexttoken, left.value); - } - } - } - - function indentation(bias) { - var i; - if (option.white && nexttoken.id !== '(end)') { - i = indent + (bias || 0); - if (nexttoken.from !== i) { - warning( -"Expected '{a}' to have an indentation at {b} instead at {c}.", - nexttoken, nexttoken.value, i, nexttoken.from); - } - } - } - - function nolinebreak(t) { - t = t || token; - if (t.line !== nexttoken.line) { - warning("Line breaking error '{a}'.", t, t.value); - } - } - - - function comma() { - if (token.line !== nexttoken.line) { - if (!option.laxbreak) { - warning("Bad line breaking before '{a}'.", token, nexttoken.id); - } - } else if (token.character !== nexttoken.from && option.white) { - warning("Unexpected space after '{a}'.", nexttoken, token.value); - } - advance(','); - nonadjacent(token, nexttoken); - } - - -// Functional constructors for making the symbols that will be inherited by -// tokens. - - function symbol(s, p) { - var x = syntax[s]; - if (!x || typeof x !== 'object') { - syntax[s] = x = { - id: s, - lbp: p, - value: s - }; - } - return x; - } - - - function delim(s) { - return symbol(s, 0); - } - - - function stmt(s, f) { - var x = delim(s); - x.identifier = x.reserved = true; - x.fud = f; - return x; - } - - - function blockstmt(s, f) { - var x = stmt(s, f); - x.block = true; - return x; - } - - - function reserveName(x) { - var c = x.id.charAt(0); - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { - x.identifier = x.reserved = true; - } - return x; - } - - - function prefix(s, f) { - var x = symbol(s, 150); - reserveName(x); - x.nud = (typeof f === 'function') ? f : function () { - this.right = expression(150); - this.arity = 'unary'; - if (this.id === '++' || this.id === '--') { - if (option.plusplus) { - warning("Unexpected use of '{a}'.", this, this.id); - } else if ((!this.right.identifier || this.right.reserved) && - this.right.id !== '.' && this.right.id !== '[') { - warning("Bad operand.", this); - } - } - return this; - }; - return x; - } - - - function type(s, f) { - var x = delim(s); - x.type = s; - x.nud = f; - return x; - } - - - function reserve(s, f) { - var x = type(s, f); - x.identifier = x.reserved = true; - return x; - } - - - function reservevar(s, v) { - return reserve(s, function () { - if (typeof v === 'function') { - v(this); - } - return this; - }); - } - - - function infix(s, f, p, w) { - var x = symbol(s, p); - reserveName(x); - x.led = function (left) { - if (!w) { - nobreaknonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - } - if (typeof f === 'function') { - return f(left, this); - } else { - this.left = left; - this.right = expression(p); - return this; - } - }; - return x; - } - - - function relation(s, f) { - var x = symbol(s, 100); - x.led = function (left) { - nobreaknonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - var right = expression(100); - if ((left && left.id === 'NaN') || (right && right.id === 'NaN')) { - warning("Use the isNaN function to compare with NaN.", this); - } else if (f) { - f.apply(this, [left, right]); - } - if (left.id === '!') { - warning("Confusing use of '{a}'.", left, '!'); - } - if (right.id === '!') { - warning("Confusing use of '{a}'.", left, '!'); - } - this.left = left; - this.right = right; - return this; - }; - return x; - } - - - function isPoorRelation(node) { - return node && - ((node.type === '(number)' && +node.value === 0) || - (node.type === '(string)' && node.value === '') || - (node.type === 'null' && !option.boss) || - node.type === 'true' || - node.type === 'false' || - node.type === 'undefined'); - } - - - function assignop(s, f) { - symbol(s, 20).exps = true; - return infix(s, function (left, that) { - var l; - that.left = left; - if (predefined[left.value] === false && - scope[left.value]['(global)'] === true) { - warning("Read only.", left); - } else if (left['function']) { - warning("'{a}' is a function.", left, left.value); - } - if (option.safe) { - l = left; - do { - if (typeof predefined[l.value] === 'boolean') { - warning('ADsafe violation.', l); - } - l = l.left; - } while (l); - } - if (left) { - if (left.id === '.' || left.id === '[') { - if (!left.left || left.left.value === 'arguments') { - warning('Bad assignment.', that); - } - that.right = expression(19); - return that; - } else if (left.identifier && !left.reserved) { - if (funct[left.value] === 'exception') { - warning("Do not assign to the exception parameter.", left); - } - that.right = expression(19); - return that; - } - if (left === syntax['function']) { - warning( -"Expected an identifier in an assignment and instead saw a function invocation.", - token); - } - } - error("Bad assignment.", that); - }, 20); - } - - - function bitwise(s, f, p) { - var x = symbol(s, p); - reserveName(x); - x.led = (typeof f === 'function') ? f : function (left) { - if (option.bitwise) { - warning("Unexpected use of '{a}'.", this, this.id); - } - this.left = left; - this.right = expression(p); - return this; - }; - return x; - } - - - function bitwiseassignop(s) { - symbol(s, 20).exps = true; - return infix(s, function (left, that) { - if (option.bitwise) { - warning("Unexpected use of '{a}'.", that, that.id); - } - nonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - if (left) { - if (left.id === '.' || left.id === '[' || - (left.identifier && !left.reserved)) { - expression(19); - return that; - } - if (left === syntax['function']) { - warning( -"Expected an identifier in an assignment, and instead saw a function invocation.", - token); - } - return that; - } - error("Bad assignment.", that); - }, 20); - } - - - function suffix(s, f) { - var x = symbol(s, 150); - x.led = function (left) { - if (option.plusplus) { - warning("Unexpected use of '{a}'.", this, this.id); - } else if ((!left.identifier || left.reserved) && - left.id !== '.' && left.id !== '[') { - warning("Bad operand.", this); - } - this.left = left; - return this; - }; - return x; - } - - - // fnparam means that this identifier is being defined as a function - // argument (see identifier()) - function optionalidentifier(fnparam) { - if (nexttoken.identifier) { - advance(); - if (option.safe && banned[token.value]) { - warning("ADsafe violation: '{a}'.", token, token.value); - } else if (token.reserved && !option.es5) { - // `undefined` as a function param is a common pattern to protect - // against the case when somebody does `undefined = true` and - // help with minification. More info: https://gist.github.com/315916 - if (!fnparam || token.value != 'undefined') { - warning("Expected an identifier and instead saw '{a}' (a reserved word).", - token, token.id); - } - } - return token.value; - } - } - - // fnparam means that this identifier is being defined as a function - // argument - function identifier(fnparam) { - var i = optionalidentifier(fnparam); - if (i) { - return i; - } - if (token.id === 'function' && nexttoken.id === '(') { - warning("Missing name in function statement."); - } else { - error("Expected an identifier and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - } - - - function reachable(s) { - var i = 0, t; - if (nexttoken.id !== ';' || noreach) { - return; - } - for (;;) { - t = peek(i); - if (t.reach) { - return; - } - if (t.id !== '(endline)') { - if (t.id === 'function') { - warning( -"Inner functions should be listed at the top of the outer function.", t); - break; - } - warning("Unreachable '{a}' after '{b}'.", t, t.value, s); - break; - } - i += 1; - } - } - - - function statement(noindent) { - var i = indent, r, s = scope, t = nexttoken; - -// We don't like the empty statement. - - if (t.id === ';') { - warning("Unnecessary semicolon.", t); - advance(';'); - return; - } - -// Is this a labelled statement? - - if (t.identifier && !t.reserved && peek().id === ':') { - advance(); - advance(':'); - scope = Object.create(s); - addlabel(t.value, 'label'); - if (!nexttoken.labelled) { - warning("Label '{a}' on {b} statement.", - nexttoken, t.value, nexttoken.value); - } - if (jx.test(t.value + ':')) { - warning("Label '{a}' looks like a javascript url.", - t, t.value); - } - nexttoken.label = t.value; - t = nexttoken; - } - -// Parse the statement. - - if (!noindent) { - indentation(); - } - r = expression(0, true); - -// Look for the final semicolon. - - if (!t.block) { - if (!r || !r.exps) { - warning("Expected an assignment or function call and instead saw an expression.", token); - } else if (option.nonew && r.id === '(' && r.left.id === 'new') { - warning("Do not use 'new' for side effects."); - } - if (nexttoken.id !== ';') { - if (!option.asi) { - warningAt("Missing semicolon.", token.line, token.from + token.value.length); - } - } else { - adjacent(token, nexttoken); - advance(';'); - nonadjacent(token, nexttoken); - } - } - -// Restore the indentation. - - indent = i; - scope = s; - return r; - } - - - function use_strict() { - if (nexttoken.value === 'use strict') { - if (strict_mode) { - warning("Unnecessary \"use strict\"."); - } - advance(); - advance(';'); - strict_mode = true; - option.newcap = true; - option.undef = true; - return true; - } else { - return false; - } - } - - - function statements(begin) { - var a = [], f, p; - if (option.adsafe) { - switch (begin) { - case 'script': - -// JSHint is also the static analizer for ADsafe. See www.ADsafe.org. - - if (!adsafe_may) { - if (nexttoken.value !== 'ADSAFE' || - peek(0).id !== '.' || - (peek(1).value !== 'id' && - peek(1).value !== 'go')) { - error('ADsafe violation: Missing ADSAFE.id or ADSAFE.go.', - nexttoken); - } - } - if (nexttoken.value === 'ADSAFE' && - peek(0).id === '.' && - peek(1).value === 'id') { - if (adsafe_may) { - error('ADsafe violation.', nexttoken); - } - advance('ADSAFE'); - advance('.'); - advance('id'); - advance('('); - if (nexttoken.value !== adsafe_id) { - error('ADsafe violation: id does not match.', nexttoken); - } - advance('(string)'); - advance(')'); - advance(';'); - adsafe_may = true; - } - break; - case 'lib': - if (nexttoken.value === 'ADSAFE') { - advance('ADSAFE'); - advance('.'); - advance('lib'); - advance('('); - advance('(string)'); - comma(); - f = expression(0); - if (f.id !== 'function') { - error('The second argument to lib must be a function.', f); - } - p = f.funct['(params)']; - p = p && p.join(', '); - if (p && p !== 'lib') { - error("Expected '{a}' and instead saw '{b}'.", - f, '(lib)', '(' + p + ')'); - } - advance(')'); - advance(';'); - return a; - } else { - error("ADsafe lib violation."); - } - } - } - while (!nexttoken.reach && nexttoken.id !== '(end)') { - if (nexttoken.id === ';') { - warning("Unnecessary semicolon."); - advance(';'); - } else { - a.push(statement()); - } - } - return a; - } - - - /* - * Parses a single block. A block is a sequence of statements wrapped in - * braces. - * - * ordinary - true for everything but function bodies and try blocks. - * stmt - true if block can be a single statement (e.g. in if/for/while). - */ - function block(ordinary, stmt) { - var a, - b = inblock, - old_indent = indent, - m = strict_mode, - s = scope, - t; - - inblock = ordinary; - scope = Object.create(scope); - nonadjacent(token, nexttoken); - t = nexttoken; - - if (nexttoken.id === '{') { - advance('{'); - if (nexttoken.id !== '}' || token.line !== nexttoken.line) { - indent += option.indent; - while (!ordinary && nexttoken.from > indent) { - indent += option.indent; - } - if (!ordinary && !use_strict() && !m && option.strict && - funct['(context)']['(global)']) { - warning("Missing \"use strict\" statement."); - } - a = statements(); - strict_mode = m; - indent -= option.indent; - indentation(); - } - advance('}', t); - indent = old_indent; - } else if (!ordinary) { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, '{', nexttoken.value); - } else { - if (!stmt || option.curly) - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, '{', nexttoken.value); - - noreach = true; - a = [statement()]; - noreach = false; - } - funct['(verb)'] = null; - scope = s; - inblock = b; - if (ordinary && option.noempty && (!a || a.length === 0)) { - warning("Empty block."); - } - return a; - } - - - function countMember(m) { - if (membersOnly && typeof membersOnly[m] !== 'boolean') { - warning("Unexpected /*member '{a}'.", token, m); - } - if (typeof member[m] === 'number') { - member[m] += 1; - } else { - member[m] = 1; - } - } - - - function note_implied(token) { - var name = token.value, line = token.line, a = implied[name]; - if (typeof a === 'function') { - a = false; - } - if (!a) { - a = [line]; - implied[name] = a; - } else if (a[a.length - 1] !== line) { - a.push(line); - } - } - - -// CSS parsing. - - function cssName() { - if (nexttoken.identifier) { - advance(); - return true; - } - } - - - function cssNumber() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - nolinebreak(); - } - if (nexttoken.type === '(number)') { - advance('(number)'); - return true; - } - } - - - function cssString() { - if (nexttoken.type === '(string)') { - advance(); - return true; - } - } - - - function cssColor() { - var i, number, value; - if (nexttoken.identifier) { - value = nexttoken.value; - if (value === 'rgb' || value === 'rgba') { - advance(); - advance('('); - for (i = 0; i < 3; i += 1) { - if (i) { - advance(','); - } - number = nexttoken.value; - if (nexttoken.type !== '(number)' || number < 0) { - warning("Expected a positive number and instead saw '{a}'", - nexttoken, number); - advance(); - } else { - advance(); - if (nexttoken.id === '%') { - advance('%'); - if (number > 100) { - warning("Expected a percentage and instead saw '{a}'", - token, number); - } - } else { - if (number > 255) { - warning("Expected a small number and instead saw '{a}'", - token, number); - } - } - } - } - if (value === 'rgba') { - advance(','); - number = +nexttoken.value; - if (nexttoken.type !== '(number)' || number < 0 || number > 1) { - warning("Expected a number between 0 and 1 and instead saw '{a}'", - nexttoken, number); - } - advance(); - if (nexttoken.id === '%') { - warning("Unexpected '%'."); - advance('%'); - } - } - advance(')'); - return true; - } else if (cssColorData[nexttoken.value] === true) { - advance(); - return true; - } - } else if (nexttoken.type === '(color)') { - advance(); - return true; - } - return false; - } - - - function cssLength() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - nolinebreak(); - } - if (nexttoken.type === '(number)') { - advance(); - if (nexttoken.type !== '(string)' && - cssLengthData[nexttoken.value] === true) { - adjacent(); - advance(); - } else if (+token.value !== 0) { - warning("Expected a linear unit and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - return true; - } - return false; - } - - - function cssLineHeight() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - } - if (nexttoken.type === '(number)') { - advance(); - if (nexttoken.type !== '(string)' && - cssLengthData[nexttoken.value] === true) { - adjacent(); - advance(); - } - return true; - } - return false; - } - - - function cssWidth() { - if (nexttoken.identifier) { - switch (nexttoken.value) { - case 'thin': - case 'medium': - case 'thick': - advance(); - return true; - } - } else { - return cssLength(); - } - } - - - function cssMargin() { - if (nexttoken.identifier) { - if (nexttoken.value === 'auto') { - advance(); - return true; - } - } else { - return cssLength(); - } - } - - function cssAttr() { - if (nexttoken.identifier && nexttoken.value === 'attr') { - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - advance(')'); - return true; - } - return false; - } - - - function cssCommaList() { - while (nexttoken.id !== ';') { - if (!cssName() && !cssString()) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - if (nexttoken.id !== ',') { - return true; - } - comma(); - } - } - - - function cssCounter() { - if (nexttoken.identifier && nexttoken.value === 'counter') { - advance(); - advance('('); - advance(); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(')'); - return true; - } - if (nexttoken.identifier && nexttoken.value === 'counters') { - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(')'); - return true; - } - return false; - } - - - function cssShape() { - var i; - if (nexttoken.identifier && nexttoken.value === 'rect') { - advance(); - advance('('); - for (i = 0; i < 4; i += 1) { - if (!cssLength()) { - warning("Expected a number and instead saw '{a}'.", - nexttoken, nexttoken.value); - break; - } - } - advance(')'); - return true; - } - return false; - } - - - function cssUrl() { - var c, url; - if (nexttoken.identifier && nexttoken.value === 'url') { - nexttoken = lex.range('(', ')'); - url = nexttoken.value; - c = url.charAt(0); - if (c === '"' || c === '\'') { - if (url.slice(-1) !== c) { - warning("Bad url string."); - } else { - url = url.slice(1, -1); - if (url.indexOf(c) >= 0) { - warning("Bad url string."); - } - } - } - if (!url) { - warning("Missing url."); - } - advance(); - if (option.safe && ux.test(url)) { - error("ADsafe URL violation."); - } - urls.push(url); - return true; - } - return false; - } - - - cssAny = [cssUrl, function () { - for (;;) { - if (nexttoken.identifier) { - switch (nexttoken.value.toLowerCase()) { - case 'url': - cssUrl(); - break; - case 'expression': - warning("Unexpected expression '{a}'.", - nexttoken, nexttoken.value); - advance(); - break; - default: - advance(); - } - } else { - if (nexttoken.id === ';' || nexttoken.id === '!' || - nexttoken.id === '(end)' || nexttoken.id === '}') { - return true; - } - advance(); - } - } - }]; - - - cssBorderStyle = [ - 'none', 'dashed', 'dotted', 'double', 'groove', - 'hidden', 'inset', 'outset', 'ridge', 'solid' - ]; - - cssBreak = [ - 'auto', 'always', 'avoid', 'left', 'right' - ]; - - cssMedia = { - 'all': true, - 'braille': true, - 'embossed': true, - 'handheld': true, - 'print': true, - 'projection': true, - 'screen': true, - 'speech': true, - 'tty': true, - 'tv': true - }; - - cssOverflow = [ - 'auto', 'hidden', 'scroll', 'visible' - ]; - - cssAttributeData = { - background: [ - true, 'background-attachment', 'background-color', - 'background-image', 'background-position', 'background-repeat' - ], - 'background-attachment': ['scroll', 'fixed'], - 'background-color': ['transparent', cssColor], - 'background-image': ['none', cssUrl], - 'background-position': [ - 2, [cssLength, 'top', 'bottom', 'left', 'right', 'center'] - ], - 'background-repeat': [ - 'repeat', 'repeat-x', 'repeat-y', 'no-repeat' - ], - 'border': [true, 'border-color', 'border-style', 'border-width'], - 'border-bottom': [ - true, 'border-bottom-color', 'border-bottom-style', - 'border-bottom-width' - ], - 'border-bottom-color': cssColor, - 'border-bottom-style': cssBorderStyle, - 'border-bottom-width': cssWidth, - 'border-collapse': ['collapse', 'separate'], - 'border-color': ['transparent', 4, cssColor], - 'border-left': [ - true, 'border-left-color', 'border-left-style', 'border-left-width' - ], - 'border-left-color': cssColor, - 'border-left-style': cssBorderStyle, - 'border-left-width': cssWidth, - 'border-right': [ - true, 'border-right-color', 'border-right-style', - 'border-right-width' - ], - 'border-right-color': cssColor, - 'border-right-style': cssBorderStyle, - 'border-right-width': cssWidth, - 'border-spacing': [2, cssLength], - 'border-style': [4, cssBorderStyle], - 'border-top': [ - true, 'border-top-color', 'border-top-style', 'border-top-width' - ], - 'border-top-color': cssColor, - 'border-top-style': cssBorderStyle, - 'border-top-width': cssWidth, - 'border-width': [4, cssWidth], - bottom: [cssLength, 'auto'], - 'caption-side' : ['bottom', 'left', 'right', 'top'], - clear: ['both', 'left', 'none', 'right'], - clip: [cssShape, 'auto'], - color: cssColor, - content: [ - 'open-quote', 'close-quote', 'no-open-quote', 'no-close-quote', - cssString, cssUrl, cssCounter, cssAttr - ], - 'counter-increment': [ - cssName, 'none' - ], - 'counter-reset': [ - cssName, 'none' - ], - cursor: [ - cssUrl, 'auto', 'crosshair', 'default', 'e-resize', 'help', 'move', - 'n-resize', 'ne-resize', 'nw-resize', 'pointer', 's-resize', - 'se-resize', 'sw-resize', 'w-resize', 'text', 'wait' - ], - direction: ['ltr', 'rtl'], - display: [ - 'block', 'compact', 'inline', 'inline-block', 'inline-table', - 'list-item', 'marker', 'none', 'run-in', 'table', 'table-caption', - 'table-cell', 'table-column', 'table-column-group', - 'table-footer-group', 'table-header-group', 'table-row', - 'table-row-group' - ], - 'empty-cells': ['show', 'hide'], - 'float': ['left', 'none', 'right'], - font: [ - 'caption', 'icon', 'menu', 'message-box', 'small-caption', - 'status-bar', true, 'font-size', 'font-style', 'font-weight', - 'font-family' - ], - 'font-family': cssCommaList, - 'font-size': [ - 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', - 'xx-large', 'larger', 'smaller', cssLength - ], - 'font-size-adjust': ['none', cssNumber], - 'font-stretch': [ - 'normal', 'wider', 'narrower', 'ultra-condensed', - 'extra-condensed', 'condensed', 'semi-condensed', - 'semi-expanded', 'expanded', 'extra-expanded' - ], - 'font-style': [ - 'normal', 'italic', 'oblique' - ], - 'font-variant': [ - 'normal', 'small-caps' - ], - 'font-weight': [ - 'normal', 'bold', 'bolder', 'lighter', cssNumber - ], - height: [cssLength, 'auto'], - left: [cssLength, 'auto'], - 'letter-spacing': ['normal', cssLength], - 'line-height': ['normal', cssLineHeight], - 'list-style': [ - true, 'list-style-image', 'list-style-position', 'list-style-type' - ], - 'list-style-image': ['none', cssUrl], - 'list-style-position': ['inside', 'outside'], - 'list-style-type': [ - 'circle', 'disc', 'square', 'decimal', 'decimal-leading-zero', - 'lower-roman', 'upper-roman', 'lower-greek', 'lower-alpha', - 'lower-latin', 'upper-alpha', 'upper-latin', 'hebrew', 'katakana', - 'hiragana-iroha', 'katakana-oroha', 'none' - ], - margin: [4, cssMargin], - 'margin-bottom': cssMargin, - 'margin-left': cssMargin, - 'margin-right': cssMargin, - 'margin-top': cssMargin, - 'marker-offset': [cssLength, 'auto'], - 'max-height': [cssLength, 'none'], - 'max-width': [cssLength, 'none'], - 'min-height': cssLength, - 'min-width': cssLength, - opacity: cssNumber, - outline: [true, 'outline-color', 'outline-style', 'outline-width'], - 'outline-color': ['invert', cssColor], - 'outline-style': [ - 'dashed', 'dotted', 'double', 'groove', 'inset', 'none', - 'outset', 'ridge', 'solid' - ], - 'outline-width': cssWidth, - overflow: cssOverflow, - 'overflow-x': cssOverflow, - 'overflow-y': cssOverflow, - padding: [4, cssLength], - 'padding-bottom': cssLength, - 'padding-left': cssLength, - 'padding-right': cssLength, - 'padding-top': cssLength, - 'page-break-after': cssBreak, - 'page-break-before': cssBreak, - position: ['absolute', 'fixed', 'relative', 'static'], - quotes: [8, cssString], - right: [cssLength, 'auto'], - 'table-layout': ['auto', 'fixed'], - 'text-align': ['center', 'justify', 'left', 'right'], - 'text-decoration': [ - 'none', 'underline', 'overline', 'line-through', 'blink' - ], - 'text-indent': cssLength, - 'text-shadow': ['none', 4, [cssColor, cssLength]], - 'text-transform': ['capitalize', 'uppercase', 'lowercase', 'none'], - top: [cssLength, 'auto'], - 'unicode-bidi': ['normal', 'embed', 'bidi-override'], - 'vertical-align': [ - 'baseline', 'bottom', 'sub', 'super', 'top', 'text-top', 'middle', - 'text-bottom', cssLength - ], - visibility: ['visible', 'hidden', 'collapse'], - 'white-space': [ - 'normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap', 'inherit' - ], - width: [cssLength, 'auto'], - 'word-spacing': ['normal', cssLength], - 'word-wrap': ['break-word', 'normal'], - 'z-index': ['auto', cssNumber] - }; - - function styleAttribute() { - var v; - while (nexttoken.id === '*' || nexttoken.id === '#' || - nexttoken.value === '_') { - if (!option.css) { - warning("Unexpected '{a}'.", nexttoken, nexttoken.value); - } - advance(); - } - if (nexttoken.id === '-') { - if (!option.css) { - warning("Unexpected '{a}'.", nexttoken, nexttoken.value); - } - advance('-'); - if (!nexttoken.identifier) { - warning( -"Expected a non-standard style attribute and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - return cssAny; - } else { - if (!nexttoken.identifier) { - warning("Excepted a style attribute, and instead saw '{a}'.", - nexttoken, nexttoken.value); - } else { - if (is_own(cssAttributeData, nexttoken.value)) { - v = cssAttributeData[nexttoken.value]; - } else { - v = cssAny; - if (!option.css) { - warning("Unrecognized style attribute '{a}'.", - nexttoken, nexttoken.value); - } - } - } - advance(); - return v; - } - } - - - function styleValue(v) { - var i = 0, - n, - once, - match, - round, - start = 0, - vi; - switch (typeof v) { - case 'function': - return v(); - case 'string': - if (nexttoken.identifier && nexttoken.value === v) { - advance(); - return true; - } - return false; - } - for (;;) { - if (i >= v.length) { - return false; - } - vi = v[i]; - i += 1; - if (vi === true) { - break; - } else if (typeof vi === 'number') { - n = vi; - vi = v[i]; - i += 1; - } else { - n = 1; - } - match = false; - while (n > 0) { - if (styleValue(vi)) { - match = true; - n -= 1; - } else { - break; - } - } - if (match) { - return true; - } - } - start = i; - once = []; - for (;;) { - round = false; - for (i = start; i < v.length; i += 1) { - if (!once[i]) { - if (styleValue(cssAttributeData[v[i]])) { - match = true; - round = true; - once[i] = true; - break; - } - } - } - if (!round) { - return match; - } - } - } - - function styleChild() { - if (nexttoken.id === '(number)') { - advance(); - if (nexttoken.value === 'n' && nexttoken.identifier) { - adjacent(); - advance(); - if (nexttoken.id === '+') { - adjacent(); - advance('+'); - adjacent(); - advance('(number)'); - } - } - return; - } else { - switch (nexttoken.value) { - case 'odd': - case 'even': - if (nexttoken.identifier) { - advance(); - return; - } - } - } - warning("Unexpected token '{a}'.", nexttoken, nexttoken.value); - } - - function substyle() { - var v; - for (;;) { - if (nexttoken.id === '}' || nexttoken.id === '(end)' || - xquote && nexttoken.id === xquote) { - return; - } - while (nexttoken.id === ';') { - warning("Misplaced ';'."); - advance(';'); - } - v = styleAttribute(); - advance(':'); - if (nexttoken.identifier && nexttoken.value === 'inherit') { - advance(); - } else { - if (!styleValue(v)) { - warning("Unexpected token '{a}'.", nexttoken, - nexttoken.value); - advance(); - } - } - if (nexttoken.id === '!') { - advance('!'); - adjacent(); - if (nexttoken.identifier && nexttoken.value === 'important') { - advance(); - } else { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'important', nexttoken.value); - } - } - if (nexttoken.id === '}' || nexttoken.id === xquote) { - warning("Missing '{a}'.", nexttoken, ';'); - } else { - advance(';'); - } - } - } - - function styleSelector() { - if (nexttoken.identifier) { - if (!is_own(htmltag, option.cap ? - nexttoken.value.toLowerCase() : nexttoken.value)) { - warning("Expected a tagName, and instead saw {a}.", - nexttoken, nexttoken.value); - } - advance(); - } else { - switch (nexttoken.id) { - case '>': - case '+': - advance(); - styleSelector(); - break; - case ':': - advance(':'); - switch (nexttoken.value) { - case 'active': - case 'after': - case 'before': - case 'checked': - case 'disabled': - case 'empty': - case 'enabled': - case 'first-child': - case 'first-letter': - case 'first-line': - case 'first-of-type': - case 'focus': - case 'hover': - case 'last-child': - case 'last-of-type': - case 'link': - case 'only-of-type': - case 'root': - case 'target': - case 'visited': - advance(); - break; - case 'lang': - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a lang code, and instead saw :{a}.", - nexttoken, nexttoken.value); - } - advance(')'); - break; - case 'nth-child': - case 'nth-last-child': - case 'nth-last-of-type': - case 'nth-of-type': - advance(); - advance('('); - styleChild(); - advance(')'); - break; - case 'not': - advance(); - advance('('); - if (nexttoken.id === ':' && peek(0).value === 'not') { - warning("Nested not."); - } - styleSelector(); - advance(')'); - break; - default: - warning("Expected a pseudo, and instead saw :{a}.", - nexttoken, nexttoken.value); - } - break; - case '#': - advance('#'); - if (!nexttoken.identifier) { - warning("Expected an id, and instead saw #{a}.", - nexttoken, nexttoken.value); - } - advance(); - break; - case '*': - advance('*'); - break; - case '.': - advance('.'); - if (!nexttoken.identifier) { - warning("Expected a class, and instead saw #.{a}.", - nexttoken, nexttoken.value); - } - advance(); - break; - case '[': - advance('['); - if (!nexttoken.identifier) { - warning("Expected an attribute, and instead saw [{a}].", - nexttoken, nexttoken.value); - } - advance(); - if (nexttoken.id === '=' || nexttoken.value === '~=' || - nexttoken.value === '$=' || - nexttoken.value === '|=' || - nexttoken.id === '*=' || - nexttoken.id === '^=') { - advance(); - if (nexttoken.type !== '(string)') { - warning("Expected a string, and instead saw {a}.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(']'); - break; - default: - error("Expected a CSS selector, and instead saw {a}.", - nexttoken, nexttoken.value); - } - } - } - - function stylePattern() { - if (nexttoken.id === '{') { - warning("Expected a style pattern, and instead saw '{a}'.", nexttoken, - nexttoken.id); - } - for (;;) { - styleSelector(); - if (nexttoken.id === '' || nexttoken.id === '{' || - nexttoken.id === '(end)') { - return ''; - } - if (nexttoken.id === ',') { - comma(); - } - } - } - - function stylelist() { - while (nexttoken.id !== '' && nexttoken.id !== '(end)') { - stylePattern(); - xmode = 'styleproperty'; - if (nexttoken.id === ';') { - advance(';'); - } else { - advance('{'); - substyle(); - xmode = 'style'; - advance('}'); - } - } - } - - function styles() { - var i; - while (nexttoken.id === '@') { - i = peek(); - advance('@'); - if (nexttoken.identifier) { - switch (nexttoken.value) { - case 'import': - advance(); - if (!cssUrl()) { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'url', nexttoken.value); - advance(); - } - advance(';'); - break; - case 'media': - advance(); - for (;;) { - if (!nexttoken.identifier || cssMedia[nexttoken.value] === true) { - error("Expected a CSS media type, and instead saw '{a}'.", nexttoken, nexttoken.id); - } - advance(); - if (nexttoken.id !== ',') { - break; - } - advance(','); - } - advance('{'); - stylelist(); - advance('}'); - break; - default: - warning("Expected an at-rule, and instead saw @{a}.", - nexttoken, nexttoken.value); - } - } else { - warning("Expected an at-rule, and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - } - stylelist(); - } - - -// HTML parsing. - - function doBegin(n) { - if (n !== 'html' && !option.fragment) { - if (n === 'div' && option.adsafe) { - error("ADSAFE: Use the fragment option."); - } else { - error("Expected '{a}' and instead saw '{b}'.", - token, 'html', n); - } - } - if (option.adsafe) { - if (n === 'html') { - error( -"Currently, ADsafe does not operate on whole HTML documents. It operates onProblem' + (isFinite(c.line) ? ' at line ' + - c.line + ' character ' + c.character : '') + - ': ' + c.reason.entityify() + - '
' + - (e && (e.length > 80 ? e.slice(0, 77) + '...' : - e).entityify()) + '
'); - } - } - } - - if (data.implieds) { - s = []; - for (i = 0; i < data.implieds.length; i += 1) { - s[i] = '' + data.implieds[i].name + ' ' +
- data.implieds[i].line + '';
- }
- o.push('Implied global: ' + s.join(', ') + '
'); - } - - if (data.unused) { - s = []; - for (i = 0; i < data.unused.length; i += 1) { - s[i] = '' + data.unused[i].name + ' ' +
- data.unused[i].line + ' ' +
- data.unused[i]['function'] + '';
- }
- o.push('Unused variable: ' + s.join(', ') + '
'); - } - if (data.json) { - o.push('JSON: bad.
'); - } - o.push('CSS.
'); - } else if (data.json && !err) { - o.push('JSON: good.
'); - } else if (data.globals) { - o.push('/*members ';
- l = 10;
- for (i = 0; i < a.length; i += 1) {
- k = a[i];
- n = k.name();
- if (l + n.length > 72) {
- o.push(m + '
');
- m = ' ';
- l = 1;
- }
- l += n.length + 2;
- if (data.member[k] === 1) {
- n = '' + n + '';
- }
- if (i < a.length - 1) {
- n += ', ';
- }
- m += n;
- }
- o.push(m + '
*/');
- }
- o.push('jasmine.undefined instead of undefined, since undefined is just
- * a plain old variable and may be redefined by somebody else.
- *
- * @private
- */
-jasmine.undefined = jasmine.___undefined___;
-
/**
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
*
@@ -439,18 +431,23 @@ jasmine.util.argsToArray = function(args) {
var arrayOfArgs = [];
for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
return arrayOfArgs;
-};jasmine.ExceptionFormatter = function() {
+};
+
+jasmine.util.isUndefined = function(obj) {
+ return obj === void 0;
+};
+jasmine.ExceptionFormatter = function() {
this.message = function(error) {
- var message = error.name
- + ': '
- + error.message;
+ var message = error.name +
+ ': ' +
+ error.message;
if (error.fileName || error.sourceURL) {
message += " in " + (error.fileName || error.sourceURL);
}
if (error.line || error.lineNumber) {
- message += " (line " + (error.line || error.lineNumber) + ")"
+ message += " (line " + (error.line || error.lineNumber) + ")";
}
return message;
@@ -458,7 +455,7 @@ jasmine.util.argsToArray = function(args) {
this.stack = function(error) {
return error ? error.stack : null;
- }
+ };
};//TODO: expectation result may make more sense as a presentation of an expectation.
jasmine.buildExpectationResult = function(options) {
var messageFormatter = options.messageFormatter || function() {},
@@ -475,13 +472,13 @@ jasmine.buildExpectationResult = function(options) {
function message() {
if (options.passed) {
- return "Passed."
+ return "Passed.";
} else if (options.message) {
- return options.message
+ return options.message;
} else if (options.error) {
return messageFormatter(options.error);
}
- return ""
+ return "";
}
function stack() {
@@ -514,8 +511,6 @@ jasmine.buildExpectationResult = function(options) {
this.spies_ = [];
this.currentSpec = null;
- this.undefined = jasmine.undefined;
-
this.reporter = new jasmine.ReportDispatcher([
"jasmineStarted",
"jasmineDone",
@@ -557,20 +552,20 @@ jasmine.buildExpectationResult = function(options) {
return function() {
var befores = [];
for (var suite = currentSuite; suite; suite = suite.parentSuite) {
- befores = befores.concat(suite.beforeFns)
+ befores = befores.concat(suite.beforeFns);
}
return befores.reverse();
- }
+ };
};
var afterFns = function(currentSuite) {
return function() {
var afters = [];
for (var suite = currentSuite; suite; suite = suite.parentSuite) {
- afters = afters.concat(suite.afterFns)
+ afters = afters.concat(suite.afterFns);
}
return afters;
- }
+ };
};
var specConstructor = jasmine.Spec;
@@ -635,7 +630,7 @@ jasmine.buildExpectationResult = function(options) {
exceptionFormatter: exceptionFormatter,
resultCallback: specResultCallback,
getSpecName: function(spec) {
- return getSpecName(spec, suite)
+ return getSpecName(spec, suite);
},
onStart: specStarted,
description: description,
@@ -720,11 +715,11 @@ jasmine.buildExpectationResult = function(options) {
};
jasmine.Env.prototype.spyOn = function(obj, methodName) {
- if (obj == this.undefined) {
+ if (jasmine.util.isUndefined(obj)) {
throw "spyOn could not find an object to spy upon for " + methodName + "()";
}
- if (obj[methodName] === this.undefined) {
+ if (jasmine.util.isUndefined(obj[methodName])) {
throw methodName + '() method does not exist';
}
@@ -879,7 +874,7 @@ jasmine.buildExpectationResult = function(options) {
b.__Jasmine_been_here_before__ = a;
var hasKey = function(obj, keyName) {
- return obj !== null && obj[keyName] !== this.undefined;
+ return obj !== null && !jasmine.util.isUndefined(obj[keyName]);
};
for (var property in b) {
@@ -915,13 +910,15 @@ jasmine.buildExpectationResult = function(options) {
for (var i = 0; i < this.equalityTesters_.length; i++) {
var equalityTester = this.equalityTesters_[i];
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
- if (result !== this.undefined) return result;
+ if (!jasmine.util.isUndefined(result)) {
+ return result;
+ }
}
if (a === b) return true;
- if (a === this.undefined || a === null || b === this.undefined || b === null) {
- return (a == this.undefined && b == this.undefined);
+ if (jasmine.util.isUndefined(a) || a === null || jasmine.util.isUndefined(b) || b === null) {
+ return (jasmine.util.isUndefined(a) && jasmine.util.isUndefined(b));
}
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
@@ -1099,7 +1096,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
actual: this.actual,
message: message
});
- return jasmine.undefined;
+ return void 0;
};
};
@@ -1162,14 +1159,14 @@ jasmine.Matchers.prototype.toNotMatch = function(expected) {
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeDefined = function() {
- return (this.actual !== jasmine.undefined);
+ return !jasmine.util.isUndefined(this.actual);
};
/**
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeUndefined = function() {
- return (this.actual === jasmine.undefined);
+ return jasmine.util.isUndefined(this.actual);
};
/**
@@ -1272,7 +1269,7 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
if (this.actual.callCount === 0) {
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
} else {
- positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '')
+ positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '');
}
return [positiveMessage, invertedMessage];
};
@@ -1335,7 +1332,7 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
* @param {Number} precision, as number of decimal places
*/
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
- if (!(precision === 0)) {
+ if (precision !== 0) {
precision = precision || 2;
}
return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2);
@@ -1357,14 +1354,15 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
} catch (e) {
exception = e;
}
+
if (exception) {
- result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
+ result = (jasmine.util.isUndefined(expected) || this.env.equals_(exception.message || exception, expected.message || expected));
}
var not = this.isNot ? "not " : "";
this.message = function() {
- if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
+ if (exception && (jasmine.util.isUndefined(expected) || !this.env.equals_(exception.message || exception, expected.message || expected))) {
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
} else {
return "Expected function to throw an exception.";
@@ -1413,7 +1411,7 @@ jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function(other, mis
var env = jasmine.getEnv();
var hasKey = function(obj, keyName) {
- return obj != null && obj[keyName] !== jasmine.undefined;
+ return obj !== null && !jasmine.util.isUndefined(obj[keyName]);
};
for (var property in this.sample) {
@@ -1446,7 +1444,7 @@ jasmine.PrettyPrinter = function() {
jasmine.PrettyPrinter.prototype.format = function(value) {
this.ppNestLevel_++;
try {
- if (value === jasmine.undefined) {
+ if (jasmine.util.isUndefined(value)) {
this.emitScalar('undefined');
} else if (value === null) {
this.emitScalar('null');
@@ -1488,7 +1486,7 @@ jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
for (var property in obj) {
if (!obj.hasOwnProperty(property)) continue;
if (property == '__Jasmine_been_here_before__') continue;
- fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
+ fn(property, obj.__lookupGetter__ ? (!jasmine.util.isUndefined(obj.__lookupGetter__(property)) &&
obj.__lookupGetter__(property) !== null) : false);
}
};
@@ -1564,13 +1562,13 @@ jasmine.StringPrettyPrinter.prototype.append = function(value) {
jasmine.QueueRunner = function(attrs) {
this.fns = attrs.fns || [];
this.onComplete = attrs.onComplete || function() {};
- this.encourageGC = attrs.encourageGC || function(fn) {fn()};
+ this.encourageGC = attrs.encourageGC || function(fn) {fn();};
this.onException = attrs.onException || function() {};
this.catchException = attrs.catchException || function() { return true; };
};
jasmine.QueueRunner.prototype.execute = function() {
- this.run(this.fns, 0)
+ this.run(this.fns, 0);
};
jasmine.QueueRunner.prototype.run = function(fns, index) {
@@ -1582,7 +1580,7 @@ jasmine.QueueRunner.prototype.run = function(fns, index) {
var fn = fns[index];
var self = this;
if (fn.length > 0) {
- attempt(function() { fn.call(self, function() { self.run(fns, index + 1) }) });
+ attempt(function() { fn.call(self, function() { self.run(fns, index + 1); }); });
} else {
attempt(function() { fn.call(self); });
self.run(fns, index + 1);
@@ -1814,7 +1812,7 @@ jasmine.Suite.prototype.execute = function(onComplete) {
function wrapChild(child) {
return function (done) {
child.execute(done);
- }
+ };
}
};
jasmine.Clock = function(global, delayedFunctionScheduler) {
@@ -1875,7 +1873,7 @@ jasmine.Clock = function(global, delayedFunctionScheduler) {
self.tick = function(millis) {
if (installed) {
- delayedFunctionScheduler.tick(millis)
+ delayedFunctionScheduler.tick(millis);
} else {
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
}
diff --git a/package.json b/package.json
new file mode 100644
index 00000000..e7e0ccc9
--- /dev/null
+++ b/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "jasmine-core",
+ "license": "MIT",
+ "devDependencies": {
+ "grunt-contrib-jshint": "~0.2.0"
+ }
+}
diff --git a/spec/core/UtilSpec.js b/spec/core/UtilSpec.js
index 17694168..e7441f3d 100644
--- a/spec/core/UtilSpec.js
+++ b/spec/core/UtilSpec.js
@@ -14,4 +14,15 @@ describe("jasmine.util", function() {
expect(jasmine.isArray_(null)).toBe(false);
});
});
+
+ describe("isUndefined", function() {
+ it("reports if a variable is defined", function() {
+ var a;
+ expect(jasmine.util.isUndefined(a)).toBe(true);
+ expect(jasmine.util.isUndefined(undefined)).toBe(true);
+
+ var undefined = "diz be undefined yo";
+ expect(jasmine.util.isUndefined(undefined)).toBe(false);
+ });
+ });
});
diff --git a/spec/node_performance_suite.js b/spec/node_performance_suite.js
index 15678385..907b90bc 100644
--- a/spec/node_performance_suite.js
+++ b/spec/node_performance_suite.js
@@ -2,10 +2,6 @@ var fs = require('fs');
var util = require('util');
var path = require('path');
-// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
-// undefined = "diz be undefined yo";
-
-
var jasmineGlobals = require('../lib/jasmine-core/jasmine.js');
for (var k in jasmineGlobals) {
global[k] = jasmineGlobals[k];
diff --git a/spec/node_suite.js b/spec/node_suite.js
index 569f03c6..df9e733e 100644
--- a/spec/node_suite.js
+++ b/spec/node_suite.js
@@ -2,10 +2,6 @@ var fs = require('fs');
var util = require('util');
var path = require('path');
-// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
-// undefined = "diz be undefined yo";
-
-
var jasmineGlobals = require('../lib/jasmine-core/jasmine.js');
for (var k in jasmineGlobals) {
global[k] = jasmineGlobals[k];
diff --git a/spec/runner.html b/spec/runner.html
index 461632ad..130ccf49 100644
--- a/spec/runner.html
+++ b/spec/runner.html
@@ -20,12 +20,6 @@
var originalJasmine = jasmine;
-
-
-
diff --git a/spec/tasks/jshint_spec.rb b/spec/tasks/jshint_spec.rb
deleted file mode 100644
index 850c12f1..00000000
--- a/spec/tasks/jshint_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require 'spec_helper.rb'
-
-describe "JSHint task" do
-
- let(:tmp_dir) { "#{Dir.tmpdir}/jasmine_tasks_test" }
- let(:jasmine_dev) { JasmineDev.new }
-
- before do
- reset_dir tmp_dir
- end
-
- describe "when Node is not present" do
- before do
- jasmine_dev.should_receive(:has_node?).and_return(false)
- @output = capture_output { jasmine_dev.js_hint }
- end
-
- it "should not tell the user that lint is running" do
- @output.should_not match(/Running JSHint/)
- end
-
- it "should prompt the user to install Node" do
- @output.should match(/Node\.js is required/)
- end
- end
-
- describe "when Node is present" do
- before do
- jasmine_dev.should_receive(:has_node?).and_return(true)
-
- @output = capture_output { jasmine_dev.js_hint }
- end
-
- it "should tell the user that lint is running" do
- @output.should match(/Running JSHint/)
- @output.should match(/Jasmine JSHint PASSED/)
- end
- end
-end
\ No newline at end of file
diff --git a/src/core/Clock.js b/src/core/Clock.js
index 23f3affa..2da053bf 100644
--- a/src/core/Clock.js
+++ b/src/core/Clock.js
@@ -56,7 +56,7 @@ jasmine.Clock = function(global, delayedFunctionScheduler) {
self.tick = function(millis) {
if (installed) {
- delayedFunctionScheduler.tick(millis)
+ delayedFunctionScheduler.tick(millis);
} else {
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
}
diff --git a/src/core/Env.js b/src/core/Env.js
index 5dc71f1c..23374419 100644
--- a/src/core/Env.js
+++ b/src/core/Env.js
@@ -12,8 +12,6 @@
this.spies_ = [];
this.currentSpec = null;
- this.undefined = jasmine.undefined;
-
this.reporter = new jasmine.ReportDispatcher([
"jasmineStarted",
"jasmineDone",
@@ -55,20 +53,20 @@
return function() {
var befores = [];
for (var suite = currentSuite; suite; suite = suite.parentSuite) {
- befores = befores.concat(suite.beforeFns)
+ befores = befores.concat(suite.beforeFns);
}
return befores.reverse();
- }
+ };
};
var afterFns = function(currentSuite) {
return function() {
var afters = [];
for (var suite = currentSuite; suite; suite = suite.parentSuite) {
- afters = afters.concat(suite.afterFns)
+ afters = afters.concat(suite.afterFns);
}
return afters;
- }
+ };
};
var specConstructor = jasmine.Spec;
@@ -133,7 +131,7 @@
exceptionFormatter: exceptionFormatter,
resultCallback: specResultCallback,
getSpecName: function(spec) {
- return getSpecName(spec, suite)
+ return getSpecName(spec, suite);
},
onStart: specStarted,
description: description,
@@ -218,11 +216,11 @@
};
jasmine.Env.prototype.spyOn = function(obj, methodName) {
- if (obj == this.undefined) {
+ if (jasmine.util.isUndefined(obj)) {
throw "spyOn could not find an object to spy upon for " + methodName + "()";
}
- if (obj[methodName] === this.undefined) {
+ if (jasmine.util.isUndefined(obj[methodName])) {
throw methodName + '() method does not exist';
}
@@ -377,7 +375,7 @@
b.__Jasmine_been_here_before__ = a;
var hasKey = function(obj, keyName) {
- return obj !== null && obj[keyName] !== this.undefined;
+ return obj !== null && !jasmine.util.isUndefined(obj[keyName]);
};
for (var property in b) {
@@ -413,13 +411,15 @@
for (var i = 0; i < this.equalityTesters_.length; i++) {
var equalityTester = this.equalityTesters_[i];
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
- if (result !== this.undefined) return result;
+ if (!jasmine.util.isUndefined(result)) {
+ return result;
+ }
}
if (a === b) return true;
- if (a === this.undefined || a === null || b === this.undefined || b === null) {
- return (a == this.undefined && b == this.undefined);
+ if (jasmine.util.isUndefined(a) || a === null || jasmine.util.isUndefined(b) || b === null) {
+ return (jasmine.util.isUndefined(a) && jasmine.util.isUndefined(b));
}
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
diff --git a/src/core/ExceptionFormatter.js b/src/core/ExceptionFormatter.js
index d0fb644f..d3ea7123 100644
--- a/src/core/ExceptionFormatter.js
+++ b/src/core/ExceptionFormatter.js
@@ -1,15 +1,15 @@
jasmine.ExceptionFormatter = function() {
this.message = function(error) {
- var message = error.name
- + ': '
- + error.message;
+ var message = error.name +
+ ': ' +
+ error.message;
if (error.fileName || error.sourceURL) {
message += " in " + (error.fileName || error.sourceURL);
}
if (error.line || error.lineNumber) {
- message += " (line " + (error.line || error.lineNumber) + ")"
+ message += " (line " + (error.line || error.lineNumber) + ")";
}
return message;
@@ -17,5 +17,5 @@ jasmine.ExceptionFormatter = function() {
this.stack = function(error) {
return error ? error.stack : null;
- }
+ };
};
\ No newline at end of file
diff --git a/src/core/ExpectationResult.js b/src/core/ExpectationResult.js
index 2d3c3d57..c2bd968b 100644
--- a/src/core/ExpectationResult.js
+++ b/src/core/ExpectationResult.js
@@ -14,13 +14,13 @@ jasmine.buildExpectationResult = function(options) {
function message() {
if (options.passed) {
- return "Passed."
+ return "Passed.";
} else if (options.message) {
- return options.message
+ return options.message;
} else if (options.error) {
return messageFormatter(options.error);
}
- return ""
+ return "";
}
function stack() {
diff --git a/src/core/Matchers.js b/src/core/Matchers.js
index d7de131b..316b9913 100644
--- a/src/core/Matchers.js
+++ b/src/core/Matchers.js
@@ -61,7 +61,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
actual: this.actual,
message: message
});
- return jasmine.undefined;
+ return void 0;
};
};
@@ -124,14 +124,14 @@ jasmine.Matchers.prototype.toNotMatch = function(expected) {
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeDefined = function() {
- return (this.actual !== jasmine.undefined);
+ return !jasmine.util.isUndefined(this.actual);
};
/**
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeUndefined = function() {
- return (this.actual === jasmine.undefined);
+ return jasmine.util.isUndefined(this.actual);
};
/**
@@ -234,7 +234,7 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
if (this.actual.callCount === 0) {
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
} else {
- positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '')
+ positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '');
}
return [positiveMessage, invertedMessage];
};
@@ -297,7 +297,7 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
* @param {Number} precision, as number of decimal places
*/
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
- if (!(precision === 0)) {
+ if (precision !== 0) {
precision = precision || 2;
}
return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2);
@@ -319,14 +319,15 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
} catch (e) {
exception = e;
}
+
if (exception) {
- result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
+ result = (jasmine.util.isUndefined(expected) || this.env.equals_(exception.message || exception, expected.message || expected));
}
var not = this.isNot ? "not " : "";
this.message = function() {
- if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
+ if (exception && (jasmine.util.isUndefined(expected) || !this.env.equals_(exception.message || exception, expected.message || expected))) {
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
} else {
return "Expected function to throw an exception.";
@@ -375,7 +376,7 @@ jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function(other, mis
var env = jasmine.getEnv();
var hasKey = function(obj, keyName) {
- return obj != null && obj[keyName] !== jasmine.undefined;
+ return obj !== null && !jasmine.util.isUndefined(obj[keyName]);
};
for (var property in this.sample) {
diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js
index f276cea3..81be610f 100644
--- a/src/core/PrettyPrinter.js
+++ b/src/core/PrettyPrinter.js
@@ -13,7 +13,7 @@ jasmine.PrettyPrinter = function() {
jasmine.PrettyPrinter.prototype.format = function(value) {
this.ppNestLevel_++;
try {
- if (value === jasmine.undefined) {
+ if (jasmine.util.isUndefined(value)) {
this.emitScalar('undefined');
} else if (value === null) {
this.emitScalar('null');
@@ -55,7 +55,7 @@ jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
for (var property in obj) {
if (!obj.hasOwnProperty(property)) continue;
if (property == '__Jasmine_been_here_before__') continue;
- fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
+ fn(property, obj.__lookupGetter__ ? (!jasmine.util.isUndefined(obj.__lookupGetter__(property)) &&
obj.__lookupGetter__(property) !== null) : false);
}
};
diff --git a/src/core/QueueRunner.js b/src/core/QueueRunner.js
index 6a4fed4f..c4a5ae4f 100644
--- a/src/core/QueueRunner.js
+++ b/src/core/QueueRunner.js
@@ -1,13 +1,13 @@
jasmine.QueueRunner = function(attrs) {
this.fns = attrs.fns || [];
this.onComplete = attrs.onComplete || function() {};
- this.encourageGC = attrs.encourageGC || function(fn) {fn()};
+ this.encourageGC = attrs.encourageGC || function(fn) {fn();};
this.onException = attrs.onException || function() {};
this.catchException = attrs.catchException || function() { return true; };
};
jasmine.QueueRunner.prototype.execute = function() {
- this.run(this.fns, 0)
+ this.run(this.fns, 0);
};
jasmine.QueueRunner.prototype.run = function(fns, index) {
@@ -19,7 +19,7 @@ jasmine.QueueRunner.prototype.run = function(fns, index) {
var fn = fns[index];
var self = this;
if (fn.length > 0) {
- attempt(function() { fn.call(self, function() { self.run(fns, index + 1) }) });
+ attempt(function() { fn.call(self, function() { self.run(fns, index + 1); }); });
} else {
attempt(function() { fn.call(self); });
self.run(fns, index + 1);
diff --git a/src/core/Suite.js b/src/core/Suite.js
index acb12e14..1438b647 100644
--- a/src/core/Suite.js
+++ b/src/core/Suite.js
@@ -94,6 +94,6 @@ jasmine.Suite.prototype.execute = function(onComplete) {
function wrapChild(child) {
return function (done) {
child.execute(done);
- }
+ };
}
};
diff --git a/src/core/base.js b/src/core/base.js
index aab02e95..c114f7bf 100644
--- a/src/core/base.js
+++ b/src/core/base.js
@@ -8,7 +8,7 @@ var jasmine = {};
// TODO: do we need this now that we have boot.js?
if (typeof window == "undefined" && typeof exports == "object") {
- exports.jasmine = jasmine
+ exports.jasmine = jasmine;
}
/**
@@ -18,14 +18,6 @@ jasmine.unimplementedMethod_ = function() {
throw new Error("unimplemented method");
};
-/**
- * Use jasmine.undefined instead of undefined, since undefined is just
- * a plain old variable and may be redefined by somebody else.
- *
- * @private
- */
-jasmine.undefined = jasmine.___undefined___;
-
/**
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
*
diff --git a/src/core/util.js b/src/core/util.js
index fa9dd212..6490e36b 100644
--- a/src/core/util.js
+++ b/src/core/util.js
@@ -58,4 +58,8 @@ jasmine.util.argsToArray = function(args) {
var arrayOfArgs = [];
for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
return arrayOfArgs;
-};
\ No newline at end of file
+};
+
+jasmine.util.isUndefined = function(obj) {
+ return obj === void 0;
+};
diff --git a/tasks/jasmine_dev.rb b/tasks/jasmine_dev.rb
index 42f066ec..d1405928 100644
--- a/tasks/jasmine_dev.rb
+++ b/tasks/jasmine_dev.rb
@@ -7,7 +7,6 @@ $:.unshift(File.join(File.dirname(__FILE__), "jasmine_dev"))
require "base"
require "sources"
-require "js_hint"
require "build_distribution"
require "build_github_pages"
require "build_standalone_distribution"
diff --git a/tasks/jasmine_dev/build_distribution.rb b/tasks/jasmine_dev/build_distribution.rb
index 0ee98498..3573b8f7 100644
--- a/tasks/jasmine_dev/build_distribution.rb
+++ b/tasks/jasmine_dev/build_distribution.rb
@@ -2,8 +2,6 @@ class JasmineDev < Thor
desc "build_distribution", "Build Jasmine js & css files"
def build_distribution(directory = "./lib/jasmine-core")
- invoke :js_hint
-
say JasmineDev.spacer
say "Building Jasmine distribution from source into #{directory}", :cyan
diff --git a/tasks/jasmine_dev/js_hint.rb b/tasks/jasmine_dev/js_hint.rb
deleted file mode 100644
index d97a93a6..00000000
--- a/tasks/jasmine_dev/js_hint.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-class JasmineDev < Thor
-
- desc "js_hint", "Run Jasmine source through JSHint"
- def js_hint
- say JasmineDev.spacer
-
- return unless node_installed?
-
- say "Running JSHint on Jasmine source and specs...", :cyan
-
- run_with_output "node jshint/run.js", :capture => true
- end
-end
\ No newline at end of file