Socket
Socket
Sign inDemoInstall

@babel/generator

Package Overview
Dependencies
6
Maintainers
6
Versions
164
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
Weekly downloads
42M
decreased by-17.19%
Maintainers
6
Install size
1.89 MB
Created
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

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 20 Apr 2021

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