Socket
Socket
Sign inDemoInstall

acorn

Package Overview
Dependencies
0
Maintainers
1
Versions
132
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    acorn

ECMAScript parser


Version published
Weekly downloads
89M
increased by0.34%
Maintainers
1
Created
Weekly downloads
 

Package description

What is acorn?

Acorn is a fast, small, and standards-compliant JavaScript parser written in ECMAScript. It is used to parse JavaScript code and generate abstract syntax trees (ASTs), which can be analyzed or transformed by other tools. It is commonly used in the development of JavaScript compilers, static analysis tools, and code transformation utilities.

What are acorn's main functionalities?

Parsing JavaScript

This feature allows you to parse a string of JavaScript code into an abstract syntax tree (AST). The 'ecmaVersion' option specifies the ECMAScript version to parse.

const acorn = require('acorn');
const AST = acorn.parse('const x = 1;', { ecmaVersion: 2020 });

Walking the AST

This feature involves traversing the generated AST to visit different types of nodes. The 'acorn-walk' package provides utilities for walking the AST.

const acorn = require('acorn');
const walk = require('acorn-walk');
const AST = acorn.parse('const x = 1;', { ecmaVersion: 2020 });
walk.simple(AST, {
  Literal(node) {
    console.log(`Found a literal: ${node.value}`);
  }
});

Dynamic Import Parsing

This feature allows acorn to handle dynamic imports in the code. The 'acorn-dynamic-import' plugin extends acorn's capabilities to parse dynamic import() expressions.

const acorn = require('acorn');
const dynamicImport = require('acorn-dynamic-import').default;
const parser = acorn.Parser.extend(dynamicImport);
const AST = parser.parse('import("./module.js");', { ecmaVersion: 2020 });

Other packages similar to acorn

Readme

Source

Acorn

A tiny, fast JavaScript parser in JavaScript.

See http://marijnhaverbeke.nl/acorn/

FAQs

Last updated on 14 Feb 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc