Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue #1451: Fix a regression caused by #1388

Signed-off-by: Anton Kovalyov <anton@kovalyov.net>
  • Loading branch information...
commit c0785c0355ef7f76b4cbe92ed273a5a15e6391a2 1 parent eee3e80
@julienw julienw authored valueof committed
Showing with 21 additions and 4 deletions.
  1. +8 −2 src/jshint.js
  2. +13 −2 tests/unit/options.js
View
10 src/jshint.js
@@ -1704,6 +1704,14 @@ var JSHINT = (function () {
}
r = expression(0, true);
+ if (r && (!r.identifier || r.value !== "function") && (r.type !== "(punctuator)")) {
+ if (!state.directive["use strict"] &&
+ state.option.globalstrict &&
+ state.option.strict) {
+ warning("E007");
+ }
+ }
+
// Look for the final semicolon.
if (!t.block) {
@@ -4834,8 +4842,6 @@ var JSHINT = (function () {
if (!state.option.globalstrict && !(state.option.node || state.option.phantom)) {
warning("W097", state.tokens.prev);
}
- } else if (state.option.globalstrict && state.option.strict) {
- warning("E007");
}
statements();
View
15 tests/unit/options.js
@@ -1123,10 +1123,21 @@ exports.globalstrict = function (test) {
// Don't enforce "use strict"; if strict has been explicitly set to false
TestRun(test).test(code[1], { es3: true, globalstrict: true, strict: false });
- // Check that we can detect missing directives in files without functions
+ // Check that we can detect missing "use strict"; statement for code that is
+ // not inside a function
+ code = [
+ "var a = 1;",
+ "a += 1;",
+ "function func() {}"
+ ];
TestRun(test)
.addError(1, 'Missing "use strict" statement.')
- .test(["var a = 1;", "a += 1;"], { globalstrict: true, strict: true });
+ .test(code, { globalstrict: true, strict: true });
+
+ // globalscript does not prevent you from using only the function-mode
+ // "use strict";
+ code = '(function (test) { "use strict"; return; }());';
+ TestRun(test).test(code, { globalstrict: true, strict: true });
test.done();
};
Please sign in to comment.
Something went wrong with that request. Please try again.