ASTQuery
Use css-like selectors for walking over AST-tree
Example
var ast = esprima.parse('function test(){ var a, b = 0; a = 1; a += 2; b++; b--; };test();');
var astQuery = new ASTQuery(ast, 'es5');
astQuery.on({
print: function(node, message) {
console.log('node type is ' + node.type + ' | ' + message)
}
, ':: FunctionDeclaration': function(node) {
this.print(node, '1| ');
}
, ':: VariableDeclarator': function(node) {
this.print(node, '2| ' + node.id.name);
}
, ':: AssignmentExpression[operator="="]': function(node) {
this.print(node, '3| ' + node.left.name + "|" + node.operator);
}
}, {prefix: '::'});
astQuery.apply();
TODO
- ':other' pseudo-class
- complex selector's support ('tag>tag')
- classes support with API to adding class description
- es6 'query' string template tag (astQuery.query
VariableDeclarator:${function(node){ return node.id.name == 'a' }}
) - 'removeListener'