🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

estraverse

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

estraverse

ECMAScript JS AST traversal functions

4.2.0
Source
npm
Version published
Weekly downloads
142M
-8.07%
Maintainers
3
Weekly downloads
 
Created

What is estraverse?

The estraverse npm package is a utility for traversing and updating ECMAScript (JavaScript) abstract syntax trees (ASTs). It is commonly used in the development of JavaScript code analysis and transformation tools.

What are estraverse's main functionalities?

Traversing an AST

This feature allows you to traverse an AST, visiting all nodes in a depth-first order. You can perform actions when entering or leaving each node.

const estraverse = require('estraverse');
const ast = { /* some AST object */ };
estraverse.traverse(ast, {
  enter: function (node) {
    console.log('Entering node:', node.type);
  },
  leave: function (node) {
    console.log('Leaving node:', node.type);
  }
});

Updating an AST

This feature allows you to update nodes in an AST during traversal. In this example, it renames identifiers from 'oldName' to 'newName'.

const estraverse = require('estraverse');
const ast = { /* some AST object */ };
estraverse.replace(ast, {
  enter: function (node) {
    if (node.type === 'Identifier' && node.name === 'oldName') {
      node.name = 'newName';
      return node;
    }
  }
});

Other packages similar to estraverse

FAQs

Package last updated on 10 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts