ExpressionMonitor let’s you process expression trees with a manner

Author: Robert Bonay April 18th, 2012

We were talking about Expressions and ExpressionsVisitors earlier. ExpressionVisitors are a robust and encapsulated way to define expression tree processing logic created as a new JavaScript class, ready to be used by other parts of the system or to be subclassed for whatever reasons.

However creating a full-featured visitor class might not always be an appropriate way, for example when we want to do some simple crawling on the tree and don’t want to have an extra class for that. Or want to process/modify a specific tree? Visitors by default must not modify the tree on which they operate, instead must provide a new, modified tree from the original, and leave the original intact…

Enter ExpressionsMonitor to help us! ExpressionMonitor provides you with a way to define tree processing logic in simple functions (you don’t need a class to encapsulate them) plus let’s you monitor and mutate and not just visit the expressions.

To use an ExpressionMonitor you need an expression instance. ExpressionNode defines the monitor function that takes one parameter: and object/instance with specific method names!