Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

acorn-node

browserify8.7mApache-2.02.0.1

the acorn javascript parser, preloaded with plugins for syntax parity with recent node versions

acorn, browserify, javascript, parser

readme

acorn-node

Acorn preloaded with plugins for syntax parity with recent Node versions.

It also includes versions of the plugins compiled with Bublé, so they can be run on old Node versions (0.6 and up).

npm travis standard

Install

npm install acorn-node

Usage

var acorn = require('acorn-node')

The API is the same as acorn, but the following syntax features are enabled by default:

  • Bigint syntax 10n
  • Numeric separators syntax 10_000
  • Public and private class instance fields
  • Public and private class static fields
  • Dynamic import()
  • The import.meta property
  • export * as ns from syntax

And the following options have different defaults from acorn, to match Node modules:

  • ecmaVersion: 2019
  • allowHashBang: true
  • allowReturnOutsideFunction: true
var walk = require('acorn-node/walk')

The Acorn syntax tree walker. Comes preconfigured for the syntax plugins if necessary. See the acorn documentation for details.

License

The files in the repo root and the ./test folder are licensed as Apache-2.0.

The files in lib/ are generated from other packages:

changelog

acorn-node change log

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.

2.0.1

  • Fix crash on class methods named static:
    class X {
      static () {}
    }

Thanks @kumavis!

2.0.0

  • Use acorn's builtin dynamic import() parsing. This parses the ImportExpression node type instead of the Import node type from acorn-node 1.x.
  • Reject escape sequences in import.meta.

1.8.2

  • Revert a breaking change in import.meta parsing.

1.8.1

  • Fix crash in compiled private-class-elements code.

1.8.0

  • Upgrade acorn to v7.

    For backwards compatibility, acorn-node still uses the Import node type for dynamic imports, NOT ImportExpression like acorn v7 and estree.

  • Add numeric separator support:
    var a = 10_000_000_000_000_000_000_000_000n;

1.7.0

  • Add class instance fields support:
    class X {
      pub = 1;
      #priv = 2;
    }
  • Add class static fields support:
    class X {
      static pub = 1;
      static #priv = 2;
    }
  • Add export * as ns support when sourceType is 'module':
    export * as ns from './ns.mjs';

1.6.2

  • Allow dynamic import() in scripts.
  • Update minimum dependency versions, fixing a peerDependency warning.
  • Add Node 10 and 11 to CI.

1.6.1

  • Update acorn-dynamic-import to v4.

1.6.0

  • Upgrade acorn to v6.
  • Add bigint support.

1.5.2

  • Upgrade acorn to support optional catch binding in the AST walker.

1.5.1

  • Fix tests on Node <= 0.12.

1.5.0

  • Add tests for async iteration, optional catch binding, import.meta, dynamic import, bigint (currently unsupported).
  • Add import.meta support. (sourceType: 'module' only)
  • Add dynamic import support. (sourceType: 'module' only)
  • Fix optional catch binding support in the walker.

1.4.0

  • Upgrade acorn to 5.6, which supports optional catch bindings and other new syntax features.
  • Set ecmaVersion to 2019 to opt in to optional catch bindings etc.

1.3.0

  • Upgrade acorn to 5.4, which supports object spread and async iteration.
  • Remove acorn5-object-spread plugin.

1.2.0

  • Expose acorn/dist/walk as acorn-node/walk.

1.1.0

  • Enable allowHashBang and allowReturnOutsideFunction by default.

1.0.0

  • Initial release.