esrecurse
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
estraverse | 5.3.0 | 7.86 kB | BSD-2-Clause | prod |
Esrecurse is a JavaScript package, specifically designed for parsing ECMAScript, which provides recursive traversing functionality. It's a powerful tool for navigating and analyzing the abstract syntax tree (AST) of your JavaScript code.
To use esrecurse, you can call the visit
function with your AST and a visitor object that defines methods for the types of nodes you're interested in. For instance, to visit all variables declared at the root of a file, your code would look like this:
esrecurse.visit(ast, {
VariableDeclaration: function (node) {
this.visit(node.init);
// Further operations...
}
});
Alternatively, you can create a Visitor
instance:
var visitor = new esrecurse.Visitor({
VariableDeclaration: function (node) {
this.visit(node.init);
// Further operations...
}
});
visitor.visit(ast);
If you want to customize the Visitor object, esrecurse allows for easy instantiation of Visitor
instances:
class MyVisitor extends esrecurse.Visitor {
constructor()
{
super(null);
}
}
MyVisitor.prototype.VariableDeclaration = function (node) {
this.visit(node.init);
// Further operations...
};
To override the default visiting operation, you can call the visitChildren(node)
function from within your custom visitor methods:
MyVisitor.prototype.VariableDeclaration = function(node) {
this.visitChildren(node);
};
Esrecurse also supports user-defined node types and provides options to handle unknown nodes with the fallback
option. In addition to the standard visit
function, there are also various methods and options for customizing behavior, including user-defined node types and visiting unknown nodes.
Documentation of esrecurse can be found on its GitHub page. Here, you will find all the essential information on how to use the package, options, examples, and so on. For an in-depth exploration of using esrecurse and understanding its features, the source code provides the most detailed insights.