You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: translations/en/transformer-handbook.md
+26-10Lines changed: 26 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -172,14 +172,16 @@ We will talk about how to narrow the node to a specific type of node later in th
172
172
### Stages
173
173
174
174
Very similar to Babel -
175
-
Typescript has three primary stages,
176
-
**parse**,
175
+
Typescript however has five stages,
176
+
**parser**,
177
+
_binder_,
178
+
_checker_,
177
179
**transform**,
178
-
**emit**.
180
+
**emitting**.
179
181
180
-
With two extra steps that are exclusive to Typescript,
181
-
**binding** and **checking** (which relate to the _semantics_/type correctness,
182
-
which for the most part we're going to skimp over in this handbook).
182
+
Two steps are exclusive to Typescript,
183
+
_binder_ and _checker_.
184
+
We are going to gloss over _checker_ as it relates to Typescripts type checking specifics.
183
185
184
186
> For a more in-depth understanding of the Typescript compiler internals have a read of [Basarat's handbook](https://basarat.gitbooks.io/typescript/content/docs/compiler/overview.html).
185
187
@@ -196,7 +198,7 @@ project out.
196
198
This is why enums don't work when parsing Typescript with Babel for example,
197
199
it just doesn't have all the information available.
198
200
199
-
#### Parse
201
+
#### Parser
200
202
201
203
The Typescript parser actually has two parts,
202
204
the `scanner`,
@@ -207,9 +209,20 @@ This step will convert source code into an AST.
I definitely recommend reading the [Parser section](https://basarat.gitbooks.io/typescript/content/docs/compiler/parser.html) in the Typescript Handbook.
212
+
The parser takes source code and tries to convert it into an in-memory AST representation which you can work with in the compiler. Also: see [Parser](https://basarat.gitbooks.io/typescript/content/docs/compiler/parser.html).
211
213
212
-
#### Transform
214
+
##### Scanner
215
+
216
+
The scanner is used by the parser to convert a string into tokens in a linear fashion,
217
+
then it's up to a parser to tree-ify them.
218
+
Also: see [Scanner](https://basarat.gitbooks.io/typescript/docs/compiler/scanner.html).
219
+
220
+
#### Binder
221
+
222
+
Creates a symbol map and uses the AST to provide the type system which is important to link references and to be able to know the nodes of imports and exports.
223
+
Also: see [Binder](https://basarat.gitbooks.io/typescript/docs/compiler/binder.htmlhttps://basarat.gitbooks.io/typescript/docs/compiler/binder.html).
224
+
225
+
#### Transforms
213
226
214
227
This is the step we're all here for.
215
228
It allows us,
@@ -230,7 +243,7 @@ but if you need to do some post-compilation transformation,
230
243
or modify types,
231
244
you'll end up wanting to use `after` and `afterDeclarations`.
232
245
233
-
#### Emit
246
+
#### Emitting
234
247
235
248
This stage happens last and is responsible for _emitting_ the final code somewhere.
236
249
Generally this is usually to the file system -
@@ -500,6 +513,9 @@ These methods are useful for modifying a `node` in some form.
500
513
501
514
-`ts.updateXyz(node, ...)` - useful for updating a node (to then return), an example of this is `ts.updateVariableDeclaration()`
502
515
-`ts.updateSourceFileNode(sourceFile, ...)` - useful for updating a source file to then return
516
+
-`ts.setOriginalNode(newNode, parentNode)` - useful for setting a nodes original (parent) node
0 commit comments