trigger events based on esquery selectors during a traversal of a SpiderMonkey format AST
npm install esdispatchTrigger events based on esquery selectors during a traversal of a SpiderMonkey format AST.
npm install --save esdispatch
``js`
var counter = 0, dispatcher = new ESDispatcher;
dispatcher.on(
'UpdateExpression[operator="++"] > Identifier[name=i]',
function(node, ancestors) { ++counter; }
);
dispatcher.observe(spidermonkeyAST, function() {
counter; // 4
});
#### new ESDispatcher → ESDispatcher instance
The ESDispatcher constructor takes no arguments.
#### ESDispatcher::addListener(selector, listener) → voidlistener
Invoke whenever esdispatch walks over a node that matchesselector. listener is given two arguments: the node that matched thelistener
selector, and a list containing the ancestors of that node. may alsoenter
be an object containing an and, optionally, a leave function. In thatenter
case, the function will be called in pre-order, and the leaveESDispatcher::on
function will be called in post-order. Aliased as .
#### ESDispatcher::once(selector, listener) → voidselector
Adds a listener that is invoked only the first time matches.
#### ESDispatcher::observe(ast, onFinished) → voidonFinished`, if given, is called with no
Begin a traversal using the given SpiderMonkey AST, triggering any listeners
associated with matching queries.
arguments once the traversal is completed.