Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@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.19.0 (2022-09-05)
babel-parser
babel-helpers
, babel-plugin-proposal-async-generator-functions
, babel-preset-env
, babel-runtime-corejs2
, babel-runtime-corejs3
, babel-runtime
babel-generator
, babel-helpers
, babel-parser
, babel-plugin-proposal-decorators
, babel-plugin-syntax-decorators
, babel-runtime-corejs2
, babel-runtime-corejs3
, babel-runtime
babel-parser
decoratorsBeforeExport
default to false
(@nicolo-ribaudo)babel-generator
, babel-parser
babel-standalone
babel-helper-create-regexp-features-plugin
, babel-helpers
, babel-plugin-proposal-duplicate-named-capturing-groups-regex
, babel-plugin-transform-named-capturing-groups-regex
, babel-standalone
babel-helper-function-name
, babel-helper-wrap-function
, babel-plugin-transform-classes
babel-plugin-transform-typescript
#privateField!
(@liuxingbaoyu)babel-parser
babel-helper-builder-react-jsx
babel-core
@babel/core
functions in config errors (@nicolo-ribaudo)FAQs
Babel Types is a Lodash-esque utility library for AST nodes
The npm package @babel/types receives a total of 29,817,080 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.