Created
July 29, 2015 05:58
-
-
Save juanpicado/9791d43dcf6dffdb27d0 to your computer and use it in GitHub Desktop.
Estraverse example
This file contains 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 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); | |
}); | |
}); |
This file contains 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 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