Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the angular compiler "compile"?

I was asked that today and was not able to give a proper answer.

Typescript transpiles to JS. Then there is tree shaking, "less" (optional) and what else in the process of making a deployment. But nothing like that (afaik) has anything to do with "compiling". Everything gets bundled and heavily optimized, but it's not actually compiled, right?

There is even an "ahead of time"-compiler, which really does a noticeable job. What do I miss?

Javascript itself is still interpreted, right?

like image 994
codepleb Avatar asked Oct 10 '17 15:10

codepleb


People also ask

Which type of compilation does Angular provide?

Conclusion: You can compile your angular application in two ways: JIT and AOT.

How does Angular compile TypeScript?

Angular CLI first calls Angular built-in compiler written in TypeScript => then calls the TypeScript Transpiler => then calls the Webpack to bundle and store in the dist/ directory. When build is completed, all our app's components, services, modules etc are transpiled to JavaScript .

Is Angular a compiled language?

But angular is a javascript framework but is compiled.

What is compile time and runtime in Angular?

It basically means that you compile your configuration into your app, at the time when you compile and bundle it. If you're using the Angular CLI there's already a preconfigured setup for having such compile-time configuration options. Inside the environments folder you have a environment. ts and environment.


1 Answers

You're presuming compiling means taking the source code and producing machine code, low-level codes, etc. But compiling actually just means taking one source code and turning it into another. So it seems reasonable to say that taking Typescript and producing JavaScript is a form of compiling. It's not dissimilar to what (for example) c# does when its compiled into IL language.

That said, I'd say a better word for this is Transpiling. I'd suggest that the Typescript compiler is better described as a Transpiler.

The difference is subtle and a transpiler can be thought of as a type of compiler; but a (pure)compiled language is (usually) turning a high-level language to a low(er) level language (nearer to machine code), like the C# example. A transpiler turns a high-level language into a similar level (of abstraction) language (also high level).*

The result of the compiled code is typically not a language that you would write yourself. The result of a transpiler is another high-level language. In theory, you could write IL (as an example) but it's really designed to be produced by a compiler and there are no tools or support for doing this, you produce IL by compiling C#/vb.net, only. Whereas Javascript is a usable (and used) programming language in its own right.

*Lots of caveats as the definitions of these words and their usage are pretty vague

like image 161
Liam Avatar answered Sep 28 '22 20:09

Liam