AST Query Playground
A regular expression finds character sequences; this tool parses ES2020 syntax into ESTree nodes. Query ancestor and descendant structure, inspect source locations and download a selected node as JSON. Source code is never evaluated. Comments are displayed separately as lexical items, not represented as syntax nodes.
Key features
- Parse real ESTree syntax with Acorn in a fixed ES2020 Script/Module profile
- Match node type and one name/value/operator/kind/callee attribute with > direct-child or >> descendant relations
- Distinguish nested functions, identifiers, string Literals and separately captured LineComment/BlockComment items
- Highlight exact source ranges and navigate a bounded node tree
- Copy or download full selected ESTree node JSON with precise syntax/query error positions
How to use
- Choose the nested-function, module or comment example, or paste a local JavaScript file.
- Select the Script or Module parsing goal and keep source within the ES2020 profile.
- Enter a query such as FunctionDeclaration >> ReturnStatement or Literal[value="hello"].
- Run analysis; select a match or tree item to inspect its source range.
- Copy or download selected node JSON and refine the query as needed.
Use cases
- Tell nested returns from a function’s outer return
- Tell whether a word is a comment, string or identifier
- Locate descendants of a named function declaration
- Inspect node relationships beneath a module export
- Study concrete ESTree node JSON during code review or parser learning
Frequently asked questions
Which language versions are supported?
JavaScript ES2020 Script and Module only. TypeScript type syntax, JSX, features newer than ES2020, CSS and Python are not parsed. Invalid code for the selected goal gets an error and source position.
What query syntax is supported?
Use a node type or *, optionally with one [name=value], [value="text"], [operator=+], [kind=const] or [callee=log] filter. > means direct child, >> means descendant at any depth. Multiple filters, OR, full CSS selector syntax and regex queries are unsupported.
Are comments AST nodes?
No. ECMAScript comments are lexical trivia, not syntax tree nodes. Acorn captures them through a comment callback; the explorer places them under the smallest enclosing node only for navigation. Query them as LineComment or BlockComment.
Is the code executed or sent to a server?
No. Parsing and matching stay inside the browser. The tool never evals, imports or invokes user code and never posts it to a server. Only an explicit download saves the selected node.
Why are some results hidden?
Source is capped at 16,000 characters, the AST at 2,500 nodes, and queries at 240 characters and eight terms. The screen previews the first 180 tree items and 80 matches while showing the total match count. Node-limit failures reject the entire result.
Privacy
Pasted or selected source is parsed only in your browser. There is no eval, code execution or server upload. Exported node JSON may include source strings; review it before sharing.
Comments & questions