Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

acorn

Package Overview
Dependencies
Maintainers
1
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acorn

ECMAScript parser

  • 0.11.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
120M
decreased by-12.29%
Maintainers
1
Weekly downloads
 
Created

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

FAQs

Package last updated on 17 Dec 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc