角度编译器“编译”了什么? [英] What does the angular compiler "compile"?

查看:166
本文介绍了角度编译器“编译”了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我被问到并且无法给出正确答案。

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

Typescript转换为JS。然后是树摇动,少(可选)以及在进行部署的过程中还有什么。但是那些(afaik)与编译无关。一切都被捆绑并大量优化,但它实际上并没有被编译,对吧?

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本身仍然是解释的,对吗?

Javascript itself is still intepreted, right?

推荐答案

您假设编译意味着获取源代码并生成机器代码,低级代码等。但实际上编译只意味着获取一个源代码并将其转换为另一个源代码。所以说使用Typescript和生成JavaScript是编译的形式似乎是合理的。它与编译成IL语言时c#的作用并没有什么不同。

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.

这就是说,我想说的更好的话是 Transpiling 。我建议将Typescript编译器更好描述为一个Transpiler。

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.

差别很小,转换器可以被认为是一种编译器;但是(纯)编译语言(通常)将高级语言转换为低级别语言(更接近机器代码),如C#示例。转换器将高级语言转换为类似的(抽象)语言级别(也是高级别)。 *

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).*

结果编译代码通常不是您自己编写的语言。转换器的结果是另一种高级语言。理论上,您可以编写IL(作为示例),但它实际上是由编译器生成的,并且没有工具或支持来执行此操作,您只通过编译C#/ vb.net来生成IL。而Javascript本身就是一种可用的(和使用过的)编程语言。

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.

*由于这些词的定义及其用法非常模糊,因此很多注意事项

这篇关于角度编译器“编译”了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆