Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Apr 24, 2024 via pnpm

estraverse 5.3.0

ECMAScript JS AST traversal functions
Package summary
Share
0
issues
1
license
1
BSD-2-Clause
Package created
9 Oct 2012
Version published
25 Oct 2021
Maintainers
3
Total deps
1
Direct deps
0
License
BSD-2-Clause

Issues

0
This package has no issues

Licenses

BSD 2-Clause "Simplified" License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
place-warranty
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
estraverse@5.3.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of estraverse 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does estraverse do?

Estraverse is a popular JavaScript library used for traversing ECMAScript syntax trees (ASTs). It originates from the esmangle project. This library provides functions for effectively navigating and manipulating ECMAScript ASTs, aiding developers in software tasks like code analysis and transformation.

How do you use estraverse?

Estraverse boasts an intuitive and flexible interface that developers can easily use in their code. A common use case is traversing an AST and acting upon certain node types:

estraverse.traverse(ast, {
    enter: function (node, parent) {
        if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration')
            return estraverse.VisitorOption.Skip;
    },
    leave: function (node, parent) {
        if (node.type == 'VariableDeclarator')
          console.log(node.id.name);
    }
});

In the code block above, the traverse method is used to navigate through the nodes of the AST (represented by ast). The enter function is executed when entering each node, while the leave function is invoked when exiting. By returning the VisitorOption.Skip value in enter when a FunctionExpression or FunctionDeclaration is encountered, the traversal skips over those nodes and their children.

Estraverse also has a replace function for easy tree manipulation:

result = estraverse.replace(tree, {
    enter: function (node) {
        if (node.type === 'Literal')
            return replaced;
    }
});

In this example, all nodes of type Literal are replaced with the value of the replaced variable.

Where are the estraverse docs?

Lastly, comprehensive documentation for Estraverse is available on the wiki page of the project's GitHub repository. Here you can find detailed usage guides and further examples on how to harness the functionality of the library in your projects.