Permalink
Browse files

Don't assume 'strict' for 'node' environments.

We don't need to warn people about using "use strict" outside
of a function scope in Node environments but my previous naive
implementation was achieving this by simply turning 'globalstrict'
on. This doesn't really work because it 'globalstrict' implies
'strict' which  is not always wanted. This patch Fixes it.

Fixes GH-721.
  • Loading branch information...
1 parent 94cce9c commit 69a350aee42b9975ea1945375895b61f559fe035 @valueof valueof committed Oct 31, 2012
Showing with 12 additions and 5 deletions.
  1. +6 −3 src/stable/jshint.js
  2. +6 −2 tests/stable/unit/envs.js
View
@@ -777,7 +777,6 @@ var JSHINT = (function () {
if (option.node) {
combine(predefined, node);
- option.globalstrict = true;
}
if (option.devel) {
@@ -928,6 +927,7 @@ var JSHINT = (function () {
// If smarttabs option is used check for spaces followed by tabs only.
// Otherwise check for any occurence of mixed tabs and spaces.
// Tabs and one space followed by block comment is allowed.
+
if (option.smarttabs) {
// negative look-behind for "//"
match = s.match(/(\/\/)? \t/);
@@ -4403,8 +4403,11 @@ loop:
break;
default:
directives();
- if (directive["use strict"] && !option.globalstrict) {
- warning("Use the function form of \"use strict\".", prevtoken);
+
+ if (directive["use strict"]) {
+ if (!option.globalstrict && !option.node) {
+ warning("Use the function form of \"use strict\".", prevtoken);
+ }
}
statements();
@@ -94,10 +94,14 @@ exports.node = function (test) {
TestRun(test)
.addError(1, 'Use the function form of "use strict".')
- .test(globalStrict);
+ .test(globalStrict, { strict: true });
TestRun(test)
- .test(globalStrict, { node: true });
+ .test(globalStrict, { node: true, strict: true });
+
+ // Don't assume strict:true for Node environments. See bug GH-721.
+ TestRun(test)
+ .test("function test() { return; }", { node: true });
// Make sure that we can do fancy Node export

0 comments on commit 69a350a

Please sign in to comment.