How is the tsc TypeScript compiler compiled?

Viewed 340

The wikipedia page for TypeScript mentions that the compiler itself is written in TypeScript.

How is this possible? TypeScript transcompiles to JavaScript, and JavaScript is typically interpreted by a web browser.

How is the tsc compiler binary generated?

2 Answers

While javascript is typically associated with browsers, it can also work on servers or the command line with Node.js. Typescript's build process is composed of nodejs scripts.

The scripts for the typescript project can be found in their package.json file, found here. The build:compiler script runs this gulpfile, and part of what the gulp file does is run this file. That file executes ./lib/tsc, thus running the typescript compiler that's found in the lib directory, which then compiles the typescript code it was passed in. Note that the result is not a binary, it's a javascript file; the same (or similar) javascript file found at ./lib/tsc

In computer science, bootstrapping is the technique for producing a self-compiling compiler — that is, compiler (or assembler) written in the source programming language that it intends to compile. An initial core version of the compiler (the bootstrap compiler) is generated in a different language (which could be assembly language); successive expanded versions of the compiler are developed using this minimal subset of the language. The problem of compiling a self-compiling compiler has been called the chicken-or-egg problem in compiler design, and bootstrapping is a solution to this problem.

From: https://en.wikipedia.org/wiki/Bootstrapping_(compilers)

Related