JavaScript AST Explorer (ESTree Tree View)

Shows the abstract syntax tree of a JavaScript snippet as an indented tree with node types, fields and character ranges, or as ESTree JSON. A JSON mode shows any JSON document as a typed tree.

Use the tool

Why this tool exists

To write a codemod, a lint rule or a small parser you need to see which nodes a piece of code becomes. Online AST explorers load large parsers; this one has a compact parser written for ES2022 scripts that produces the same ESTree shape as Acorn.

It supports declarations, functions, arrow functions, async and generator functions, classes with fields, private names and static blocks, destructuring, spread, template and tagged templates, optional chaining, labels, switch, try and for loops including for await, dynamic import and import.meta. It does not parse modules (import and export statements), JSX, TypeScript or unicode escapes in identifiers, and it reports a position when it stops. The tree for 451 library files matched Acorn exactly, including start and end offsets.

How to use it

  1. Paste JavaScript in the box, or switch the language to JSON.
  2. Choose the tree view or ESTree JSON and whether to show [start-end] ranges.
  3. Read each node as Type (range) and its properties; arrays are numbered.
  4. Copy the text to use it in a bug report or a rule description.

Frequently asked questions

Is the output the same as Acorn or Esprima?

It follows the ESTree names used by Acorn. A comparison on 451 files from published libraries gave identical trees and positions. Esprima differs in a few node names.

Why does import or export fail?

The parser handles scripts only. Wrap the code in a function or remove the module syntax first.

Does it keep comments?

No. Comments and white space are skipped like in Acorn without options.

Can it explore CSS or HTML?

Not as an AST. Use the JSON mode for data, and the CSS and HTML tools on this site for their own formats.