Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created April 11, 2012 17:03
Show Gist options
  • Save jbclements/2360565 to your computer and use it in GitHub Desktop.
Save jbclements/2360565 to your computer and use it in GitHub Desktop.
Manii
var fs = require("fs");
var uglify = require("uglify-js"),
jsp = uglify.parser,
pro = uglify.uglify;
var code = fs.readFileSync(process.argv[2], "utf8");
var ast = jsp.parse(code);
var varList = new Array();
const literals = ["null", "true", "false", "this"];
var w = pro.ast_walker();
ast = w.with_walkers({
"name": function(name) {
function addVar (varN) {
if(literals.indexOf(varN) == -1
&& varList.indexOf(varN) == -1)
varList.push(varN);}
if(typeof name == "object")
addVar(name[0]);
else
addVar(name);
return [ this[0], name ];
}
}, function(){
return w.walk(ast);
});
for(var i = 0; i < varList.length; i++)
{
console.log(varList[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment