Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

acorn 8.11.3

ECMAScript parser
Package summary
Share
0
issues
0
licenses
Package created
24 Sep 2012
Version published
29 Dec 2023
Maintainers
3
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does acorn do?

Acorn is a compact, swift JavaScript parser, open-source and available under the MIT license. Its primary function is to analyze ECMAScript code and create an abstract syntax tree (AST), complying with the ESTree specification guidelines. Despite its small size, it's potent enough to parse the latest ECMAScript editions and supports various parsing options, providing the user with a customizable yet powerful tool.

How do you use acorn?

You can install and use acorn as an npm package in your project using the following commands to install the package:

npm install acorn

After installing acorn, you can use it in your code as follows:

let acorn = require("acorn");
console.log(acorn.parse("1 + 1", {ecmaVersion: 2020}));

In the example above, "1 + 1" is a JavaScript expression we're parsing to an AST. The option 'ecmaVersion: 2020' tells acorn to parse the text as per ECMAScript 2020 edition's rules.

Additionally, you can tokenize input strings by leveraging the tokenizer function. Here's a usage example:

for (let token of acorn.tokenizer('1 + 1')) {
  console.log(token);
}

This snippet will display the details of each token identified in the provided string.

Where are the acorn docs?

The documentation for acorn can be found within the source code on the Acorn GitHub repository. The readme file contains details about installation, interface, the parser class, list of available parsing options, command-line interface, plugins information, and more. Although there isn't a separate webpage for 'acorn' documentation, the GitHub repository serves as a comprehensive resource hub for users, with links to bug reports, discussion forums, and related external resources.