Skip to content

Commit

Permalink
[[FIX]] Require const intlzr in C-style for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Mar 12, 2019
1 parent 404c9a0 commit 307e9fc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4284,8 +4284,9 @@ var JSHINT = (function() {
// head of for-in and for-of statements. If this binding list is being
// parsed as part of a `for` statement of any kind, allow the initializer
// to be omitted. Although this may erroneously allow such forms from
// "C-style" `for` statements (i.e. `for (;;) {}`, the `for` statement
// logic includes dedicated logic to issue the error for such cases.
// "C-style" `for` statements (i.e. `for (const x;;) {}`, the `for`
// statement logic includes dedicated logic to issue the error for such
// cases.
if (!noin && isConst && state.tokens.next.id !== "=") {
warning("E012", state.tokens.curr, state.tokens.curr.value);
}
Expand Down Expand Up @@ -5123,6 +5124,10 @@ var JSHINT = (function() {
nolinebreak(state.tokens.curr);
advance(";");
if (decl) {
if (decl.value === "const" && !decl.hasInitializer) {
warning("E012", decl, decl.first[0].value);
}

decl.first.forEach(function(token) {
state.funct["(scope)"].initialize(token.value);
});
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2338,3 +2338,23 @@ exports.initializeCStyle = function(test) {

test.done();
};

exports.constWithoutInit = function(test) {
TestRun(test, "single binding")
.addError(1, 6, "const 'x' is initialized to 'undefined'.")
.test([
"for (const x; ;) {",
" void x;",
"}"
], { esversion: 6 });

TestRun(test, "multiple bindings")
.addError(1, 6, "const 'y' is initialized to 'undefined'.")
.test([
"for (const y, z; ;) {",
" void (y, z);",
"}"
], { esversion: 6 });

test.done();
};

0 comments on commit 307e9fc

Please sign in to comment.