Add remaining JSDoc annotations

This commit is contained in:
Ian Wehrman committed 2013-02-24 12:45:58 -08:00
1 parent 91487e3a6a
commit c0e75bcc7e
6 files changed
+481 -136

No files matched your search

@@ -28,7 +28,8 @@
* Loads a file that contains an AMD module definition using the web worker
* importScripts global function.
*
* @param {String} url - The URL of the module to load
* @param {String} url - the URL of the module to load
* @return {Object} - the module imported from the aforementioned URL
*/
function require(url) {
"use strict";
@@ -43,6 +44,10 @@ function require(url) {
* array of bindings, which are ignored. In the former case, the wrapper
* function expects require, exports and module arguments; in the latter
* case, the wrapper function expects only an exports arguments.
*
* @param {?Array<String>} bindings - an optional list of resources
* required by the module
* @param {Function} wrapper - the function that defines the module
*/
self.define = function (bindings, wrapper) {
var module = { exports: exports },
@@ -70,8 +75,14 @@ function require(url) {
HintUtils = require("HintUtils.js"),
esprima = require("thirdparty/esprima/esprima.js");
// maximum number of times a file will be reparsed before failing
var MAX_RETRIES = 10;
/**
* Send a log message back from the worker to the main thread
*
* @param {String} msg - the log message
*/
function _log(msg) {
self.postMessage({log: msg });
}
@@ -79,13 +90,20 @@ function require(url) {
/**
* Walk the scope to find all the objects of a given type, along with a
* list of their positions in the file.
*
* @param {Function} walk - the function used to walk over an implicit scope
* @param {String} keyProp - the property of the implicit scope to walk over
* @param {Array<Object>} - a list of hint tokens for the implicit scope,
* including the positions at which they occur.
*/
function siftPositions(walk, keyProp) {
var occurrences,
results = [],
key,
token,
comparator = function (a, b) { return a - b; };
comparator = function (a, b) {
return a - b;
};
occurrences = walk(function (acc, token) {
if (Object.prototype.hasOwnProperty.call(acc, token[keyProp])) {
@@ -107,6 +125,12 @@ function require(url) {
/**
* Walk the scope to compute all available association objects
*
* @param {Function} walk - the function used to walk over an implicit scope
* @param {Object} - a set of association objects: each property is a
* property name; each value is an association, which indicates the
* number of times the property occurs w.r.t. to a particular lookup
* context.
*/
function siftAssociations(walk) {
return walk(function (acc, assoc) {
@@ -128,31 +152,36 @@ function require(url) {
}
/**
* Look for a JSLint globals annotation in the comments
* Parse JSLint globals annotations from an array of JavaScript comments
*
* @param {Array<String>} comments - list of JavaScript comments
* @return {Array<Object>} - a list of global hint objects as described by
* JSLint annotations found in the comments.
*/
function extractGlobals(comments) {
var globals = [];
if (comments) {
comments.forEach(function (c) {
if (c.type === "Block" && c.value) {
if (c.value.indexOf("global") === 0) {
c.value.substring(7).split(",").forEach(function (g) {
var index = g.indexOf(":");
comments.forEach(function (comment) {
if (comment.type === "Block" && comment.value) {
var val = comment.value;
if (val.indexOf("global") === 0) {
val.substring(7).split(",").forEach(function (global) {
var index = global.indexOf(":");
if (index >= 0) {
g = g.substring(0, index);
global = global.substring(0, index);
}
globals.push(HintUtils.makeToken(g.trim()));
globals.push(HintUtils.makeToken(global.trim()));
});
} else if (c.value.indexOf("jslint") === 0) {
c.value.substring(7).split(",").forEach(function (e) {
var index = e.indexOf(":"),
prop = (index >= 0) ? e.substring(0, index).trim() : "",
val = (index >= 0) ? e.substring(index + 1, e.length).trim() : "";
} else if (val.indexOf("jslint") === 0) {
val.substring(7).split(",").forEach(function (ann) {
var index = ann.indexOf(":"),
aKey = (index >= 0) ? ann.substring(0, index).trim() : "",
aVal = (index >= 0) ? ann.substring(index + 1, ann.length).trim() : "";
if (val === "true" && HintUtils.JSL_GLOBAL_DEFS.hasOwnProperty(prop)) {
globals = globals.concat(HintUtils.JSL_GLOBAL_DEFS[prop]);
if (aVal === "true" && HintUtils.JSL_GLOBAL_DEFS.hasOwnProperty(aKey)) {
globals = globals.concat(HintUtils.JSL_GLOBAL_DEFS[aKey]);
}
});
}
@@ -164,6 +193,12 @@ function require(url) {
/**
* Send the scope and associated parse information back to the caller.
* Called by the parse function below.
*
* @param {String} dir - the directory name of the parsed file
* @param {String} file - the file name of the parsed file
* @param {Number} length - the length of the parsed file
* @param {Object} parseObj - scope and token data from the parsed file
*/
function respond(dir, file, length, parseObj) {
var success = !!parseObj,
@@ -195,7 +230,16 @@ function require(url) {
}
/**
* Use Esprima to parse a JavaScript text
* Parse a JavaScript text with Esprima. This function is intended to be
* called asynchronously; the respond function above is called with the
* results of parsing.
*
* @param {String} dir - the directory name of the file to parse
* @param {String} file - the file name of the file to parse
* @param {String} text - the text of the file to parse
* @param {Number} retries - the number of times an unparseable text should
* be retried, after blanking whatever lines are causing the parsing
* errors.
*/
function parse(dir, file, text, retries) {
try {