# acorn-to-esprima

> Convert acorn tokens to esprima

Latest version **2.0.8** (published 2016-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install acorn-to-esprima
pnpm add acorn-to-esprima
yarn add acorn-to-esprima
bun add acorn-to-esprima
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.8 |
| Published | 2016-01-30 |
| First published | 2015-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Sebastian McKenzie |
| Maintainers | hzoo, sebmck |
| Keywords | acorn, esprima, babel-eslint, babel-jscs, babel |

## Links

- npm: https://www.npmjs.com/package/acorn-to-esprima
- Repository: https://github.com/babel/acorn-to-esprima
- Homepage: https://github.com/babel/acorn-to-esprima#readme
- Issues: https://github.com/babel/acorn-to-esprima/issues
- npm.io page: https://npm.io/package/acorn-to-esprima

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 2.0.8 (latest) — 2016-01-30
- 2.0.7 — 2016-01-30
- 2.0.6 — 2015-12-29
- 2.0.4 — 2015-12-09
- 2.0.3 — 2015-12-09
- 2.0.2 — 2015-12-04
- 2.0.1 — 2015-11-28
- 2.0.0 — 2015-11-26
- 1.0.7 — 2015-11-17
- 1.0.6 — 2015-11-14
- 1.0.5 — 2015-11-01
- 1.0.4 — 2015-09-14
- 1.0.3 — 2015-09-14
- 1.0.2 — 2015-08-31
- 1.0.1 — 2015-08-25

## README

# acorn-to-esprima

Some functions to help transform an acorn/babel ast to esprima format.

Primarily for use in [babel-eslint](https://github.com/babel/babel-eslint), [babel-jscs](https://github.com/jscs-dev/babel-jscs), and [ast explorer](https://github.com/fkling/esprima_ast_explorer)

**There are no dependencies** (the methods were changed to pass in dependencies instead)

The current functions exposed are:

- `function attachComments(ast, comments, tokens)`
  - This modifies the comments passed in.
- `function toTokens(tokens, tt)`
  - `tt` is `require("babel-core").acorn.tokTypes`
  - Converts template string tokens (`convertTemplateType`)
  - filters out comment tokens
  - runs `toToken` over each token
- `function toToken(token, tt)`
  - Sets `token.type`, `token.range`, and `token.value`
- `function toAST(ast, traverse)`
  - `traverse` is `require("babel-core").traverse;`
  - traverses over the ast and makes any necessary changes (usually es6+)
- `function convertComments(comments)`
  - Modifies `comment.type`

How to use:

Check out the parse method of https://github.com/babel/babel-eslint/blob/master/index.js
```js
// example
exports.parse = function (code) {
  var comments = opts.onComment = [];
  var tokens = opts.onToken = [];

  var ast;
  try {
    ast = parse(code, {
        locations: true,
        ranges: true
    });
  } catch (err) { throw err; }

  tokens.pop();
  ast.tokens = acornToEsprima.toTokens(tokens, tt);

  acornToEsprima.convertComments(comments);
  ast.comments = comments;
  acornToEsprima.attachComments(ast, comments, ast.tokens);

  acornToEsprima.toAST(ast, traverse);

  return ast;
}
```

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