estools/estraverse

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

geandromatos opened this issue · 1 comments

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

You probably want to use escope for this.