Created
April 11, 2012 16:50
-
-
Save jbclements/2360480 to your computer and use it in GitHub Desktop.
Weng
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 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