# escorn

> Acorn transpiler with a babel compat layer

Latest version **0.7.0** (published 2021-09-16) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install escorn
pnpm add escorn
yarn add escorn
bun add escorn
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.7.0 |
| Published | 2021-09-16 |
| First published | 2021-07-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 10 |
| Unpacked size | 633.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | The Preact Team |
| Maintainers | marvinhagemeister |
| Keywords | acorn, babel, transpiler |

## Links

- npm: https://www.npmjs.com/package/escorn
- npm.io page: https://npm.io/package/escorn

## Dependencies (10)

- [glob](https://npm.io/package/glob.md) ^7.1.7
- [acorn](https://npm.io/package/acorn.md) ^8.4.1
- [astring](https://npm.io/package/astring.md) ^1.7.5
- [acorn-jsx](https://npm.io/package/acorn-jsx.md) ^5.3.2
- [sourcemap-codec](https://npm.io/package/sourcemap-codec.md) ^1.4.8
- [acorn-class-fields](https://npm.io/package/acorn-class-fields.md) ^1.0.0
- [acorn-private-methods](https://npm.io/package/acorn-private-methods.md) ^1.0.0
- [acorn-import-assertions](https://npm.io/package/acorn-import-assertions.md) ^1.7.5
- [acorn-logical-assignment](https://npm.io/package/acorn-logical-assignment.md) ^0.1.4
- [acorn-static-class-features](https://npm.io/package/acorn-static-class-features.md) ^1.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.7.0 (latest) — 2021-09-16
- 0.6.3 — 2021-09-16
- 0.6.2 — 2021-09-15
- 0.6.1 — 2021-09-14
- 0.6.0 — 2021-09-14
- 0.5.1 — 2021-08-10
- 0.5.0 — 2021-07-23
- 0.4.1 — 2021-07-18
- 0.4.0 — 2021-07-18
- 0.3.0 — 2021-07-18
- 0.2.0 — 2021-07-18
- 0.1.0 — 2021-07-18

## README

# escorn

A babel compatibility layer built on [acorn](https://github.com/acornjs/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](https://wmr.dev/), but should be usable outside of that.

## Usage

Installation:

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

Transform example:

```js
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:

```js
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](./LICENSE).

---
_Source: https://npm.io/package/escorn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
