DevTools Logo

JavaScript AST Visualizer

JavaScript AST Visualizer

Parse JavaScript into a navigable AST tree locally

JavaScript source

JavaScript only. TypeScript annotations are not supported.

Paste JavaScript source to inspect its AST hierarchy. Set a depth limit for large programs, review node type counts, and copy deterministic recursive JSON. TypeScript syntax is intentionally unsupported and reports a location-aware parser error.

    Examples

    Function count

    Input
    visualizeJavaScriptAst("function foo() { return 1; }").counts
    Output
    { FunctionDeclaration: 1, ... (keys sorted) }

    Every node type is counted once per visit with keys in alphabetical order.

    Depth truncation

    Input
    visualizeJavaScriptAst("const value = { nested: { answer: 42 } }", 1)
    Output
    { tree.children[0].truncated: true, counts.ObjectExpression: undefined }

    At maxDepth 1 the first child truncates and deeper object nodes are never visited.

    About this tool

    JavaScript AST Visualizer parses modules with visualizeJavaScriptAst(source, maxDepth = 20) (alias parseJavaScriptAst): acorn compiles with ecmaVersion latest and sourceType module, then createTree walks every node and array member into an AstTreeNode tree of { type, children, truncated? }.

    Counts tally every visited type and return sorted alphabetically, and json is JSON.stringify(tree, null, 2) — so FunctionDeclaration, VariableDeclaration, and Program counts plus the JSON string are identical across runs for identical input.

    Limits and errors are explicit: non-integer or negative maxDepth throws, nodes at depth >= maxDepth return truncated true without traversing deeper, and acorn failures rethrow as JavaScriptAstError with one-based line and column in the message.

    How to use this tool

    1. Paste JavaScript

      Provide module source — imports and exports parse, TypeScript annotations do not.

    2. Set depth

      Lower maxDepth to collapse deep subtrees into truncated markers.

    3. Read counts

      Use the sorted counts map to spot node density and recursion depth.

    4. Export JSON

      Copy the deterministic JSON tree for snapshots or teaching diagrams.

    Use cases

    Teaching syntax trees

    Show how functions, declarations, and expressions nest in real code.

    Auditing complexity

    Compare node counts across refactors to spot growing branches.

    Debugging parsers

    Pinpoint acorn syntax errors by exact line and column.

    Common mistakes

    Mistake:Pasting TypeScript and expecting a tree.

    Fix:acorn rejects type annotations — strip : string style syntax or transpile first.

    Mistake:Reading truncated subtrees as complete.

    Fix:truncated true means children were cut at maxDepth — raise the limit to see deeper nodes.

    Frequently asked questions

    What does this tool do?

    It runs visualizeJavaScriptAst on module source with acorn, returning a node tree, alphabetically sorted type counts, and a deterministic JSON string.

    How do depth limits and errors work?

    Nodes at depth >= maxDepth return truncated true without deeper visits, non-integer or negative depths throw, and syntax failures rethrow as JavaScriptAstError with one-based line and column.

    Is my code uploaded or stored?

    No. Acorn parsing and tree rendering run fully client-side.

    Why did TypeScript fail, or counts miss a node?

    Acorn rejects type annotations, and truncated subtrees are excluded from counts by design — raise maxDepth to include deeper ObjectExpression style nodes.

    References & standards

    .env Secret Safety Linter

    Validate .env syntax and spot likely leaked credentials or placeholder secrets.

    .htaccess Generator

    Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth

    2D Fluid Dynamics & Particle Physics Sandbox

    A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.

    AI Function Calling Schema Generator

    Generate function calling JSON schemas from TypeScript interfaces

    Algorithm Arena & Data Structure Visualizer

    Interactive arena for algorithms and data structures: eight sorting algorithms racing on one seeded input, six pathfinding algorithms walking generated mazes, and BST, AVL, Red-Black, B-tree, heap and trie operations replayed step by step with rotations highlighted. Every run shows the Big-O table and the phase-highlighted reference implementation in four languages, and compared values can be played as pitch (sonification) through the shared audio engine. Everything runs client-side; inputs never leave the browser.

    Ansible Playbook Generator

    Build an Ansible playbook — hosts, vars, and tasks with modules — as YAML