Sign inDemoInstall


Package Overview
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies



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

Version published
Weekly downloads
increased by4.04%
Bundle size
42.1 kB
Minified + gzipped

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)) { = 'newVariable';

Other packages similar to @babel/types



v7.23.0 (2023-09-25)

:rocket: New Feature
  • babel-plugin-proposal-import-wasm-source, babel-plugin-syntax-import-source, babel-plugin-transform-dynamic-import
    • #15870 Support transforming import source for wasm (@nicolo-ribaudo)
  • babel-helper-module-transforms, babel-helpers, babel-plugin-proposal-import-defer, babel-plugin-syntax-import-defer, babel-plugin-transform-modules-commonjs, babel-runtime-corejs2, babel-runtime-corejs3, babel-runtime, babel-standalone
  • babel-generator, babel-parser, babel-types
  • babel-generator, babel-helper-module-transforms, babel-parser, babel-plugin-transform-dynamic-import, babel-plugin-transform-modules-amd, babel-plugin-transform-modules-commonjs, babel-plugin-transform-modules-systemjs, babel-traverse, babel-types
  • babel-standalone
    • #15671 Pass through nonce to the transformed script element (@JLHwung)
  • babel-helper-function-name, babel-helper-member-expression-to-functions, babel-helpers, babel-parser, babel-plugin-proposal-destructuring-private, babel-plugin-proposal-optional-chaining-assign, babel-plugin-syntax-optional-chaining-assign, babel-plugin-transform-destructuring, babel-plugin-transform-optional-chaining, babel-runtime-corejs2, babel-runtime-corejs3, babel-runtime, babel-standalone, babel-types
  • babel-helpers, babel-plugin-proposal-decorators
  • babel-traverse, babel-types
  • babel-preset-typescript
  • babel-parser
:bug: Bug Fix
  • babel-plugin-transform-block-scoping
    • #15962 fix: transform-block-scoping captures the variables of the method in the loop (@liuxingbaoyu)
:nail_care: Polish
  • babel-traverse
  • babel-plugin-proposal-explicit-resource-management
:microscope: Output optimization
  • babel-core, babel-helper-module-transforms, babel-plugin-transform-async-to-generator, babel-plugin-transform-classes, babel-plugin-transform-dynamic-import, babel-plugin-transform-function-name, babel-plugin-transform-modules-amd, babel-plugin-transform-modules-commonjs, babel-plugin-transform-modules-umd, babel-plugin-transform-parameters, babel-plugin-transform-react-constant-elements, babel-plugin-transform-react-inline-elements, babel-plugin-transform-runtime, babel-plugin-transform-typescript, babel-preset-env




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.


Using npm:

npm install --save-dev @babel/types

or using yarn:

yarn add @babel/types --dev


Last updated on 25 Sep 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.


Related posts

SocketSocket SOC 2 Logo


  • 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