The TypeScript parser doesn't directly produce a tree like that, but you can still use its object model to do all sorts of things. We use it in some tools to do syntax transforms for testing purposes, for example. Here's a snippet that you can use to print the syntax tree:

import ts from "typescript";
 
const code = "enum { x = 1 }";
const sc = ts.createSourceFile("x.ts", code, ts.ScriptTarget.Latest, true);

let indent = 0;
function print(node: ts.Node) {
    console.log(new Array(indent + 1).join(" ") + ts.SyntaxKind[node.kind]);
    indent++;
    ts.forEachChild(node, print);
    indent--;
}
 
print(sc);
Answer from Ryan Cavanaugh on Stack Overflow
🌐
Esprima
esprima.org
Esprima
Esprima is a high performance, standard-compliant ECMAScript parser written in ECMAScript (also popularly known as JavaScript).
Online Parsing
Parser produces the (beautiful) syntax tree · // Life, Universe, and Everything var answer = 6 * 7; · Ready · Syntax · Tokens · URL for this code:
Minifiy & Obfuscate
Shorten variable names Remove unreachable branches Remove unused variable definitions Fold (literal) constants Eliminate dead code · Minification reduces the size of the code without affecting its execution. Further compression is achieved by compacting the syntax tree, shortening variable ...
Source Rewrite
Indent with: tab 2 spaces 4 spaces · String literal quotes: single (') double (") automatic
Syntax Validator
Unlike a typical code linter, this syntax validator does not care about coding styles and formatting · If there is a syntax error, place the mouse cursor over the squiggly red line to reveal the detailed error description
🌐
GitHub
github.com › Diullei › esprima-typeScript
GitHub - Diullei/esprima-typeScript: TypeScript parsing infrastructure for multipurpose analysis. Made over Esprima.js · GitHub
TypeScript parsing infrastructure for multipurpose analysis. Made over Esprima.js - Diullei/esprima-typeScript
Author   Diullei
🌐
Devpost
devpost.com › software › esprima-typescript
Esprima-TypeScript | Devpost
May 20, 2014 - This is a parser for TypeScript Language modified by Esprima.js.This has been modified for TypeScript with little changes to Esprima.JS.I have taken help from the already existing Esprima_TypeScript parser available for free usage from GITHUB ...
🌐
npm
npmjs.com › package › @types › esprima
@types/esprima - npm
TypeScript definitions for esprima. Latest version: 4.0.6, last published: 2 years ago. Start using @types/esprima in your project by running `npm i @types/esprima`. There are 33 other projects in the npm registry using @types/esprima.
      » npm install @types/esprima
    
🌐
Esprima
docs.esprima.org › en › latest › getting-started.html
Chapter 1. Getting Started — Esprima master documentation
Important: Esprima can only process JavaScript programs. It does not handle other variations of JavaScript such as Flow, TypeScript, etc.
🌐
GitHub
github.com › jquery › esprima › issues › 1356
TypeScript integration, suggested approach? · Issue #1356 · jquery/esprima
November 1, 2015 - 3+ years ago this fork was created: https://github.com/Diullei/esprima-typeScript, but not maintained. Pretty certain that both esprima and TypeScript have diverged sufficiently to warrant a comple...
Author   SamuelMarks
🌐
GitHub
github.com › microsoft › TypeScript › issues › 4897
Parsing+generating TypeScript? - à la Esprima · Issue #4897 · microsoft/TypeScript
September 21, 2015 - Here's the closest thing I could find: https://github.com/Diullei/esprima-typeScript But it hasn't been maintained for >2 years. I'm using TypeScript for one of my projects, but I need to develop code-generators to make everything flow c...
Author   SamuelMarks
🌐
Esprima
docs.esprima.org › en › latest › syntax-tree-format.html
Appendix A. Syntax Tree Format — Esprima master documentation
Esprima syntax tree format is derived from the original version of Mozilla Parser API, which is then formalized and expanded as the ESTree specification. Note: In the following sections, interfaces are described using the syntax of TypeScript interface.
Find elsewhere
🌐
GitHub
github.com › Diullei › esprima-typeScript › blob › master › demo › validate.html
esprima-typeScript/demo/validate.html at master · Diullei/esprima-typeScript
TypeScript parsing infrastructure for multipurpose analysis. Made over Esprima.js - Diullei/esprima-typeScript
Author   Diullei
🌐
NPM Compare
npm-compare.com › acorn,esprima,typescript
acorn vs typescript vs esprima: Which is Better JavaScript Parsing and Type Checking Libraries?
Esprima is a high-performance, standard-compliant JavaScript parser that also generates an AST, but it is often used for static analysis and linting due to its extensive support for ECMAScript features. TypeScript, on the other hand, is a superset of JavaScript that adds static typing, enabling ...
🌐
npm
npmjs.com › package › esprima
esprima - npm
July 13, 2018 - Esprima (esprima.org, BSD license) is a high performance, standard-compliant ECMAScript parser written in ECMAScript (also popularly known as JavaScript).
      » npm install esprima
    
Published   Jul 13, 2018
Version   4.0.1
Author   Ariya Hidayat
Homepage   http://esprima.org
🌐
PyPI
pypi.org › project › esprima
esprima · PyPI
Esprima (esprima.org, BSD license) is a high performance, standard-compliant ECMAScript parser officially written in ECMAScript (also popularly known as JavaScript) and ported to Python.
      » pip install esprima
    
Published   Aug 24, 2018
Version   4.0.1
🌐
GitHub
github.com › AbhiLegend › esprima-typeScript
GitHub - AbhiLegend/esprima-typeScript: TypeScript parsing infrastructure for multipurpose analysis. Made over Esprima.js
TypeScript parsing infrastructure for multipurpose analysis. Made over Esprima.js - AbhiLegend/esprima-typeScript
Author   AbhiLegend
🌐
LinkedIn
linkedin.com › pulse › discover-magic-code-visualization-unravel-your-files-pablo
Discover the Magic of Code Visualization, Unravel the Complexities of your TypeScript files with JavaScript!
July 30, 2023 - We'll be using a tool called "Esprima" to help us with this process. Esprima is a JavaScript library that can parse our TypeScript code into something called an "Abstract Syntax Tree" or AST. Don't be intimidated by the fancy name.
🌐
Hacker News
news.ycombinator.com › item
Fast ECMAScript Parser – Alternative to Acorn / Esprima | Hacker News
September 26, 2017 - Looked at the parser code - it's well crafted. Works with integers instead of strings wherever possible · The API is dead simple. Produces standard ESTree AST. Should take 10 minutes to port projects from `acorn` and `esprima` to `cherow`
🌐
Analysis-tools
analysis-tools.dev › tool › esprima
Esprima, a linter for Javascript - Rating And 72 Alternatives | Analysis Tools
Ecosystem for structural matching JavaScript and TypeScript code. Offers search tool that understands code structure. Available as CLI tool and Visual Studio Code extension. It helps to search code faster and more accurately making you workflow ...
🌐
Esprima
esprima.org › doc
Esprima Documentation
The documentation is available in the following formats: · Warning: since this version is still being actively development, the documentation is subject to change without notice
🌐
CodeSandbox
codesandbox.io › examples › package › @types › esprima
@types/esprima examples - CodeSandbox
Use this online @types/esprima playground to view and fork @types/esprima example apps and templates on CodeSandbox.
🌐
NPM Compare
npm-compare.com › esprima,typescript
typescript vs esprima: Which is Better JavaScript Parsing and Type Checking Libraries?
June 29, 2024 - Esprima and TypeScript are JavaScript libraries that serve different purposes in the development process. Esprima is a JavaScript parser that helps analyze and understand JavaScript code, while TypeScript is a superset of JavaScript that adds static typing and type checking capabilities.