jrfeenst/esquery — pull request #12 by michaelficarra (2013-10-03 05:38:58+00:00)
Title: use single-pass evaluation model; expose composable interface; use estraverse

There's a couple things happening in this PR.

0. Using a single-pass right-to-left evaluation model, we've guaranteed that collecting all matches for a given query runs in O(n * log n) time.
0. Exposes a `matches` function that takes a node, a list of its ancestors, and a selector, and returns a boolean that represents whether the selector matches the given node in that position in the tree. This part was my main motivation, since I plan to use esquery in this way in another project.
0. Replaces the naive visitor with [Constellation/estraverse](https://github.com/Constellation/estraverse), which knows how to visit each type of node.

There's one downside: I've had to remove arbitrary subjects. I haven't been able to implement that yet. I have an idea for how we can do it, though: after `match` determines it should collect a node, walk up to the real subject(s) by matching ancestors against the appropriate portion of the selector, and collect that instead.