Skip to content

Commit 93c8e42

Browse files
committed
Integrate wiki docs
1 parent 722501c commit 93c8e42

File tree

4 files changed

+87
-18
lines changed

4 files changed

+87
-18
lines changed

GLOSSARY.md

+39-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
11
### Terminology from inside the codebase
22

3-
- `Parser` - Takes source code and tries to convert it into an in-memory AST representation which you can work
4-
with in the compiler. Also: [see Parser](https://basarat.gitbooks.io/typescript/docs/compiler/parser.html)
5-
- `Scanner` - Used by the parser to convert a string an chops into tokens in a linear fashion, then it's up to a
6-
parser to tree-ify them. Also: [see Scanner](https://basarat.gitbooks.io/typescript/docs/compiler/scanner.html)
7-
- `Binder` - Creates a symbol map and uses the AST to provide the type system
8-
[See Binder](https://basarat.gitbooks.io/typescript/docs/compiler/binder.html)
9-
- `Checker` - Takes the AST, symbols and does the type checking and inference -
10-
[See Checker](https://basarat.gitbooks.io/typescript/docs/compiler/checker.html)
11-
- `Token` - A set of characters with some kind of semantic meaning, a parser generates a set of tokens
12-
- `AST` - An abstract syntax tree. Basically the in-memory representation of all the identifiers as a tree of
13-
tokens.
14-
- `Node` - An object that lives inside the tree
15-
- `Location` / `Range`
16-
- `Freshness` - When a literal type is first created and not expanded by hitting a mutable location, see [Widening
17-
and Narrowing in TypeScript][wnn].
18-
- `Symbol` - An object that tracks all the places a variable or type is declared
19-
- `Transient Symbol` - A symbol created in the checker, as opposed to in the binder
3+
* **Core TypeScript Compiler**
4+
5+
* **Parser:** Starting from a set of sources, and following the productions of the language grammar, to generate an Abstract Syntax Tree (AST). Also: [see Parser](https://basarat.gitbooks.io/typescript/docs/compiler/parser.html),
6+
7+
* **Binder:** Linking declarations contributing to the same structure using a Symbol (e.g. different declarations of the same interface or module, or a function and a module with the same name). This allows the type system to reason about these named declarations. [See Binder](https://basarat.gitbooks.io/typescript/docs/compiler/binder.html)
8+
* **Type resolver/ Checker:** Resolving types of each construct, checking semantic operations and generate diagnostics as appropriate. [See Checker](https://basarat.gitbooks.io/typescript/docs/compiler/checker.html)
9+
10+
* **Emitter:** Output generated from a set of inputs (.ts and .d.ts) files can be one of: JavaScript (.js), definitions (.d.ts), or source maps (.js.map)
11+
12+
* **Pre-processor:** The "Compilation Context" refers to all files involved in a "program". The context is created by inspecting all files passed in to the compiler on the command line, in order, and then adding any files they may reference directly or indirectly through `import` statements and `/// <reference path=... />` tags.
13+
The result of walking the reference graph is an ordered list of source files, that constitute the program.
14+
When resolving imports, preference is given to ".ts" files over ".d.ts" files to ensure the most up-to-date files are processed.
15+
The compiler does a node-like process to resolve imports by walking up the directory chain to find a source file with a .ts or .d.ts extension matching the requested import.
16+
Failed import resolution does not result in an error, as an ambient module could be already declared.
17+
18+
* **Standalone compiler (tsc):** The batch compilation CLI. Mainly handle reading and writing files for different supported engines (e.g. Node.js)
19+
20+
* **Language Service:** The "Language Service" exposes an additional layer around the core compiler pipeline that are best suiting editor-like applications.
21+
The language service supports the common set of a typical editor operations like statement completions, signature help, code formatting and outlining, colorization, etc... Basic re-factoring like rename, Debugging interface helpers like validating breakpoints as well as TypeScript-specific features like support of incremental compilation (--watch equivalent on the command-line). The language service is designed to efficiently handle scenarios with files changing over time within a long-lived compilation context; in that sense, the language service provides a slightly different perspective about working with programs and source files from that of the other compiler interfaces.
22+
> Please refer to the [[Using the Language Service API]] page for more details.
23+
24+
* **Standalone Server (tsserver):** The `tsserver` wraps the compiler and services layer, and exposes them through a JSON protocol.
25+
> Please refer to the [[Standalone Server (tsserver)]] for more details.
2026
2127
### Type stuff which can be see outside the compilers
2228

29+
* Node: 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.
30+
31+
* SourceFile: The AST of a given source file. A SourceFile is itself a Node; it provides an additional set of interfaces to access the raw text of the file, references in the file, the list of identifiers in the file, and mapping from a position in the file to a line and character numbers.
32+
33+
* Program: A collection of SourceFiles and a set of compilation options that represent a compilation unit. The program is the main entry point to the type system and code generation.
34+
35+
* Symbol: A named declaration. Symbols are created as a result of binding. Symbols connect declaration nodes in the tree to other declarations contributing to the same entity. Symbols are the basic building block of the semantic system.
36+
37+
* `Type`: Types are the other part of the semantic system. Types can be named (e.g. classes and interfaces), or anonymous (e.g. object types).
38+
39+
* Signature``: There are three types of signatures in the language: call, construct and index signatures.
40+
41+
- `Transient Symbol` - A symbol created in the checker, as opposed to in the binder
42+
- `Freshness` - When a literal type is first created and not expanded by hitting a mutable location, see [Widening
43+
and Narrowing in TypeScript][wnn].
44+
2345
- `Expando` - This is [the term](https://developer.mozilla.org/en-US/docs/Glossary/Expando) used to describe taking a JS object and adding new things to it which expands the type's shape
2446

2547
```js

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,53 @@ If you are completely new to the TypeScript codebase, this YouTube video covers
1010

1111
<a href='https://www.youtube.com/watch?v=X8k_4tZ16qU&list=PLYUbsZda9oHu-EiIdekbAzNO0-pUM5Iqj&index=4'><img src="https://user-images.githubusercontent.com/49038/140491214-720ce354-e526-4599-94ec-72cdbecc2b01.png" /></a>
1212

13+
14+
<details>
15+
<summary>If you are really short on time, here is a quick overview of the compilation process.</summary>
16+
17+
The process starts with preprocessing.
18+
The preprocessor figures out what files should be included in the compilation by following references (`/// <reference path=... />` tags, `require` and `import` statements).
19+
20+
The parser then generates AST `Node`s.
21+
These are just an abstract representation of the user input in a tree format.
22+
A `SourceFile` object represents an AST for a given file with some additional information like the file name and source text.
23+
24+
The binder then passes over the AST nodes and generates and binds `Symbol`s.
25+
One `Symbol` is created for each named entity.
26+
There is a subtle distinction but several declaration nodes can name the same entity.
27+
That means that sometimes different `Node`s will have the same `Symbol`, and each `Symbol` keeps track of its declaration `Node`s.
28+
For example, a `class` and a `namespace` with the same name can *merge* and will have the same `Symbol`.
29+
The binder also handles scopes and makes sure that each `Symbol` is created in the correct enclosing scope.
30+
31+
Generating a `SourceFile` (along with its `Symbol`s) is done through calling the `createSourceFile` API.
32+
33+
So far, `Symbol`s represent named entities as seen within a single file, but several declarations can merge multiple files, so the next step is to build a global view of all files in the compilation by building a `Program`.
34+
35+
A `Program` is a collection of `SourceFile`s and a set of `CompilerOptions`.
36+
A `Program` is created by calling the `createProgram` API.
37+
38+
From a `Program` instance a `TypeChecker` can be created.
39+
`TypeChecker` is the core of the TypeScript type system.
40+
It is the part responsible for figuring out relationships between `Symbols` from different files, assigning `Type`s to `Symbol`s, and generating any semantic `Diagnostic`s (i.e. errors).
41+
42+
The first thing a `TypeChecker` will do is to consolidate all the `Symbol`s from different `SourceFile`s into a single view, and build a single Symbol Table by "merging" any common `Symbol`s (e.g. `namespace`s spanning multiple files).
43+
44+
After initializing the original state, the `TypeChecker` is ready to answer any questions about the program.
45+
Such "questions" might be:
46+
* What is the `Symbol` for this `Node`?
47+
* What is the `Type` of this `Symbol`?
48+
* What `Symbol`s are visible in this portion of the AST?
49+
* What are the available `Signature`s for a function declaration?
50+
* What errors should be reported for a file?
51+
52+
The `TypeChecker` computes everything lazily; it only "resolves" the necessary information to answer a question.
53+
The checker will only examine `Node`s/`Symbol`s/`Type`s that contribute to the question at hand and will not attempt to examine additional entities.
54+
55+
An `Emitter` can also be created from a given `Program`.
56+
The `Emitter` is responsible for generating the desired output for a given `SourceFile`; this includes `.js`, `.jsx`, `.d.ts`, and `.js.map` outputs.
57+
58+
</details>
59+
1360
From there, you can start in the [First Steps to Contributing to the TypeScript Repo](https://github.com/microsoft/TypeScript-Compiler-Notes/tree/main/intro#the-typescript-compiler) consult the [Glossary](./GLOSSARY.md) or dive directly into the [`./codebase/`](./codebase) or [`./systems/`](./systems) folders.
1461

1562
## Asking Questions

codebase/src/compiler/scanner.md

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ doesn't do that.
8181
<!-- prettier-ignore-start -->
8282
[0]: ./parser.md
8383
[1]: <src/compiler/scanner.ts - export function createScanner>
84+
[1]: http://abc.com
8485
[2]: <src/compiler/scanner.ts - function setText(>
8586
[3]: GLOSSARY.md#incremental-parsing
8687
[4]: <src/compiler/scanner.ts - function scan(>

codebase/src/services/formatting.md

-1
This file was deleted.

0 commit comments

Comments
 (0)