Skip to content

Commit

Permalink
[[FIX]] Init block bindings in C-style for loop
Browse files Browse the repository at this point in the history
Previously, the `noin` production parameter was interpreted as an
indication of a `for/in` or `for/of` loop. This is incorrect because the
production parameter will also be set in the context of a C-style `for`
loop.

Ensure that block-scoped bindings are initialized sequentially for
C-style `for` loops.
  • Loading branch information
jugglinmike authored and rwaldron committed Mar 12, 2019
1 parent 8d71df8 commit 404c9a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jshint.js
Expand Up @@ -4334,7 +4334,7 @@ var JSHINT = (function() {
// Bindings are not immediately initialized in for-in and for-of
// statements. As with `const` initializers (described above), the `for`
// statement parsing logic includes
if (!noin) {
if (state.tokens.next.value !== "in" && state.tokens.next.value !== "of") {
for (t in tokens) {
if (tokens.hasOwnProperty(t)) {
t = tokens[t];
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/core.js
Expand Up @@ -2327,3 +2327,14 @@ exports["TDZ within for in/of head"] = function(test) {

test.done();
};

// regression test for gh-3370
exports.initializeCStyle = function(test) {
TestRun(test)
.test([
"for (let x, y = x; ;) {}",
"for (const x = 0, y = x; ;) {}"
], { esversion: 6 });

test.done();
};

0 comments on commit 404c9a0

Please sign in to comment.