Skip to content

Commit

Permalink
Function scoped options; closed jshint#37
Browse files Browse the repository at this point in the history
  • Loading branch information
valueof committed Apr 11, 2011
1 parent 9c07e4c commit 2b4583e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
12 changes: 9 additions & 3 deletions jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2841,8 +2841,13 @@ loop: for (;;) {


function doFunction(i, statement) {
var f, s = scope;
scope = Object.create(s);
var f,
oldOption = option,
oldScope = scope;

option = Object.create(option);
scope = Object.create(scope);

funct = {
'(name)' : i || '"' + anonname + '"',
'(line)' : nexttoken.line,
Expand All @@ -2861,7 +2866,8 @@ loop: for (;;) {
funct['(params)'] = functionparams();

block(false);
scope = s;
scope = oldScope;
option = oldOption;
funct['(last)'] = token.line;
funct = funct['(context)'];
return f;
Expand Down
10 changes: 10 additions & 0 deletions tests/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,14 @@ exports.testVoid = function () {
, "var a = void(1);"
];
assert.ok(JSHINT(code));
};

exports.functionScopedOptions = function () {
var src = fs.readFileSync(__dirname + '/fixtures/functionScopedOptions.js', 'utf8');
assert.ok(!JSHINT(src));
assert.eql(JSHINT.errors.length, 2);
assert.eql(JSHINT.errors[0].line, 1);
assert.eql(JSHINT.errors[0].reason, "eval is evil.");
assert.eql(JSHINT.errors[1].line, 8);
assert.eql(JSHINT.errors[1].reason, "eval is evil.");
};
8 changes: 8 additions & 0 deletions tests/fixtures/functionScopedOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eval("hey();");

(function () {
/*jshint evil:true */
eval("hey();");
}());

eval("hey();");

0 comments on commit 2b4583e

Please sign in to comment.