MCPcopy
hub / github.com/acornjs/acorn

github.com/acornjs/acorn @8.17.0 sqlite

repository ↗ · DeepWiki ↗ · release 8.17.0 ↗
2,524 symbols 5,079 edges 86 files 516 documented · 20%
README

Acorn Logo Acorn

Build Status NPM version CDNJS

A tiny, fast JavaScript parser, written completely in JavaScript.

Community

Acorn is open source software released under an MIT license.

You are welcome to report bugs or create pull requests on github.

Packages

This repository holds three packages:

To build the content of the repository, run npm install.

git clone https://github.com/acornjs/acorn.git
cd acorn
npm install

Plugin developments

Acorn is designed to support plugins which can, within reasonable bounds, redefine the way the parser works. Plugins can add new token types and new tokenizer contexts (if necessary), and extend methods in the parser object. This is not a clean, elegant API—using it requires an understanding of Acorn's internals, and plugins are likely to break whenever those internals are significantly changed. But still, it is possible, in this way, to create parsers for JavaScript dialects without forking all of Acorn. And in principle it is even possible to combine such plugins, so that if you have, for example, a plugin for parsing types and a plugin for parsing JSX-style XML literals, you could load them both and parse code with both JSX tags and types.

A plugin is a function from a parser class to an extended parser class. Plugins can be used by simply applying them to the Parser class (or a version of that already extended by another plugin). But because that gets a little awkward, syntactically, when you are using multiple plugins, the static method Parser.extend can be called with any number of plugin values as arguments to create a Parser class extended by all those plugins. You'll usually want to create such an extended class only once, and then repeatedly call parse on it, to avoid needlessly confusing the JavaScript engine's optimizer.

const {Parser} = require("acorn")

const MyParser = Parser.extend(
  require("acorn-jsx")(),
  require("acorn-bigint")
)
console.log(MyParser.parse("// Some bigint + JSX code"))

Plugins override methods in their new parser class to implement additional functionality. It is recommended for a plugin package to export its plugin function as its default value or, if it takes configuration parameters, to export a constructor function that creates the plugin function.

This is what a trivial plugin, which adds a bit of code to the readToken method, might look like:

module.exports = function noisyReadToken(Parser) {
  return class extends Parser {
    readToken(code) {
      console.log("Reading a token!")
      super.readToken(code)
    }
  }
}

Extension points exported contracts — how you extend this code

NodeTypes (Interface)
* This interface is only used for defining AnyNode. * It exists so that it can be extended by plugins: * *
acorn/src/acorn.d.ts
Found (Interface)
(no doc)
acorn-walk/src/walk.d.ts
Node (Interface)
(no doc)
acorn/src/acorn.d.ts
SourceLocation (Interface)
(no doc)
acorn/src/acorn.d.ts
Position (Interface)
(no doc)
acorn/src/acorn.d.ts
Identifier (Interface)
(no doc)
acorn/src/acorn.d.ts

Core symbols most depended-on inside this repo

finishNode
called by 158
acorn-loose/src/state.js
forEach
called by 136
test/bench/fixtures/angular.js
extend
called by 131
acorn/src/state.js
eat
called by 118
acorn/src/regexp.js
raise
called by 113
acorn/src/regexp.js
invariant
called by 101
test/bench/fixtures/react-dom.js
expect
called by 98
acorn-loose/src/state.js
startNode
called by 79
acorn-loose/src/state.js

Shape

Function 2,346
Interface 85
Method 61
Class 32

Languages

TypeScript100%

Modules by API surface

test/bench/fixtures/ember.js1,142 symbols
test/bench/fixtures/angular.js555 symbols
test/bench/fixtures/react-dom.js345 symbols
test/bench/fixtures/jquery.js102 symbols
test/bench/fixtures/react.js92 symbols
acorn/src/acorn.d.ts90 symbols
acorn/src/regexp.js34 symbols
acorn-loose/src/state.js25 symbols
acorn/src/state.js18 symbols
acorn-walk/src/index.js17 symbols
test/bench/fixtures/backbone.js16 symbols
acorn/src/locutil.js8 symbols

Dependencies from manifests, versioned

@babel/core7.29.0 · 1×
@babel/preset-env7.29.2 · 1×
@eslint/js9.39.2 · 1×
@rollup/plugin-buble1.0.3 · 1×
@unicode/unicode-17.0.01.6.16 · 1×
acorn8.11.0 · 1×
babylon* · 1×
benchtable0.1.0 · 1×
eslint9.39.2 · 1×
eslint-plugin-import2.32.0 · 1×
eslint-plugin-n17.23.1 · 1×
esprima* · 1×

For agents

$ claude mcp add acorn \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact