Typescript is rapidly gaining momentum. So, today I thought I talk about it a little. Here is an overview of the typescript architecture.
Overall the typescript architecture is:
Let us now discuss each step briefly:
- Parse: It is a traditional recursive descent parser, tweaked a bit to support incremental parsing, that emits an abstract syntax tree (AST). It is a tree that helps in identifying which files are imported in a file.
- Type Checker: The type-checker constructs a symbol table and then performs type analysis of every expression in the file, reporting errors it finds.
- Transform: The transform step is a set of AST to AST transformations that perform various tasks such as, removing type declarations, lowering module and class declarations to ES5, converting async methods to state-machines, etc.
- Print: Actual conversion of TS to JS the most expensive operation of the whole process.
So, what is the point of all this? Actually typescript provides some extension points in which we change the output and make many awesome things.
TypeScript supports the following extension points to alter its output. You can:
- Modify the TypeScript source it sees (CompilerHost.getSourceFile)
- Alter the list of transforms (CustomTransformers). You can read about how to create a custom transform which is the most recommended way to change a typescript program here.
- Intercept the output before it is written (WriteFileCallback)
It is not recommended to alter the source code as this complicates the managing of source maps, and is not supported by TypeScript’s language service plug-in model.
Let me know your thoughts on this. Would you love to have more such articles?