Address initial comments and suggestions from code review by @rlim.

This commit is contained in:
Ian Wehrman committed 2013-02-21 11:01:14 -08:00
1 parent 9c371fc518
commit 27b7dce115
8 files changed
+68 -45

No files matched your search

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -33,9 +33,7 @@ define(function (require, exports, module) {
DOUBLE_QUOTE = "\"";
function makeToken(value, positions) {
if (positions === undefined) {
positions = [];
}
positions = positions || [];
return {
value: value,
@@ -48,7 +46,8 @@ define(function (require, exports, module) {
*/
function maybeIdentifier(key) {
return (/[0-9a-z_.\$]/i).test(key) ||
(key.indexOf("\"") === 0) || (key.indexOf("\'") === 0);
(key.indexOf(SINGLE_QUOTE) === 0) ||
(key.indexOf(DOUBLE_QUOTE) === 0);
}
/**
@@ -178,7 +177,9 @@ define(function (require, exports, module) {
var LITERAL_NAMES = [
"true", "false", "null", "undefined"
],
LITERAL_TOKENS = LITERAL_NAMES.map(function (t) { return makeToken(t, []); }),
LITERAL_TOKENS = LITERAL_NAMES.map(function (t) {
return makeToken(t, []);
}),
LITERALS = annotateLiterals(LITERAL_TOKENS);
var JSL_GLOBAL_NAMES = [
@@ -193,12 +194,13 @@ define(function (require, exports, module) {
"sync", "toint32", "version", "ActiveXObject", "CScript", "Enumerator",
"System", "VBArray", "WScript"
],
JSL_GLOBALS = annotateGlobals(JSL_GLOBAL_NAMES.map(function (t) {
JSL_GLOBAL_TOKENS = annotateGlobals(JSL_GLOBAL_NAMES.map(function (t) {
return makeToken(t, []);
})).reduce(function (prev, curr) {
})),
JSL_GLOBALS = JSL_GLOBAL_TOKENS.reduce(function (prev, curr) {
prev[curr.value] = curr;
return prev;
}, {});
}, {}); // builds an object from the array of tokens.
var JSL_GLOBALS_BROWSER = [
JSL_GLOBALS.clearInterval,
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -230,8 +230,8 @@ define(function (require, exports, module) {
break;
case "NewExpression":
if (tree['arguments']) { // pacifies JSLint
tree['arguments'].forEach(function (t) {
if (tree["arguments"]) { // pacifies JSLint
tree["arguments"].forEach(function (t) {
_buildScope(t, parent);
});
}
@@ -257,7 +257,7 @@ define(function (require, exports, module) {
break;
case "CallExpression":
tree['arguments'].forEach(function (t) {
tree["arguments"].forEach(function (t) {
_buildScope(t, parent);
});
_buildScope(tree.callee, parent);
@@ -523,35 +523,35 @@ define(function (require, exports, module) {
* Traverse identifier declarations in the scope down via children
*/
Scope.prototype.walkDownDeclarations = function (add, init) {
return this.walkDownList(add, init, 'idDeclarations');
return this.walkDownList(add, init, "idDeclarations");
};
/*
* Traverse identifier occurrences in the scope down via children
*/
Scope.prototype.walkDownIdentifiers = function (add, init) {
return this.walkDownList(add, init, 'idOccurrences');
return this.walkDownList(add, init, "idOccurrences");
};
/*
* Traverse property occurrences in the scope down via children
*/
Scope.prototype.walkDownProperties = function (add, init) {
return this.walkDownList(add, init, 'propOccurrences');
return this.walkDownList(add, init, "propOccurrences");
};
/*
* Traverse associations in the scope down via children
*/
Scope.prototype.walkDownAssociations = function (add, init) {
return this.walkDownList(add, init, 'associations');
return this.walkDownList(add, init, "associations");
};
/*
* Traverse literals in the scope down via children
*/
Scope.prototype.walkDownLiterals = function (add, init) {
return this.walkDownList(add, init, 'literals');
return this.walkDownList(add, init, "literals");
};
/**
@@ -576,35 +576,35 @@ define(function (require, exports, module) {
* Traverse identifier declarations in the scope up via the parent
*/
Scope.prototype.walkUpDeclarations = function (add, init) {
return this.walkUp(add, init, 'idDeclarations');
return this.walkUp(add, init, "idDeclarations");
};
/**
* Traverse identifier occurrences in the scope up via the parent
*/
Scope.prototype.walkUpIdentifiers = function (add, init) {
return this.walkUp(add, init, 'idOccurrences');
return this.walkUp(add, init, "idOccurrences");
};
/**
* Traverse property occurrences in the scope up via the parent
*/
Scope.prototype.walkUpProperties = function (add, init) {
return this.walkUp(add, init, 'propOccurrences');
return this.walkUp(add, init, "propOccurrences");
};
/**
* Traverse associations in the scope up via the parent
*/
Scope.prototype.walkUpAssociations = function (add, init) {
return this.walkUp(add, init, 'associations');
return this.walkUp(add, init, "associations");
};
/**
* Traverse literal occurrences in the scope up via the parent
*/
Scope.prototype.walkUpLiterals = function (add, init) {
return this.walkUp(add, init, 'literals');
return this.walkUp(add, init, "literals");
};
/**
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -114,7 +114,7 @@ define(function (require, exports, module) {
Session.prototype._getPreviousToken = function (cursor) {
var token = this.getToken(cursor),
prev = token,
doc;
doc = this.editor.document;
do {
if (prev.start < cursor.ch) {
@@ -122,7 +122,6 @@ define(function (require, exports, module) {
} else if (prev.start > 0) {
cursor.ch = prev.start - 1;
} else if (cursor.line > 0) {
doc = this.editor.document;
cursor.ch = doc.getLine(cursor.line - 1).length;
cursor.line--;
} else {
@@ -180,8 +179,8 @@ define(function (require, exports, module) {
};
/**
* Get the type of the type of the current session, i.e., whether it is a
* property lookup and, if so, what the context of the lookup is.
* Get the type of the current session, i.e., whether it is a property
* lookup and, if so, what the context of the lookup is.
*/
Session.prototype.getType = function () {
var propertyLookup = false,
@@ -227,7 +226,7 @@ define(function (require, exports, module) {
* Compute the minimum distance between a token, with which is
* associated a sorted list of positions, and a given offset.
*/
function mindist(pos, token) {
function minDistToPos(pos, token) {
var arr = token.positions,
low = 0,
high = arr.length,
@@ -275,26 +274,26 @@ define(function (require, exports, module) {
if (token.distToPos >= 0) {
dist = token.distToPos;
} else {
dist = mindist(pos, token);
dist = minDistToPos(pos, token);
token.distToPos = dist;
}
return dist;
}
var adist = getDistToPos(a),
bdist = getDistToPos(b);
var aDist = getDistToPos(a),
bDist = getDistToPos(b);
if (adist === Infinity) {
if (bdist === Infinity) {
if (aDist === Infinity) {
if (bDist === Infinity) {
return 0;
} else {
return 1;
}
} else {
if (bdist === Infinity) {
if (bDist === Infinity) {
return -1;
} else {
return adist - bdist;
return aDist - bDist;
}
}
};
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -232,9 +232,8 @@ define(function (require, exports, module) {
JSHints.prototype.getHints = function (key) {
var cursor = session.getCursor(),
token = session.getToken(cursor);
if ((key === null) || HintUtils.maybeIdentifier(token.string)) {
if (token && HintUtils.hintable(token)) {
if ((key === null) || HintUtils.hintable(token)) {
if (token) {
if (!cachedScope) {
var offset = session.getOffset(),
scopeResponse = ScopeManager.getScopeInfo(session.editor.document, offset),
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -67,8 +67,8 @@ function require(url) {
"use strict";
var Scope = require("Scope.js"),
HintUtils = require('HintUtils.js'),
esprima = require('thirdparty/esprima/esprima.js');
HintUtils = require("HintUtils.js"),
esprima = require("thirdparty/esprima/esprima.js");
var MAX_RETRIES = 100;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -1,3 +1,26 @@
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* 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 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.
*
*/
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, xit, expect, beforeEach, afterEach, waitsFor, runs, $, brackets, waitsForDone */