Skip to content

Commit

Permalink
Issue #1388: Warn about missing 'use strict' in files w/o funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
valueof committed Dec 25, 2013
1 parent 39a40e4 commit 7ec3f14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser.js
Expand Up @@ -3923,6 +3923,8 @@ function parse(input, options, program) {
if (!state.option.globalstrict && !(state.option.node || state.option.phantom)) {
warn("W097", { token: state.tokens.prev });
}
} else if (state.option.globalstrict && state.option.strict) {
warn("E007");
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/options.js
Expand Up @@ -940,6 +940,11 @@ 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
TestRun(test)
.addError(1, 'Missing "use strict" statement.')
.test(["var a = 1;", "a += 1;"], { globalstrict: true, strict: true });

test.done();
};

Expand Down

0 comments on commit 7ec3f14

Please sign in to comment.