Socket
Socket
Sign inDemoInstall

estools

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    estools

Provides a set of utility function to traverse, filter and map esprima ASTs


Version published
Maintainers
1
Install size
8.71 kB
Created

Readme

Source

estools Build Status Coverage Status

Estools provides a set of utility functions to traverse, filter and map esprima ASTs.

npm install estools --save

var estools = require('estools')

API

traverse(ast, visitor)

Traverses all tree nodes of an AST and calls visitor functions passing the AST node.

ast is the result of esprima.parse, visitor may be a function or a visitor object.

The visitor object may define the following functions

enter(node, parent)

Called when entering a node. The current node and parent node are passed as parameter

Example

traverse(ast, {
  enter : function(node, parent) {
    console.log(node.type);  // Print the node type to std out
  }
});

leave(node, parent)

Called when leaving a node. The current node and parent node are passed as parameter

Example

traverse(ast, {
  leave : function(node, parent) {
    console.log(node.type);  // Print the node type to std out
  }
});

visit(node, parent, next)

Called after enter and before leave. The current node and a parent node are passed as parameter. Additionally a function next is passed. The visit function is responsible to call next to visit child nodes. To skip child nodes just omit the call to visit.

Example

traverse(ast, {
  visit : function(node, parent, next) {
    next();
  }
});

Example skipping nodes traverse(ast, { visit : function(node, parent, next) { if (node.type != 'FunctionExpression') { // Skip child nodes of function expressions next(); } } });

filter(ast, filterObj)

Filters AST nodes and returns matching AST nodes as a flat list.

map(ast, mappingFunction)

Maps ASTs and nodes to a normalized tree with node having child nodes stored in a nodes field array.

Keywords

FAQs

Last updated on 15 Jul 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc