Socket
Socket
Sign inDemoInstall

@babel/types

Package Overview
Dependencies
3
Maintainers
4
Versions
154
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @babel/types

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


Version published
Weekly downloads
58M
increased by1.74%
Maintainers
4
Install size
2.38 MB
Created
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.3 (2023-11-09)

:bug: Bug Fix
  • babel-plugin-transform-typescript
    • #16071 Strip type-only TS namespaces (@colinaaa)
  • babel-generator
  • babel-compat-data, babel-plugin-bugfix-v8-static-class-fields-redefine-readonly, babel-preset-env
  • babel-plugin-transform-object-super
  • babel-helper-module-transforms, babel-plugin-transform-modules-amd, babel-plugin-transform-modules-commonjs, babel-plugin-transform-modules-umd
:memo: Documentation
  • #16044 docs: Update links in @babel/eslint-parser README (@aryehb)
:house: Internal
  • babel-core, babel-preset-env
:running_woman: Performance
:microscope: Output optimization
  • babel-plugin-transform-computed-properties

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 09 Nov 2023

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