Socket
Socket
Sign inDemoInstall

esrap

Package Overview
Dependencies
2
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    esrap

Parse in reverse


Version published
Maintainers
1
Install size
108 kB
Created

Changelog

Source

1.2.2

  • Correctly handle arrow functions where body includes an object expression (#9)

Readme

Source

esrap

Parse in reverse. AST goes in, code comes out.

Usage

import { print } from 'esrap';

const { code, map } = print({
  type: 'Program',
  body: [
    {
      type: 'ExpressionStatement',
      expression: {
        callee: {
          type: 'Identifier',
          name: 'alert'
        },
        arguments: [
          {
            type: 'Literal',
            value: 'hello world!'
          }
        ]
      }
    }
  ]
});

console.log(code); // alert('hello world!');

If the nodes of the input AST have loc properties (e.g. the AST was generated with acorn with the locations option set), sourcemap mappings will be created.

Options

You can pass information that will be added to the resulting sourcemap (note that the AST is assumed to come from a single file):

const { code, map } = print(ast, {
  sourceMapSource: 'input.js',
  sourceMapContent: fs.readFileSync('input.js', 'utf-8')
});

Why not just use Prettier?

Because it's ginormous.

Developing

This repo uses Bun. Once it's installed, do bun install to install dependencies, and bun test to run the tests.

License

MIT

FAQs

Last updated on 30 Apr 2024

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