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
Install size
2.36 MB

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.22.0 (2023-05-26)

:rocket: New Feature
  • babel-parser, babel-plugin-transform-typescript
    • #15497 [ts] Support import ... = and export = in scripts (@nicolo-ribaudo)
  • babel-compat-data, babel-core, babel-plugin-proposal-unicode-sets-regex, babel-plugin-transform-unicode-sets-regex, babel-preset-env, babel-standalone
  • babel-helpers, babel-plugin-proposal-explicit-resource-management, babel-plugin-transform-runtime, babel-runtime-corejs2, babel-runtime-corejs3, babel-runtime, babel-standalone
  • babel-plugin-proposal-import-attributes-to-assertions
  • babel-core, babel-generator, babel-parser, babel-plugin-syntax-import-attributes, babel-preset-env, babel-standalone, babel-types
  • babel-generator, babel-parser, babel-traverse, babel-types
  • babel-core, babel-helper-create-regexp-features-plugin, babel-parser
  • babel-helpers, babel-plugin-proposal-decorators, babel-plugin-syntax-decorators, babel-runtime-corejs2, babel-runtime-corejs3, babel-runtime
:nail_care: Polish
  • babel-plugin-transform-react-constant-elements, babel-plugin-transform-react-jsx, babel-traverse, babel-types
:house: Internal
  • babel-parser
  • babel-compat-data, babel-helper-transform-fixture-test-runner, babel-node, babel-plugin-proposal-decorators, babel-plugin-proposal-duplicate-named-capturing-groups-regex, babel-plugin-transform-async-generator-functions, babel-plugin-transform-named-capturing-groups-regex, babel-plugin-transform-runtime, babel-preset-env, babel-runtime-corejs3
  • babel-core, babel-plugin-proposal-async-generator-functions, babel-plugin-proposal-class-properties, babel-plugin-proposal-class-static-block, babel-plugin-proposal-decorators, babel-plugin-proposal-dynamic-import, babel-plugin-proposal-export-namespace-from, babel-plugin-proposal-function-sent, babel-plugin-proposal-json-strings, babel-plugin-proposal-logical-assignment-operators, babel-plugin-proposal-nullish-coalescing-operator, babel-plugin-proposal-numeric-separator, babel-plugin-proposal-object-rest-spread, babel-plugin-proposal-optional-catch-binding, babel-plugin-proposal-optional-chaining, babel-plugin-proposal-pipeline-operator, babel-plugin-proposal-private-methods, babel-plugin-proposal-private-property-in-object, babel-plugin-proposal-unicode-property-regex, babel-preset-env, babel-standalone




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 26 May 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