Socket
Socket
Sign inDemoInstall

@babel/types

Package Overview
Dependencies
3
Maintainers
4
Versions
151
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

@babel/types

Babel Types is a Lodash-esque utility library for AST nodes

    7.23.5
    GitHub
    npm

Version published
Maintainers
4
Weekly downloads
57,381,161
increased by2.36%

Weekly downloads

Package description

What is @babel/types?

The @babel/types package is a part of the Babel compiler ecosystem. It contains methods for building and validating AST (Abstract Syntax Tree) nodes for JavaScript-like languages. It is commonly used for creating and transforming code within Babel plugins.

What are @babel/types's main functionalities?

AST Node Creation

This feature allows the creation of AST nodes. The code sample demonstrates how to create an identifier and a numeric literal using the package.

const t = require('@babel/types');
const identifier = t.identifier('myVariable');
const numericLiteral = t.numericLiteral(123);

AST Node Validation

This feature is used to validate if a node is of a specific type. The code sample checks if a node is an identifier.

const t = require('@babel/types');
const isValid = t.isIdentifier(t.identifier('myVariable'));

AST Node Transformation

This feature allows the transformation of AST nodes. The code sample creates a binary expression node that represents 'a + b'.

const t = require('@babel/types');
const binaryExpression = t.binaryExpression('+', t.identifier('a'), t.identifier('b'));

AST Node Traversal

This feature is not directly provided by @babel/types but is often used in conjunction with it. It involves traversing the AST and updating nodes. The code sample renames an identifier within the AST.

const t = require('@babel/types');
const traverse = require('@babel/traverse').default;
const ast = t.file(t.program([t.expressionStatement(t.identifier('myVariable'))]));
traverse(ast, {
  enter(path) {
    if (t.isIdentifier(path.node)) {
      path.node.name = 'newVariable';
    }
  }
});

Other packages similar to @babel/types

Changelog

Source

v7.23.5 (2023-11-29)

:eyeglasses: Spec Compliance
  • babel-plugin-proposal-decorators
    • #16138 Class binding is in TDZ during decorators initialization (@nicolo-ribaudo)
  • babel-helpers, babel-plugin-proposal-decorators
:bug: Bug Fix
  • babel-traverse, babel-types
  • babel-plugin-transform-classes
  • babel-generator
  • babel-helpers
  • babel-helper-create-class-features-plugin, babel-plugin-transform-class-properties, babel-plugin-transform-typescript
  • babel-generator, babel-plugin-transform-modules-commonjs, babel-plugin-transform-parameters, babel-plugin-transform-typescript, babel-traverse
  • babel-eslint-plugin
:microscope: Output optimization

Readme

Source

@babel/types

Babel Types is a Lodash-esque utility library for AST nodes

See our website @babel/types for more information or the issues associated with this package.

Install

Using npm:

npm install --save-dev @babel/types

or using yarn:

yarn add @babel/types --dev

FAQs

Last updated on 29 Nov 2023

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the 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