Skip to content

Commit 3310969

Browse files
committed
starting on the TypeScript compiler
1 parent 28a29ff commit 3310969

File tree

8 files changed

+72
-9
lines changed

8 files changed

+72
-9
lines changed

GLOSSARY.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Duck Typing
2-
If it walks like a duck and quacks like a duck, its a duck. For TypeScript if it has all the members structurally then it okay for other things (irrespecitive of name) that accept that structure.
2+
If it walks like a duck and quacks like a duck, its a duck. For TypeScript if it has all the members structurally then it okay for other things (irrespecitive of name) that accept that structure.
3+
4+
# OE
5+
Operating Environment. I'd like to use the term Operating System, but that is not necessarily what I mean here. Think Browser,Node.js,WScriptHost etc.

SUMMARY.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* [Async Await](docs/async-await.md)
1717
* [Generators](docs/generators.md)
1818
* [Project](docs/project/project.md)
19-
* [tsconfig.json](docs/project/tsconfig.md)
19+
* [Compilation Context](docs/project/compilation-context.md)
20+
* [tsconfig.json](docs/project/tsconfig.md)
2021
* [Declaration Spaces](docs/project/declarationspaces.md)
2122
* [Modules](docs/project/modules.md)
2223
* [File Module Details](docs/project/external-modules.md)
@@ -29,3 +30,6 @@
2930
* [Type Assertion](docs/types/type-assertion.md)
3031
* [Type Compatability](docs/types/type-compatability.md)
3132
* [JSX](docs/jsx/tsx.md)
33+
* [TypeScript Compiler](docs/compiler/overview.md)
34+
* [Program](docs/compiler/program.md)
35+
* [AST](docs/compiler/ast.md)

docs/compiler/ast.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Node
2+
The basic building block of the Abstract Syntax Tree (AST). In general node represent non-terminals in the language grammar; some terminals are kept in the tree such as identifiers and literals.
3+
4+
## Note on AST description
5+
Two key things make up an AST node definition. Its `SyntaxKind` which identifies it within the AST and its `interface`, the API the node provides when instantiated for the AST.
6+
7+
## SourceFile
8+
9+
* `SyntaxKind.SourceFile`
10+
* `interface SourceFile`.
11+
12+
Each `SourceFile` is a top-level AST node that is contained in the `Program`.

docs/compiler/overview.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Compiler
2+
The typescript compiler source is located under the [`src/compiler`] folder : https://github.com/Microsoft/TypeScript/tree/master/src/compiler
3+
4+
It is split into the follow key parts:
5+
* Scanner (`scanner.ts`)
6+
* Parser (`parser.ts`)
7+
* Binder (`bindder.ts`)
8+
* Checker (`checker.ts`)
9+
* Emitter (`emitter.ts`)
10+
11+
Each of these get their own unique files in the source. These parts will be explained later on in this chapter.
12+
13+
There are a few additional files in the TypeScript compiler that provide utilities to many of these key portions:
14+
15+
## File: Utilities
16+
core.ts : core utilities used by the TypeScript compiler
17+
18+
## File: Key Data Structures
19+
`types.ts` contains key data structures and interfaces uses throughout the compiler. Here is a sampling of a few key ones:
20+
* `SyntaxKind`
21+
The AST node type is identified by the `SyntaxKind` enum.
22+
* `TypeChecker`
23+
This is the interface provided by the TypeChecker.
24+
* `CompilerHost`
25+
This is used by the `Program` to interact with the `System`
26+
27+
## File: System
28+
All interaction of the TypeScript compiler with the operating system goes through a `System` interface. Both the interface and its implementations (`WScript` and `Node`) are defined in `system.ts`. You can think of it as the *Operating Environment* (OE).
29+
30+
## File: Program
31+
The compilation context ([a concept we covered previously](docs/project/compilation-context.md)) is represented within the TypeScript compiler as a `Program`.

docs/compiler/program.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Program
2+
3+
### Usage of `CompilerHost`
4+
Its interaction mechanism with the OE:
5+
6+
`Program` *-uses->* `CompilerHost` *-uses->* `System`
7+
8+
The reason for having a `CompilerHost` as a point of indirection is that it allows it's interface to be more finely tuned for `Program` needs and not bother with OE needs (e.g. the `Program` doesn't care about `fileExists` a function provided by `System`).
9+
10+
There are other users of `System` as well (e.g. tests).
11+
12+
### SourceFile
13+
14+
* `SyntaxKind.SourceFile`
15+
* `interface SourceFile`.
16+
17+
The `program` consists of a bunch of source files. A `sourceFile` is actually a top-level AST node as well (`SyntaxKind.SourceFile`). Instances implement `interface SourceFile`.

docs/compiler/scanner.md

Whitespace-only changes.

docs/project/compilation-context.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Compilation Context
2+
The compilation context is basically just a fancy term for grouping of the files that TypeScript will parse and analyze to determine what is valid and what isn't. Along with the information about which files, the compilation context contains information about *which compiler options*. A great way to define this logical grouping (we also like to use the term *project*) is using a `tsconfig.json` file.

docs/project/tsconfig.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
## Compilation Context
2-
The compilation context is basically just a fancy term for grouping of the files that TypeScript will parse and analyze to determine what is valid and what isn't. A great way to define this logical grouping (we also like to use the term *project*) is using a `tsconfig.json` file.
3-
4-
51
### Basic
62
It is extremely easy to get started with tsconfig.json as the basic file you need is:
73
```json
@@ -32,6 +28,4 @@ Good IDEs come with built in support for on the fly `ts` to `js` compilation. If
3228
* Just run `tsc` and it will look for `tsconfig.json` in the current as well as all parent folders till it finds it.
3329
* Run `tsc -p ./path-to-project-directory`. Of course the path can be a complete or relative to the current directory.
3430

35-
You can even start the TypeScript compiler in *watch* mode using `tsc -w` and it will watch your TypeScript files for changes.
36-
37-
{% include "footer.md" %}
31+
You can even start the TypeScript compiler in *watch* mode using `tsc -w` and it will watch your TypeScript project files for changes.

0 commit comments

Comments
 (0)