Created
April 11, 2012 17:02
-
-
Save jbclements/2360559 to your computer and use it in GitHub Desktop.
Miller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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