benjamn/ast-types — pull request #81 by drslump (2014-12-14 22:36:20+00:00)
Title: [WorkInProgress] NodeVisitor for quick and simple traversals

Derived from the discussion on #80 it seemed clear to me that even if optimising the `PathVisitor` is something to look forward to, some use cases do not even need to perform transformations. For instance, the es6 arrow function transform, needs to check if `this` is somewhere inside the function body. To perform that traversal there is no need to use the fully featured visitor, instead the simple and fast `NodeVisitor` can be used.

Note that there is **no support for context or replacement in this visitor**, it's intended to be used primarily for look ups.

Here are the results from the `test/perf.js` file:
```
PathVisitor took 144ms (name count: 6295)
NodeVisitor took 17ms (name count: 6295)
```

The usage is pretty simple, API compatible with `PathVisitor` but working with plain nodes instead of `NodePath`. Just import the visitor and feed it an actual node:

```js
var NodeVisitor = require('ast-types').NodeVisitor;

NodeVisitor.visit(ast, {
visitIdentifier: function (node) {
console.log(node.type, node.name);
}
});
```

I'll include some unit tests if you give the go ahead to including this :)