esrap
Parse in reverse
Last updated 3 years ago by rich_harris .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install esrap 
SYNC missed versions from official npm registry.

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

Current Tags

  • 2.4.0                                ...           latest (2 months ago)

63 Versions

  • 2.4.0                                ...           2 months ago
  • 2.3.14                                ...           2 months ago
  • 2.3.13                                ...           2 months ago
  • 2.3.12                                ...           2 months ago
  • 2.3.11                                ...           2 months ago
  • 2.3.10                                ...           2 months ago
  • 2.3.9                                ...           2 months ago
  • 2.3.8                                ...           2 months ago
  • 2.3.7                                ...           3 months ago
  • 2.3.6                                ...           3 months ago
  • 2.3.5                                ...           3 months ago
  • 2.3.4                                ...           3 months ago
  • 2.3.3                                ...           3 months ago
  • 2.3.2                                ...           4 months ago
  • 2.3.1                                ...           4 months ago
  • 2.3.0                                ...           4 months ago
  • 2.2.13                                ...           5 months ago
  • 2.2.12                                ...           5 months ago
  • 2.2.11                                ...           6 months ago
  • 2.2.10                                ...           6 months ago
  • 2.2.9                                ...           6 months ago
  • 2.2.8                                ...           7 months ago
  • 2.2.7                                ...           7 months ago
  • 2.2.6                                ...           7 months ago
  • 2.2.5                                ...           8 months ago
  • 2.2.4                                ...           8 months ago
  • 2.2.3                                ...           10 months ago
  • 2.2.2                                ...           10 months ago
  • 2.2.1                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.3                                ...           a year ago
  • 2.1.2                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.4.9                                ...           a year ago
  • 1.4.8                                ...           a year ago
  • 1.4.7                                ...           a year ago
  • 1.4.6                                ...           2 years ago
  • 1.4.5                                ...           2 years ago
  • 1.4.4                                ...           2 years ago
  • 1.4.3                                ...           2 years ago
  • 1.4.2                                ...           2 years ago
  • 1.4.1                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.7                                ...           2 years ago
  • 1.3.6                                ...           2 years ago
  • 1.3.4                                ...           2 years ago
  • 1.3.3                                ...           2 years ago
  • 1.3.2                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.3                                ...           2 years ago
  • 1.2.2                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Total 162
Today 0
This Week 3
This Month 123
Last Day 0
Last Week 1
Last Month 24
Dependencies (2)
Dev Dependencies (5)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE