Skip to content

Is it possible to resolve members while visiting nodes? #12

@Divulcan

Description

@Divulcan

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions