![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
@babel/parser
Advanced tools
Package description
The @babel/parser package is a JavaScript parser that allows you to convert ECMAScript 2015+ code into a parse tree. This package is part of the Babel toolchain and is primarily used for transforming JavaScript code. It provides a flexible and extensible framework for parsing modern JavaScript syntax, enabling developers to analyze, understand, and manipulate the code structure.
Parsing JavaScript
This feature allows you to parse JavaScript code into an abstract syntax tree (AST). The code sample demonstrates how to parse a simple piece of JavaScript code, specifying the source type and enabling plugins for JSX and TypeScript support.
const babelParser = require('@babel/parser');
const code = 'let x = 1;';
const ast = babelParser.parse(code, {
sourceType: 'module',
plugins: [
'jsx',
'typescript'
]
});
Using Plugins for Syntax Support
The @babel/parser package supports various plugins to extend its parsing capabilities to include newer JavaScript syntax and experimental features. This example shows how to enable the 'asyncGenerators' and 'classProperties' plugins to parse code using these features.
const astWithPlugins = babelParser.parse(code, {
plugins: [
'asyncGenerators',
'classProperties'
]
});
Acorn is a lightweight, fast JavaScript parser written in JavaScript. It aims to achieve similar goals as @babel/parser, providing an AST for source code. However, Acorn focuses more on speed and a smaller footprint, making it a good choice for environments where these factors are critical.
Esprima is another popular JavaScript parser that supports ECMAScript 3, 5, 2015, 2016, 2017, and 2018 standards. It is used by many tools and frameworks for static analysis and code manipulation. Compared to @babel/parser, Esprima offers a more stable and standardized parsing solution but might not be as flexible in terms of plugin support and experimental syntax.
typescript-estree is a parser that allows you to parse TypeScript code into an ESTree-compatible form. It is part of the TypeScript-ESLint project and is specifically designed for linting TypeScript code. While it shares the goal of parsing code into an AST with @babel/parser, typescript-estree is focused on TypeScript and integrates closely with ESLint for linting purposes.
Changelog
v7.22.6 (2023-07-04)
babel-compat-data
, babel-helper-compilation-targets
, babel-preset-env
babel-plugin-transform-optional-chaining
delete a?.b
in function params (@nicolo-ribaudo)babel-helper-split-export-declaration
, babel-plugin-transform-modules-commonjs
babel-compat-data
, babel-preset-env
babel-helpers
, babel-plugin-proposal-explicit-resource-management
, babel-runtime-corejs3
, babel-runtime
@@asyncDispose
(@nicolo-ribaudo)babel-standalone
stage-2
(@liuxingbaoyu)babel-core
--frozen-intrinsics
(@liuxingbaoyu)babel-helper-create-class-features-plugin
, babel-plugin-transform-classes
babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining
, babel-plugin-transform-class-properties
, babel-plugin-transform-optional-chaining
, babel-plugin-transform-typescript
?.
(@nicolo-ribaudo)babel-plugin-proposal-destructuring-private
, babel-plugin-proposal-do-expressions
, babel-plugin-proposal-pipeline-operator
, babel-plugin-transform-class-properties
, babel-plugin-transform-nullish-coalescing-operator
, babel-plugin-transform-optional-chaining
, babel-plugin-transform-private-property-in-object
, babel-traverse
Readme
A JavaScript parser
See our website @babel/parser for more information or the issues associated with this package.
Using npm:
npm install --save-dev @babel/parser
or using yarn:
yarn add @babel/parser --dev
FAQs
A JavaScript parser
The npm package @babel/parser receives a total of 44,726,979 weekly downloads. As such, @babel/parser popularity was classified as popular.
We found that @babel/parser 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
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.