Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 27b7dce

Browse files
committed
Address initial comments and suggestions from code review by @rlim.
1 parent 9c371fc commit 27b7dce

File tree

8 files changed

+68
-45
lines changed

8 files changed

+68
-45
lines changed

src/extensions/default/JavaScriptCodeHints/HintUtils.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -33,9 +33,7 @@ define(function (require, exports, module) {
3333
DOUBLE_QUOTE = "\"";
3434

3535
function makeToken(value, positions) {
36-
if (positions === undefined) {
37-
positions = [];
38-
}
36+
positions = positions || [];
3937

4038
return {
4139
value: value,
@@ -48,7 +46,8 @@ define(function (require, exports, module) {
4846
*/
4947
function maybeIdentifier(key) {
5048
return (/[0-9a-z_.\$]/i).test(key) ||
51-
(key.indexOf("\"") === 0) || (key.indexOf("\'") === 0);
49+
(key.indexOf(SINGLE_QUOTE) === 0) ||
50+
(key.indexOf(DOUBLE_QUOTE) === 0);
5251
}
5352

5453
/**
@@ -178,7 +177,9 @@ define(function (require, exports, module) {
178177
var LITERAL_NAMES = [
179178
"true", "false", "null", "undefined"
180179
],
181-
LITERAL_TOKENS = LITERAL_NAMES.map(function (t) { return makeToken(t, []); }),
180+
LITERAL_TOKENS = LITERAL_NAMES.map(function (t) {
181+
return makeToken(t, []);
182+
}),
182183
LITERALS = annotateLiterals(LITERAL_TOKENS);
183184

184185
var JSL_GLOBAL_NAMES = [
@@ -193,12 +194,13 @@ define(function (require, exports, module) {
193194
"sync", "toint32", "version", "ActiveXObject", "CScript", "Enumerator",
194195
"System", "VBArray", "WScript"
195196
],
196-
JSL_GLOBALS = annotateGlobals(JSL_GLOBAL_NAMES.map(function (t) {
197+
JSL_GLOBAL_TOKENS = annotateGlobals(JSL_GLOBAL_NAMES.map(function (t) {
197198
return makeToken(t, []);
198-
})).reduce(function (prev, curr) {
199+
})),
200+
JSL_GLOBALS = JSL_GLOBAL_TOKENS.reduce(function (prev, curr) {
199201
prev[curr.value] = curr;
200202
return prev;
201-
}, {});
203+
}, {}); // builds an object from the array of tokens.
202204

203205
var JSL_GLOBALS_BROWSER = [
204206
JSL_GLOBALS.clearInterval,

src/extensions/default/JavaScriptCodeHints/Scope.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -230,8 +230,8 @@ define(function (require, exports, module) {
230230
break;
231231

232232
case "NewExpression":
233-
if (tree['arguments']) { // pacifies JSLint
234-
tree['arguments'].forEach(function (t) {
233+
if (tree["arguments"]) { // pacifies JSLint
234+
tree["arguments"].forEach(function (t) {
235235
_buildScope(t, parent);
236236
});
237237
}
@@ -257,7 +257,7 @@ define(function (require, exports, module) {
257257
break;
258258

259259
case "CallExpression":
260-
tree['arguments'].forEach(function (t) {
260+
tree["arguments"].forEach(function (t) {
261261
_buildScope(t, parent);
262262
});
263263
_buildScope(tree.callee, parent);
@@ -523,35 +523,35 @@ define(function (require, exports, module) {
523523
* Traverse identifier declarations in the scope down via children
524524
*/
525525
Scope.prototype.walkDownDeclarations = function (add, init) {
526-
return this.walkDownList(add, init, 'idDeclarations');
526+
return this.walkDownList(add, init, "idDeclarations");
527527
};
528528

529529
/*
530530
* Traverse identifier occurrences in the scope down via children
531531
*/
532532
Scope.prototype.walkDownIdentifiers = function (add, init) {
533-
return this.walkDownList(add, init, 'idOccurrences');
533+
return this.walkDownList(add, init, "idOccurrences");
534534
};
535535

536536
/*
537537
* Traverse property occurrences in the scope down via children
538538
*/
539539
Scope.prototype.walkDownProperties = function (add, init) {
540-
return this.walkDownList(add, init, 'propOccurrences');
540+
return this.walkDownList(add, init, "propOccurrences");
541541
};
542542

543543
/*
544544
* Traverse associations in the scope down via children
545545
*/
546546
Scope.prototype.walkDownAssociations = function (add, init) {
547-
return this.walkDownList(add, init, 'associations');
547+
return this.walkDownList(add, init, "associations");
548548
};
549549

550550
/*
551551
* Traverse literals in the scope down via children
552552
*/
553553
Scope.prototype.walkDownLiterals = function (add, init) {
554-
return this.walkDownList(add, init, 'literals');
554+
return this.walkDownList(add, init, "literals");
555555
};
556556

557557
/**
@@ -576,35 +576,35 @@ define(function (require, exports, module) {
576576
* Traverse identifier declarations in the scope up via the parent
577577
*/
578578
Scope.prototype.walkUpDeclarations = function (add, init) {
579-
return this.walkUp(add, init, 'idDeclarations');
579+
return this.walkUp(add, init, "idDeclarations");
580580
};
581581

582582
/**
583583
* Traverse identifier occurrences in the scope up via the parent
584584
*/
585585
Scope.prototype.walkUpIdentifiers = function (add, init) {
586-
return this.walkUp(add, init, 'idOccurrences');
586+
return this.walkUp(add, init, "idOccurrences");
587587
};
588588

589589
/**
590590
* Traverse property occurrences in the scope up via the parent
591591
*/
592592
Scope.prototype.walkUpProperties = function (add, init) {
593-
return this.walkUp(add, init, 'propOccurrences');
593+
return this.walkUp(add, init, "propOccurrences");
594594
};
595595

596596
/**
597597
* Traverse associations in the scope up via the parent
598598
*/
599599
Scope.prototype.walkUpAssociations = function (add, init) {
600-
return this.walkUp(add, init, 'associations');
600+
return this.walkUp(add, init, "associations");
601601
};
602602

603603
/**
604604
* Traverse literal occurrences in the scope up via the parent
605605
*/
606606
Scope.prototype.walkUpLiterals = function (add, init) {
607-
return this.walkUp(add, init, 'literals');
607+
return this.walkUp(add, init, "literals");
608608
};
609609

610610
/**

src/extensions/default/JavaScriptCodeHints/ScopeManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),

src/extensions/default/JavaScriptCodeHints/Session.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -114,15 +114,14 @@ define(function (require, exports, module) {
114114
Session.prototype._getPreviousToken = function (cursor) {
115115
var token = this.getToken(cursor),
116116
prev = token,
117-
doc;
117+
doc = this.editor.document;
118118

119119
do {
120120
if (prev.start < cursor.ch) {
121121
cursor.ch = prev.start;
122122
} else if (prev.start > 0) {
123123
cursor.ch = prev.start - 1;
124124
} else if (cursor.line > 0) {
125-
doc = this.editor.document;
126125
cursor.ch = doc.getLine(cursor.line - 1).length;
127126
cursor.line--;
128127
} else {
@@ -180,8 +179,8 @@ define(function (require, exports, module) {
180179
};
181180

182181
/**
183-
* Get the type of the type of the current session, i.e., whether it is a
184-
* property lookup and, if so, what the context of the lookup is.
182+
* Get the type of the current session, i.e., whether it is a property
183+
* lookup and, if so, what the context of the lookup is.
185184
*/
186185
Session.prototype.getType = function () {
187186
var propertyLookup = false,
@@ -227,7 +226,7 @@ define(function (require, exports, module) {
227226
* Compute the minimum distance between a token, with which is
228227
* associated a sorted list of positions, and a given offset.
229228
*/
230-
function mindist(pos, token) {
229+
function minDistToPos(pos, token) {
231230
var arr = token.positions,
232231
low = 0,
233232
high = arr.length,
@@ -275,26 +274,26 @@ define(function (require, exports, module) {
275274
if (token.distToPos >= 0) {
276275
dist = token.distToPos;
277276
} else {
278-
dist = mindist(pos, token);
277+
dist = minDistToPos(pos, token);
279278
token.distToPos = dist;
280279
}
281280
return dist;
282281
}
283282

284-
var adist = getDistToPos(a),
285-
bdist = getDistToPos(b);
283+
var aDist = getDistToPos(a),
284+
bDist = getDistToPos(b);
286285

287-
if (adist === Infinity) {
288-
if (bdist === Infinity) {
286+
if (aDist === Infinity) {
287+
if (bDist === Infinity) {
289288
return 0;
290289
} else {
291290
return 1;
292291
}
293292
} else {
294-
if (bdist === Infinity) {
293+
if (bDist === Infinity) {
295294
return -1;
296295
} else {
297-
return adist - bdist;
296+
return aDist - bDist;
298297
}
299298
}
300299
};

src/extensions/default/JavaScriptCodeHints/main.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -232,9 +232,8 @@ define(function (require, exports, module) {
232232
JSHints.prototype.getHints = function (key) {
233233
var cursor = session.getCursor(),
234234
token = session.getToken(cursor);
235-
if ((key === null) || HintUtils.maybeIdentifier(token.string)) {
236-
if (token && HintUtils.hintable(token)) {
237-
235+
if ((key === null) || HintUtils.hintable(token)) {
236+
if (token) {
238237
if (!cachedScope) {
239238
var offset = session.getOffset(),
240239
scopeResponse = ScopeManager.getScopeInfo(session.editor.document, offset),

src/extensions/default/JavaScriptCodeHints/parser-worker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -67,8 +67,8 @@ function require(url) {
6767
"use strict";
6868

6969
var Scope = require("Scope.js"),
70-
HintUtils = require('HintUtils.js'),
71-
esprima = require('thirdparty/esprima/esprima.js');
70+
HintUtils = require("HintUtils.js"),
71+
esprima = require("thirdparty/esprima/esprima.js");
7272

7373
var MAX_RETRIES = 100;
7474

src/extensions/default/JavaScriptCodeHints/styles/brackets-js-hints.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),

src/extensions/default/JavaScriptCodeHints/unittests.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
124
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
225
/*global define, describe, it, xit, expect, beforeEach, afterEach, waitsFor, runs, $, brackets, waitsForDone */
326

0 commit comments

Comments
 (0)