Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable leaking into global scope #21

Closed
pigulla opened this issue Aug 16, 2013 · 1 comment
Closed

Variable leaking into global scope #21

pigulla opened this issue Aug 16, 2013 · 1 comment

Comments

@pigulla
Copy link

pigulla commented Aug 16, 2013

Consider the following source:

function a() {
    var x;
    function b() {
        x = 42;
    }
}

When I run escope via this script:

var escope = require("escope"),
    esprima = require("esprima");

var src = require("fs").readFileSync("source.js");

var ast = esprima.parse(src),
    scopes = escope.analyze(ast).scopes;

// dump names of variables in the global scope
console.dir(scopes[0].variables.map(function (variable) {
    return variable.name
}));

I get the following outpout: ["a", "x"]

Interestingly, if I change x = 42 to x() or simply x, it does not appear in the output.

Am I using escope incorrectly or why is x in the global scope?

@Constellation
Copy link
Member

Nice catch! This is bug.
I'll fix it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants