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

ast-types

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-types

Esprima-compatible implementation of the Mozilla JS Parser API

  • 0.8.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19M
decreased by-12.76%
Maintainers
1
Weekly downloads
 
Created

What is ast-types?

The ast-types npm package is designed to define and manipulate ASTs (Abstract Syntax Trees) efficiently. It provides a flexible way to inspect, transform, and generate code from ASTs, which is particularly useful in the context of building compilers, code analysis tools, and code transformers.

What are ast-types's main functionalities?

Defining AST node types

This feature allows users to define various types of AST nodes. The code sample shows how to define an 'Identifier' and a 'BinaryExpression' node, specifying their structure and inheritance.

const def = require('ast-types').Type.def;
def('Identifier')
  .bases('Node')
  .build('name');
def('BinaryExpression')
  .bases('Expression')
  .build('operator', 'left', 'right');

Building AST nodes

This feature enables the construction of AST nodes using predefined builders. The code sample demonstrates creating a binary expression that adds two literals.

const builders = require('ast-types').builders;
const b = builders;
const ast = b.binaryExpression('+', b.literal(1), b.literal(2));

Visiting AST nodes

This feature provides a mechanism to traverse and manipulate nodes in an AST. The code sample illustrates how to visit all identifier nodes in an AST and log their names.

const visit = require('ast-types').visit;
const ast = require('./some-ast');
visit(ast, {
  visitIdentifier(path) {
    console.log('Found an identifier:', path.node.name);
    this.traverse(path);
  }
});

Other packages similar to ast-types

Keywords

FAQs

Package last updated on 21 Aug 2015

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