Skip to content

Instantly share code, notes, and snippets.

@fokusferit
Last active January 13, 2017 14:53
Show Gist options
  • Save fokusferit/6b059c8c1688bfc4a556ecd62a14b42c to your computer and use it in GitHub Desktop.
Save fokusferit/6b059c8c1688bfc4a556ecd62a14b42c to your computer and use it in GitHub Desktop.
var estraverse = require('estraverse');
var fs = require('fs');
fs.readFile('./ast.json', 'utf-8', function(err, ast) {
if(err) throw err;
const data = JSON.parse(ast);
estraverse.traverse(data, {
enter: function(node, parent) {
if(node.type === "Literal" && parent.type === "ArrayExpression") {
if(!Number.isInteger(node.value)){
// stop traversal when a Literal is not a number
return estraverse.VisitorOption.Break;
}
}
},
leave: function(node, parent) {
//nothing for now
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment