Socket
Socket
Sign inDemoInstall

@babel/generator

Package Overview
Dependencies
10
Maintainers
4
Versions
162
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/generator

Turns an AST into code.


Version published
Maintainers
4
Weekly downloads
49,337,853
decreased by-5.37%

Weekly downloads

Package description

What is @babel/generator?

The @babel/generator package is a part of the Babel toolchain that is responsible for generating code from an Abstract Syntax Tree (AST). It takes an AST as input and turns it into code with source maps, if desired. This is particularly useful when you want to transform code using Babel and then generate the transformed code.

What are @babel/generator's main functionalities?

Code Generation from AST

This feature allows you to generate code from an AST. The code sample demonstrates parsing a piece of code into an AST and then generating the code back from the AST.

const { parse } = require('@babel/parser');
const generate = require('@babel/generator').default;
const code = 'let a = 1;';
const ast = parse(code);
const output = generate(ast, {}, code);
console.log(output.code);

Source Map Support

This feature enables the generation of source maps along with the generated code. The code sample shows how to generate a source map for the code that is being generated from an AST.

const { parse } = require('@babel/parser');
const generate = require('@babel/generator').default;
const code = 'let a = 1;';
const ast = parse(code);
const output = generate(ast, { sourceMaps: true }, code);
console.log(output.map);

Other packages similar to @babel/generator

Changelog

Source

v7.18.12 (2022-08-05)

:bug: Bug Fix
  • babel-plugin-transform-react-constant-elements
    • #14828 fix: react-cons-elem should not hoist router comp (@JLHwung)
  • babel-generator
  • babel-plugin-transform-typescript
    • #14827 Fix: do not report global variables as injected binding (@JLHwung)

Readme

Source

@babel/generator

Turns an AST into code.

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

Install

Using npm:

npm install --save-dev @babel/generator

or using yarn:

yarn add @babel/generator --dev

FAQs

Last updated on 05 Aug 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