mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Add built-in global objects, and a TODO to also add built-in global properties and associations.
This commit is contained in:
1 parent
9a8c8e8c3f
commit
9c371fc518
3 files changed
+41
-12
No files matched your search
@@ -161,13 +161,18 @@ define(function (require, exports, module) {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO 1: The definitions below should be defined in a separate JSON file.
|
||||
// TODO 2: Add properties and associations for the builtin globals.
|
||||
|
||||
var KEYWORD_NAMES = [
|
||||
"break", "case", "catch", "continue", "debugger", "default", "delete",
|
||||
"do", "else", "finally", "for", "function", "if", "in", "instanceof",
|
||||
"new", "return", "switch", "this", "throw", "try", "typeof", "var",
|
||||
"void", "while", "with"
|
||||
],
|
||||
KEYWORD_TOKENS = KEYWORD_NAMES.map(function (t) { return makeToken(t, []); }),
|
||||
KEYWORD_TOKENS = KEYWORD_NAMES.map(function (t) {
|
||||
return makeToken(t, []);
|
||||
}),
|
||||
KEYWORDS = annotateKeywords(KEYWORD_TOKENS);
|
||||
|
||||
var LITERAL_NAMES = [
|
||||
@@ -176,7 +181,7 @@ define(function (require, exports, module) {
|
||||
LITERAL_TOKENS = LITERAL_NAMES.map(function (t) { return makeToken(t, []); }),
|
||||
LITERALS = annotateLiterals(LITERAL_TOKENS);
|
||||
|
||||
var JSL_GLOBALS = [
|
||||
var JSL_GLOBAL_NAMES = [
|
||||
"clearInterval", "clearTimeout", "document", "event", "frames",
|
||||
"history", "Image", "location", "name", "navigator", "Option",
|
||||
"parent", "screen", "setInterval", "setTimeout", "window",
|
||||
@@ -187,10 +192,13 @@ define(function (require, exports, module) {
|
||||
"readFile", "readUrl", "runCommand", "seal", "serialize", "spawn",
|
||||
"sync", "toint32", "version", "ActiveXObject", "CScript", "Enumerator",
|
||||
"System", "VBArray", "WScript"
|
||||
].reduce(function (prev, curr) {
|
||||
prev[curr] = makeToken(curr);
|
||||
return prev;
|
||||
}, {});
|
||||
],
|
||||
JSL_GLOBALS = annotateGlobals(JSL_GLOBAL_NAMES.map(function (t) {
|
||||
return makeToken(t, []);
|
||||
})).reduce(function (prev, curr) {
|
||||
prev[curr.value] = curr;
|
||||
return prev;
|
||||
}, {});
|
||||
|
||||
var JSL_GLOBALS_BROWSER = [
|
||||
JSL_GLOBALS.clearInterval,
|
||||
@@ -274,6 +282,22 @@ define(function (require, exports, module) {
|
||||
windows : JSL_GLOBALS_WINDOWS
|
||||
};
|
||||
|
||||
var BUILTIN_GLOBAL_NAMES = [
|
||||
"Array", "Boolean", "Date", "Function", "Iterator", "Number", "Object",
|
||||
"RegExp", "String", "ArrayBuffer", "DataView", "Float32Array",
|
||||
"Float64Array", "Int16Array", "Int32Array", "Int8Array", "Uint16Array",
|
||||
"Uint32Array", "Uint8Array", "Uint8ClampedArray", "Error", "EvalError",
|
||||
"InternalError", "RangeError", "ReferenceError", "StopIteration",
|
||||
"SyntaxError", "TypeError", "URIError", "decodeURI",
|
||||
"decodeURIComponent", "encodeURI", "encodeURIComponent", "eval",
|
||||
"isFinite", "isNaN", "parseFloat", "parseInt", "uneval", "Infinity",
|
||||
"JSON", "Math", "NaN"
|
||||
],
|
||||
BUILTIN_GLOBAL_TOKENS = BUILTIN_GLOBAL_NAMES.map(function (t) {
|
||||
return makeToken(t, []);
|
||||
}),
|
||||
BUILTIN_GLOBALS = annotateGlobals(BUILTIN_GLOBAL_TOKENS);
|
||||
|
||||
exports.makeToken = makeToken;
|
||||
exports.hintable = hintable;
|
||||
exports.maybeIdentifier = maybeIdentifier;
|
||||
@@ -285,6 +309,7 @@ define(function (require, exports, module) {
|
||||
exports.annotateWithScope = annotateWithScope;
|
||||
exports.annotateWithAssociation = annotateWithAssociation;
|
||||
exports.JSL_GLOBAL_DEFS = JSL_GLOBAL_DEFS;
|
||||
exports.BUILTIN_GLOBALS = BUILTIN_GLOBALS;
|
||||
exports.KEYWORDS = KEYWORDS;
|
||||
exports.LITERALS = LITERALS;
|
||||
exports.MODE_NAME = MODE_NAME;
|
||||
|
||||
@@ -162,8 +162,6 @@ function require(url) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
globals.sort(function (a, b) { return a.value < b.value; });
|
||||
return globals;
|
||||
}
|
||||
|
||||
@@ -210,9 +208,15 @@ function require(url) {
|
||||
comment : true
|
||||
});
|
||||
|
||||
var scope = new Scope(ast),
|
||||
definedGlobals = extractGlobals(ast.comments),
|
||||
builtinGlobals = HintUtils.BUILTIN_GLOBALS,
|
||||
allGlobals = definedGlobals.concat(builtinGlobals),
|
||||
comparator = function (a, b) { return a.value < b.value; };
|
||||
|
||||
respond(dir, file, text.length, {
|
||||
scope : new Scope(ast),
|
||||
globals : extractGlobals(ast.comments)
|
||||
scope : scope,
|
||||
globals : allGlobals.sort(comparator)
|
||||
});
|
||||
} catch (err) {
|
||||
// If parsing fails, we can try again after blanking out the line
|
||||
|
||||
@@ -185,11 +185,11 @@ define(function (require, exports, module) {
|
||||
hintsPresentExact(hintObj, ["A2", "A3", "A1"]);
|
||||
hintsAbsent(hintObj, ["funB"]);
|
||||
});
|
||||
|
||||
|
||||
it("should list keywords", function () {
|
||||
testEditor.setCursorPos({ line: 6, ch: 0 });
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
hintsPresent(hintObj, ["function", "var", "switch"]);
|
||||
hintsPresent(hintObj, ["break", "case", "catch"]);
|
||||
});
|
||||
|
||||
it("should list explicitly defined globals from JSLint annotations", function () {
|
||||
|
||||
Reference in new issue
Block a user