jshint/jshint — Issue #465: Neither funcscope nor latedef triggered when both violated
Author: isaacto
Created: 2012-02-23 02:37:31+00:00
State: open

Run the following code over jshint:

function f() {
"use strict";
console.log(y);
for (var x = 0; x < 10; ++x) {
var y = x * x;
}
}

The variable y is used in line 3 before defined in line 5, and out of "scope" of the for loop as well. Somehow neither funcscope and latedef catch it, which is clearly incorrect. If the use of y is moved to below the loop, jshint catches funcscope.

The error is triggered on variable definition, so I think perhaps the problem is that the existing usages of variable are not passed into newly defined function. I don't have the time to trace the code though, so I cannot be sure.