Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

estree-walker

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

estree-walker

Traverse an ESTree-compliant AST

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24M
decreased by-25.72%
Maintainers
1
Weekly downloads
 
Created

What is estree-walker?

The estree-walker package is a simple utility for walking an ESTree-compliant AST (Abstract Syntax Tree), such as those produced by parsers like Acorn or Esprima. It allows users to traverse the tree and manipulate nodes during the traversal.

What are estree-walker's main functionalities?

Walking an AST

This feature allows you to traverse an AST, performing actions when entering and leaving each node. The 'enter' function is called when a node is entered, and the 'leave' function is called when a node is left during the traversal.

const { walk } = require('estree-walker');

const ast = { /* some AST object */ };

walk(ast, {
  enter(node, parent, prop, index) {
    // Perform actions upon entering a node
  },
  leave(node, parent, prop, index) {
    // Perform actions upon leaving a node
  }
});

Manipulating Nodes

This feature demonstrates how you can manipulate nodes during traversal. In this example, numeric literal values are doubled.

const { walk } = require('estree-walker');

const ast = { /* some AST object */ };

walk(ast, {
  enter(node) {
    if (node.type === 'Literal' && typeof node.value === 'number') {
      node.value *= 2; // Double the number
    }
  }
});

Other packages similar to estree-walker

FAQs

Package last updated on 03 Feb 2020

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