-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Hello,
I was playing around with the library (it's great, thank you for sharing), and this caught my attention:
As the parser tracks variable scopes to detect variable redeclarations, it will be possible to expose this information to the consumer.
Given this, I am curious whether it would be reasonable to expose scopes on more nodes. I'm thinking of cases where multiple members can have the same identifier name and resolving the "target" needs to take into account the current scope.
Example:
var x = 5;
if (x == 2) {
console.log('Hello world!')
} else {
var x = 7;
console.log(x)
}
Another example:
function foo() {
console.log('Hello World 1');
}
function foo() {
console.log('Hello World 2');
}
foo();
Another (slightly more cursed) example:
var x = "a";
switch(x) {
case "a":
case 2:
var x = 1;
case 3:
console.log(x);
break;
}
SWC uses a numeric ctxt field to denote the scope a node belongs to, however, as far as I know, neither esprima nor acorn expose this information so... Is adding some sort of scope indicator something that is being considered or planned?
Thank you!