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

How to find all the code variables that are at the root and within the scope of functions #108

Open
geandromatos opened this issue Apr 27, 2020 · 1 comment

Comments

@geandromatos
Copy link

estraverse.traverse (ast, {
     enter: function (node, parent) {
         if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration')
             return estraverse.VisitorOption.Skip;
     },
     leave: function (node, parent) {
         if (node.type == 'VariableDeclarator')
           console.log (node.id.name);
     }
});

How do I modify this code to remove all variable declarations from the code, all objects and properties

example:
var b = navigator;
var h = function () {var enabled = navigator.userAgent}
var c = b.appName

how I would like it to look:
b is navigator;
h is a function
enabled is navigator.userAgent
c is b.appname

object b is navigator
property is appName

@michaelficarra
Copy link
Member

You probably want to use escope for this.

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