Socket
Socket
Sign inDemoInstall

@babel/traverse

Package Overview
Dependencies
31
Maintainers
4
Versions
166
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @babel/traverse

The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes


Version published
Weekly downloads
46M
increased by1.26%
Maintainers
4
Install size
3.97 MB
Created
Weekly downloads
 

Package description

What is @babel/traverse?

The @babel/traverse package is part of the Babel toolchain and is used for traversing and manipulating the abstract syntax tree (AST) generated by Babel. It provides methods to visit nodes in the tree, update them, add or remove nodes, and perform various transformations on the code represented by the AST.

What are @babel/traverse's main functionalities?

Visiting Nodes

This feature allows you to visit specific nodes in the AST. You can specify the types of nodes you're interested in and provide functions that will be called when those nodes are encountered during traversal.

{"type": "Identifier", "name": "a"}

Modifying Nodes

With @babel/traverse, you can modify nodes in the AST. This can include changing node types, adding or removing properties, or even replacing a node with a different one.

{"type": "Identifier", "name": "b"}

Adding and Removing Nodes

This feature allows you to add new nodes to the AST or remove existing ones. This is useful for code transformations where you need to introduce new variables, functions, or other constructs, or clean up unused code.

{"type": "VariableDeclaration", "declarations": [{"type": "VariableDeclarator", "id": {"type": "Identifier", "name": "c"}, "init": {"type": "Literal", "value": 3, "raw": "3"}}], "kind": "const"}

Scope Management

The package provides utilities for managing scope within the AST. This includes tracking variable declarations, bindings, and references, which is crucial for correctly transforming code without introducing errors.

{"type": "BlockStatement", "body": [], "directives": []}

Other packages similar to @babel/traverse

Changelog

Source

v7.17.9 (2022-04-06)

:bug: Bug Fix
  • babel-parser, babel-standalone
    • #14427 Restore numeric separators support in @babel/standalone (@nicolo-ribaudo)
  • babel-traverse
    • #14403 Fix NodePath.referencesImport for JSXMemberExpression (@swandir)
  • babel-plugin-proposal-decorators
  • babel-parser
  • babel-generator, babel-parser
  • babel-plugin-transform-classes, babel-plugin-transform-modules-commonjs, babel-preset-env
  • babel-helper-create-class-features-plugin, babel-plugin-proposal-class-properties
:nail_care: Polish
  • babel-plugin-proposal-decorators
:memo: Documentation
:house: Internal

Readme

Source

@babel/traverse

The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes

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

Install

Using npm:

npm install --save-dev @babel/traverse

or using yarn:

yarn add @babel/traverse --dev

FAQs

Last updated on 06 Apr 2022

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