Skip to content

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

@geandromatos

Description

@geandromatos

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions