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

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

问题描述

我今天被问到这个问题,无法给出正确的答案.

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 interpreted, right?

推荐答案

你假设编译意味着获取源代码并生成机器代码、低级代码等.但编译实际上只是获取一个源代码并转换它变成另一个.所以说采用 Typescript 并生成 JavaScript 是一种形式的编译似乎是合理的.它与(例如)c# 在编译成 IL 语言时所做的事情没有什么不同.

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.

也就是说,我会说一个更好的词是转译.我建议将 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天全站免登陆