You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
557 B
JavaScript
18 lines
557 B
JavaScript
/* Simple AST node visitor builder. */
|
|
var visitor = {
|
|
/*
|
|
* Builds a node visitor -- a function which takes a node and any number of
|
|
* other parameters, calls an appropriate function according to the node type,
|
|
* passes it all its parameters and returns its value. The functions for
|
|
* various node types are passed in a parameter to |buildNodeVisitor| as a
|
|
* hash.
|
|
*/
|
|
buildNodeVisitor: function(functions) {
|
|
return function(node) {
|
|
return functions[node.type].apply(null, arguments);
|
|
};
|
|
}
|
|
};
|
|
|
|
module.exports = visitor;
|