Socket
Socket
Sign inDemoInstall

@types/estraverse

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/estraverse

TypeScript definitions for estraverse


Version published
Maintainers
1
Created

What is @types/estraverse?

@types/estraverse provides TypeScript type definitions for the estraverse library, which is a tool for ECMAScript/JavaScript syntax tree traversal. It allows developers to walk through and manipulate the abstract syntax tree (AST) of JavaScript code.

What are @types/estraverse's main functionalities?

Traversing the AST

This feature allows you to traverse the AST of JavaScript code. The `enter` and `leave` methods are called when entering and leaving each node in the AST, respectively.

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

Replacing nodes in the AST

This feature allows you to replace nodes in the AST. In this example, all identifiers with the name 'oldName' are replaced with 'newName'.

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

Custom node visitor keys

This feature allows you to define custom visitor keys for traversing non-standard AST nodes. In this example, a custom node type 'CustomNode' with a child node 'childNode' is defined.

const estraverse = require('estraverse');
const ast = { /* some AST */ };
const visitorKeys = {
  CustomNode: ['childNode']
};
estraverse.traverse(ast, {
  enter: function (node) {
    console.log('Entering node:', node.type);
  }
}, visitorKeys);

Other packages similar to @types/estraverse

FAQs

Package last updated on 22 Nov 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc