Skip to content

Commit

Permalink
[[FIX]] Global "use strict" regressions
Browse files Browse the repository at this point in the history
Fixes gh-2657 and gh-2661
  • Loading branch information
nicolo-ribaudo authored and jugglinmike committed Oct 3, 2015
1 parent e85c2a1 commit 04b43d2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5321,7 +5321,10 @@ var JSHINT = (function() {
directives();

if (state.directive["use strict"]) {
if (state.option.strict !== "global") {
if (state.option.strict !== "global" &&
!((state.option.strict === true || !state.option.strict) &&
(state.option.globalstrict || state.option.module || state.option.node ||
state.option.phantom || state.option.browserify))) {
warning("W097", state.tokens.prev);
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ exports.node = function (test) {
.addError(1, "Read only.")
.test(overwrites, { es3: true, browserify: true });

TestRun(test, "gh-2657")
.test("'use strict';var a;", { node: true });

// Implied `strict: global` if `strict` is `true`
JSHINT("", { node: true, strict: true });
test.strictEqual(JSHINT.data().options.strict, "global");

test.done();
};

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,9 @@ exports.globalstrict = function (test) {
code = '(function (test) { "use strict"; return; }());';
TestRun(test).test(code, { globalstrict: true, strict: true });

TestRun(test, "gh-2661")
.test("'use strict';", { strict: false, globalstrict: true });

test.done();
};

Expand Down

0 comments on commit 04b43d2

Please sign in to comment.