A miniature model of the Typescript compiler, intended to teach the structure of the real Typescript compiler
This project contains two models of the compiler: micro-typescript and centi-typescript.
micro-typescript started when I started reading Modern Compiler Implementation in ML because I wanted to learn more about compiler backends. When I started building the example compiler I found I disagreed with the implementation of nearly everything in the frontend. So I wrote my own, and found that I had just written a small Typescript.
I realised a small Typescript would be useful to others who want to learn how the Typescript compiler works. So I rewrote it in Typescript and added some exercises to let you practise with it. micro-typescript is the smallest compiler I can imagine, implementing just a tiny slice of Typescript: var
declarations, assignments and numeric literals. The only two types are string
and number
.
So that's micro-typescript: a textbook compiler that implements a tiny bit of Typescript in a way that's a tiny bit like the Typescript compiler. centi-typescript, on the other hand, is a 1/100 scale model of the Typescript compiler. It's intended as a reference in code for peopple who want to see how the Typescript compiler actually works, without the clutter caused by real-life compatibility and requirements. Currently centi-typescript is most complete in the checker, because most of Typescript's complexity is there.
git clone https://github.com/sandersn/mini-typescript
cd mini-typescript
code .
# Get set up
npm i
npm run build
# Or have your changes instantly happen
npm run build --watch
# Run the compiler:
npm run mtsc ./tests/singleVar.ts
git checkout centi-typescript
npm run build
let
.
var
and let
the same way. The simplest way is to add a kind
property to Symbol
.let
to var
.Type
will need to become more complicated.interface
.
type
and interface
the same way.let
-> var
.