|
1 | 1 | ### Terminology from inside the codebase
|
2 | 2 |
|
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. |
20 | 26 |
|
21 | 27 | ### Type stuff which can be see outside the compilers
|
22 | 28 |
|
| 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 | + |
23 | 45 | - `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
|
24 | 46 |
|
25 | 47 | ```js
|
|
0 commit comments