kangax / jscritic

Quickly check how well 3rd party script behaves.
jscritic.com
118 stars 8 forks source link

More than one inline assignment is not always a leaking variable #22

Open adriengibrat opened 10 years ago

adriengibrat commented 10 years ago

Test case to reproduce this:

(function() {
    var local;
    function a (){
        var value = local = true;
        return value;
    }
    return a;
})();

@see https://github.com/kangax/jscritic/blob/15957a2e2a99607e328d945e9e898a845f76a22e/jscritic.js#L480 The W120 JSHint warning indicate "You might be leaking a variable" I know this would be the proper way to do this (even if "value" variable is useless in this tests case) :

(function() {
    var local;
    function a (){
        var value = true;
        local = value;
        return value;
    }
    return a;
})();

The problem is taht W120 warning is about a "code smell" more than an actual error.

Keeping tracks of variables available in each scope seems not easy to implement, but maybe I'm wrong. I don't see another not hack-ish way to check this.

kangax commented 10 years ago

Yeah, one of those things that's difficult to detect via static analysis (unless JSHint keeps track of entire scope chain properly and we can check that local is on the 1st level not 0th, so to speak)