Skip to content

Instantly share code, notes, and snippets.

@juanpicado
Created July 29, 2015 05:58
Show Gist options
  • Save juanpicado/9791d43dcf6dffdb27d0 to your computer and use it in GitHub Desktop.
Save juanpicado/9791d43dcf6dffdb27d0 to your computer and use it in GitHub Desktop.
Estraverse example
var fs = require('fs');
var esprima = require('esprima');
var escodegen = require('escodegen');
var estraverse = require('estraverse');
fs.readFile('test_1.js', 'utf8', function(err, contents) {
var ast = esprima.parse(contents);
estraverse.replace(ast, {
enter : function (node, parent) {
if (node.type === 'Property' && node.key.name.indexOf('jota') != -1) {
this.remove();
}
}
});
var code = escodegen.generate(ast);
fs.writeFile('js1.js', code, function (err) {
if (err) return console.log(err);
});
});
var jota = function() {
return {
jota1 : function(){},
jota2 : function(){},
jota3 : function(){},
jota4 : function(){},
jota5 : function(){},
jota6 : function(){}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment