Skip to content

Commit

Permalink
First pass at lexer refactoring.
Browse files Browse the repository at this point in the history
This commit will break your tree. It features a half-completed
lexer refactoring. See followup commits for more info.
  • Loading branch information
valueof committed Nov 13, 2012
1 parent 169ae4b commit e0eeef6
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 187 deletions.
45 changes: 20 additions & 25 deletions src/stable/jshint.js
Expand Up @@ -30,6 +30,7 @@

/*jshint quotmark:double */

var _ = require("underscore");
var vars = require("../shared/vars.js");
var messages = require("../shared/messages.js");
var lex = require("./lex.js").lex;
Expand Down Expand Up @@ -211,12 +212,6 @@ var JSHINT = (function () {

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);
}

function checkOption(name, t) {
if (valOptions[name] === undefined && boolOptions[name] === undefined) {
error("E001", t, name);
Expand Down Expand Up @@ -294,7 +289,7 @@ var JSHINT = (function () {
Object.keys = function (o) {
var a = [], k;
for (k in o) {
if (is_own(o, k)) {
if (_.has(o, k)) {
a.push(k);
}
}
Expand Down Expand Up @@ -324,7 +319,7 @@ var JSHINT = (function () {
function combine(t, o) {
var n;
for (n in o) {
if (is_own(o, n) && !is_own(JSHINT.blacklist, n)) {
if (_.has(o, n) && !_.has(JSHINT.blacklist, n)) {
t[n] = o[n];
}
}
Expand Down Expand Up @@ -503,14 +498,14 @@ var JSHINT = (function () {

// Define t in the current function in the current scope.
if (type === "exception") {
if (is_own(funct["(context)"], t)) {
if (_.has(funct["(context)"], t)) {
if (funct[t] !== true && !state.option.node) {
warning("W002", state.tokens.next, t);
}
}
}

if (is_own(funct, t) && !funct["(global)"]) {
if (_.has(funct, t) && !funct["(global)"]) {
if (funct[t] === true) {
if (state.option.latedef)
warning("W003", state.tokens.next, t);
Expand All @@ -529,7 +524,7 @@ var JSHINT = (function () {

if (funct["(global)"]) {
global[t] = funct;
if (is_own(implied, t)) {
if (_.has(implied, t)) {
if (state.option.latedef) {
warning("W003", state.tokens.next, t);
}
Expand Down Expand Up @@ -695,7 +690,7 @@ loop:
combine(predefined, predef);

for (var key in predef) {
if (is_own(predef, key)) {
if (_.has(predef, key)) {
declared[key] = nt;
}
}
Expand Down Expand Up @@ -1470,7 +1465,7 @@ loop:
if (isfunc) {
m = {};
for (d in state.directive) {
if (is_own(state.directive, d)) {
if (_.has(state.directive, d)) {
m[d] = state.directive[d];
}
}
Expand Down Expand Up @@ -1908,7 +1903,7 @@ loop:
default:
if (c.id !== "function") {
i = c.value.substr(0, 1);
if (state.option.newcap && (i < "A" || i > "Z") && !is_own(global, c.value)) {
if (state.option.newcap && (i < "A" || i > "Z") && !_.has(global, c.value)) {
warning("W055", state.tokens.curr);
}
}
Expand Down Expand Up @@ -2251,7 +2246,7 @@ loop:
var props = {}; // All properties, including accessors

function saveProperty(name, tkn) {
if (props[name] && is_own(props, name))
if (props[name] && _.has(props, name))
warning("W075", state.tokens.next, i);
else
props[name] = {};
Expand All @@ -2261,7 +2256,7 @@ loop:
}

function saveSetter(name, tkn) {
if (props[name] && is_own(props, name)) {
if (props[name] && _.has(props, name)) {
if (props[name].basic || props[name].setter)
warning("W075", state.tokens.next, i);
} else {
Expand All @@ -2273,7 +2268,7 @@ loop:
}

function saveGetter(name) {
if (props[name] && is_own(props, name)) {
if (props[name] && _.has(props, name)) {
if (props[name].basic || props[name].getter)
warning("W075", state.tokens.next, i);
} else {
Expand Down Expand Up @@ -2365,7 +2360,7 @@ loop:
// Check for lonely setters if in the ES5 mode.
if (state.option.es5) {
for (var name in props) {
if (is_own(props, name) && props[name].setter && !props[name].getter) {
if (_.has(props, name) && props[name].setter && !props[name].getter) {
warning("W078", props[name].setterToken);
}
}
Expand All @@ -2377,8 +2372,8 @@ loop:
};
}(delim("{")));

// This Function is called when esnext option is set to true
// it adds the `const` statement to JSHINT
// This Function is called when esnext option is set to true
// it adds the `const` statement to JSHINT

useESNextSyntax = function () {
var conststatement = stmt("const", function (prefix) {
Expand Down Expand Up @@ -2958,7 +2953,7 @@ loop:
return this;
}).exps = true;

// Superfluous reserved words
// Superfluous reserved words

reserve("class");
reserve("const");
Expand Down Expand Up @@ -3175,7 +3170,7 @@ loop:

// Check options
for (var name in o) {
if (is_own(o, name)) {
if (_.has(o, name)) {
checkOption(name, state.tokens.curr);
}
}
Expand Down Expand Up @@ -3293,7 +3288,7 @@ loop:

functions.forEach(function (func) {
for (var key in func) {
if (is_own(func, key)) {
if (_.has(func, key)) {
checkUnused(func, key);
}
}
Expand Down Expand Up @@ -3323,7 +3318,7 @@ loop:
});

for (var key in declared) {
if (is_own(declared, key) && !is_own(global, key)) {
if (_.has(declared, key) && !_.has(global, key)) {
warnUnused(key, declared[key]);
}
}
Expand Down Expand Up @@ -3376,7 +3371,7 @@ loop:
}

for (n in implied) {
if (is_own(implied, n)) {
if (_.has(implied, n)) {
implieds.push({
name: n,
line: implied[n]
Expand Down

0 comments on commit e0eeef6

Please sign in to comment.