Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created April 11, 2012 17:02
Show Gist options
  • Save jbclements/2360559 to your computer and use it in GitHub Desktop.
Save jbclements/2360559 to your computer and use it in GitHub Desktop.
Miller
var fs = require("fs");
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
fs.readFile(process.argv[2], "utf8", function(err, data) {
if (err) throw err;
var ast = jsp.parse(data);
var w = pro.ast_walker(), walk = w.walk;
var vars = {};
var _vardef = function(exp, args) {
for (ndx in exp) {
vars[exp[ndx][0]] = true;
}
};
w.with_walkers({
'name': function(exp, args) {
var literals = {
'true' : true,
'false' : true,
'null' : true,
'this' : true
};
if (!literals[exp]) {
vars[exp] = true;
}
},
'var': _vardef,
'const': _vardef
}, function() { return walk(pro.ast_add_scope(ast)); });
for (v in vars) {
console.log(v);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment