Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@babel/types
Advanced tools
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.
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';
}
}
});
Acorn is a small, fast, JavaScript-based JavaScript parser. It produces an abstract syntax tree similar to the one produced by @babel/types but does not include the same utilities for building or validating nodes.
Esprima is another JavaScript parser that produces an AST. It is used for static analysis and other code transformation tasks, similar to @babel/types, but it has its own API and does not provide the same helper functions for node creation and validation.
Recast is a JavaScript AST manipulation library that uses Esprima under the hood. It provides a different set of utilities for parsing, transforming, and printing code, and it preserves source formatting, which is different from @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.
Using npm:
npm install --save-dev @babel/types
or using yarn:
yarn add @babel/types --dev
v7.17.0 (2022-02-02)
babel-cli
, babel-core
babel-core
, babel-parser
, babel-traverse
babel-generator
, babel-parser
, babel-plugin-proposal-pipeline-operator
, babel-plugin-syntax-pipeline-operator
babel-traverse
babel-generator
, babel-parser
, babel-plugin-syntax-destructuring-private
, babel-standalone
babel-helper-create-class-features-plugin
, babel-helpers
, babel-plugin-proposal-decorators
, babel-plugin-syntax-decorators
, babel-runtime-corejs2
, babel-runtime-corejs3
, babel-runtime
, babel-standalone
, babel-types
babel-generator
, babel-parser
, babel-traverse
, babel-types
babel-core
, babel-helper-create-regexp-features-plugin
, babel-plugin-proposal-unicode-sets-regex
, babel-plugin-syntax-unicode-sets-regex
, babel-plugin-transform-dotall-regex
babel-parser
babel-register
@babel/register/experimental-worker
(@nicolo-ribaudo)babel-parser
babel-plugin-transform-runtime
babel-helper-fixtures
, babel-parser
babel-compat-data
babel-cli
, babel-core
@ampproject/remapping
to merge source maps (@jridgewell)FAQs
Babel Types is a Lodash-esque utility library for AST nodes
The npm package @babel/types receives a total of 57,580,415 weekly downloads. As such, @babel/types popularity was classified as popular.
We found that @babel/types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.