Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are typescript transform

I just read an article on official blog angular 5 (https://blog.angular.io/version-5-0-0-of-angular-now-available-37e414935ced). There is talk of typescript transform. In detail:

"TypeScript Transforms Under the hood, the Angular compiler now operates as a TypeScript transform, making incremental rebuilds dramatically faster. TypeScript transforms were a new feature introduced as part of TypeScript 2.3 that allows us to hook into the standard TypeScript compilation pipeline."

I would like to understand better it. Tranforms or compilation pipeline, what are? tnx!

like image 481
feof84 Avatar asked Nov 08 '17 07:11

feof84


People also ask

What TSC does TypeScript?

Tsc stands for `TypeScript compiler` and is a simple tool included in Typescript itself, allowing you to compile any ts files into js.

How is TypeScript converted to JavaScript?

TypeScript Code is converted into Plain JavaScript Code: TypeScript code can't be natively interpreted by browsers. So if the code was written in TypeScript, it gets compiled and converted into JavaScript. This process is known as Trans-piled.

Can I mix TypeScript and JavaScript?

The TypeScript compiler supports a mix of JavaScript and TypeScript files if we use the compiler option --allowJs : TypeScript files are compiled. JavaScript files are simply copied over to the output directory (after a few simple type checks).

Why do we need types in TypeScript?

Types for ToolingTypeScript can catch bugs when we make mistakes in our code. That's great, but TypeScript can also prevent us from making those mistakes in the first place. The type-checker has information to check things like whether we're accessing the right properties on variables and other properties.


1 Answers

This referes to the internals of how the typescript compiler generates Javascript code. Since 2.3 the compiler takes the Typescript AST (abstract syntax tree) and applies a series of transformations (the transformation pipeline). At the end of the pipeline you get a new AST that is a Javascript AST.

From the source code, these are the current transformers:

Typescript Transformers

So for example when compiling for a es5 target with jsx enabled and system modules the following transforms will be included:

  • transformTypeScript - Will remove typescript specific annotations

  • transformJsx - Will remove jsx syntax and transform it to Javascript

  • transformESNext - Will transform esnext to es2017

  • transformES2017 - Will transform es2017 to es2016

  • transformES2016 - Will transform es2016 to es2015

  • transformES2015 - Will transform es2015 to es5 (minus generators)

  • transformGenerators - Will transform es2015 generators to es5

  • transformSystemModule - Will add module specific js code.

After all the transformations are applied, writing the AST to a file is a trivial operation.

like image 65
Titian Cernicova-Dragomir Avatar answered Sep 28 '22 00:09

Titian Cernicova-Dragomir