# Acorn
Acorn is a JavaScript parser written in JavaScript, created by [[Marijn Haverbeke]] and released under the MIT license.
You give it JavaScript source code, it gives you back an abstract syntax tree in the ESTree format. That's the whole job. It does it in about the smallest, fastest package anyone managed to build.
## Why it ended up everywhere
Acorn became infrastructure. If a tool reads, transforms, bundles, or lints your JavaScript, there's a good chance Acorn is somewhere in the stack:
- ESLint uses it, via `espree`, which is built on Acorn
- Rollup uses it directly
- Webpack uses it for module analysis
- Babel's parser started life as a fork of Acorn
The reasons are boring and exactly right: it's small, it's fast, it tracks the ECMAScript spec closely, and it emits a standard tree format so downstream tools don't need custom adapters. Boring infrastructure is the best kind.
## The plugin model
Acorn's parser can be extended by plugins that override parts of the parsing logic. That's how JSX, TypeScript syntax, and proposed-but-not-yet-standard features get parsed without forking the whole project.
## Acorn vs Lezer
Both parse. They solve different problems:
| | Acorn | [[Lezer]] |
|---|---|---|
| Job | Parse a complete file into an AST | Keep a syntax tree in sync while typing |
| Model | Parse once, top to bottom | Incremental, reuses the unchanged tree |
| Broken input | Throws | Produces a usable tree anyway |
| Typical use | Build tools, linters, bundlers | Editors, [[CodeMirror]] |
If you're building a compiler step, reach for Acorn. If you're building an editor, reach for [[Lezer]].
## References
- https://github.com/acornjs/acorn
- https://github.com/estree/estree
## Related
- [[Lezer]]
- [[CodeMirror]]
- [[Marijn Haverbeke]]
- [[Open Source]]