Skip to content

Instantly share code, notes, and snippets.

@danieluhl
Created January 5, 2016 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieluhl/7f6e3988100042029d9c to your computer and use it in GitHub Desktop.
Save danieluhl/7f6e3988100042029d9c to your computer and use it in GitHub Desktop.
module.exports = function(grunt) {
grunt.registerTask('walk-ast', function() {
grunt.log.writeln('walking');
var file = require('file');
var uglify = require('uglify-js');
var result = [];
function walkAST(node) {
if (node instanceof uglify.AST_If) {
if (node.condition) {
result.push(node.condition.start.value);
}
}
}
astRoot = uglify.parse(grunt.file.read('app.js'));
astRoot.walk(new uglify.TreeWalker(walkAST));
grunt.log.writeln(JSON.stringify(result));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment