Project: syntax-tree/esast-util-from-estree

Package: esast-util-from-estree@1.3.0

  1. Dependents: 0
  2. esast utility to transform from estree
  1. util 147
  2. utility 143
  3. tree 37
  4. ast 35
  5. javascript 24
  6. estree 9
  7. ecmascript 9
  8. transform 6
  9. esast 5
  10. esast-util 4
  11. recma 3


Build Coverage Downloads Size Sponsors Backers Chat

esast utility to transform from estree.


What is this?

This package applies some transforms to a given estree to make it compatible with unist. It:

When should I use this?

The transform applied by this utility is often optional: estrees can be used in most places where esast can be used, and vice versa. But, if you come from a unist background and want to deal with JavaScript, or want to use unist utilities with JavaScript, this helps a lot.


This package is ESM only. In Node.js (version 14.14+ and 16.0+), install with npm:

npm install esast-util-from-estree

In Deno with esm.sh:

import {fromEstree} from 'https://esm.sh/esast-util-from-estree@1'

In browsers with esm.sh:

<script type="module">
  import {fromEstree} from 'https://esm.sh/esast-util-from-estree@1?bundle'


import {parse} from 'acorn'
import {fromEstree} from 'esast-util-from-estree'

// Make acorn support comments and positional info.
const comments = []
const esast = parse(
  'export function x() { /* Something senseless */ console.log(/(?:)/ + 1n) }',
  {sourceType: 'module', locations: true, onComment: comments}
esast.comments = comments



  type: 'Program',
  body: [
      type: 'ExportNamedDeclaration',
      declaration: [Object],
      specifiers: [],
      source: null,
      position: [Object]
  sourceType: 'module',
  comments: [
      type: 'Block',
      value: ' Something senseless ',
      position: [Object]
  position: {
    start: {line: 1, column: 1, offset: 0},
    end: {line: 1, column: 75, offset: 74}


This package exports the identifier fromEstree. There is no default export.

fromEstree(estree[, options])

Turn an estree into an esast.


esast (UnistNode).


Configuration (TypeScript Type).



This package is fully typed with TypeScript. It exports the additional type Options.


Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.


See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer