Parse JavaScript source code into a syntax tree to power a custom linter or static analysis tool.
Extend the parser with plugins to handle JSX or other JavaScript syntax extensions in a toolchain.
Use acorn-loose to parse JavaScript with syntax errors and still extract useful structure in an editor integration.
Traverse a syntax tree with acorn-walk to find and transform specific code patterns across a codebase.
Acorn is a small, fast JavaScript parser written entirely in JavaScript. A parser reads source code and converts it into a structured data format (called an Abstract Syntax Tree, or AST) that describes the code's structure as a tree of nodes. This is not a tool you use directly as an end user. It is a building block used inside other developer tools. Many JavaScript tools, such as linters, code formatters, bundlers, and compilers, need to understand the structure of JavaScript code before they can do their work. Acorn provides that parsing step. It takes a string of JavaScript source code as input and returns an AST that the calling tool can then analyze or transform. The repository contains three packages. The main acorn package is the strict parser for valid JavaScript. The acorn-loose package is an error-tolerant parser that can still produce a usable output even when the input code has syntax errors. The acorn-walk package provides utilities for traversing the AST that the parser produces. Acorn supports a plugin system that allows developers to extend the parser to understand JavaScript dialects or syntax extensions. For example, community-built plugins exist for JSX (the XML-like syntax used in React) and BigInt literals. Plugins are composed by extending the base Parser class, and multiple plugins can be combined together in a single parser instance. The library is MIT-licensed and is widely used as a dependency inside other open source JavaScript tooling. It has no runtime dependencies of its own and is installed via npm.
← acornjs on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.