This package has been deprecated

Author message:

This package was renamed to 'zecorn'.

escorn
TypeScript icon, indicating that this package has built-in type declarations

0.7.0 • Public • Published

escorn

A babel compatibility layer built on acorn with strong source mapping capabilities. The main focus is to generate a readable output and making it easy to reuse existing babel plugins.

This library was built for WMR, but should be usable outside of that.

Usage

Installation:

npm install -D escorn
# or via yarn
yarn add -D escorn

Transform example:

import { transform, parse } from "escorn";

function MyBabelPlugin({ types: t }) {
  return {
    name: "my-plugin",
    visitor: {
      NumericLiteral(path) {
        path.replaceWith(t.identifier("foobar"));
      },
    },
  };
}

const result = transform(`const a = 42`, {
  parse,
  plugins: [myBabelPlugin],
});

console.log(result.code);
// Logs: `const a = foobar;`

Alternative usage with a custom acorn instance:

import * as acorn from "acorn";
import { transform, acornPlugins } from "escorn";

const parser = acorn.Parser.extend(...acornPlugins);
const parse = (code, opts) =>
  parser.parse({
    ...opts,
    sourceType: "module",
    ecmaVersion: "latest",
  });

const result = transform(`const a = 42`, {
  parse,
  plugins: [],
});

License

MIT, see the license file.

Readme

Keywords

Package Sidebar

Install

npm i escorn

Weekly Downloads

4

Version

0.7.0

License

MIT

Unpacked Size

648 kB

Total Files

130

Last publish

Collaborators

  • marvinhagemeister