Babel是编译器还是编译器? [英] Is Babel a compiler or transpiler?

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

问题描述

我一直在使用



Babel是 transpiler 还是编译器,或者可能提供这两种选择?或者网站的标题是不正确的?



披露:我知道这听起来像是一个非常迂腐的问题,但我正在编写有关Babel的文档,我想要确保我的描述准确

解决方案

transpiler和compiler的定义很模糊。在保持行为的同时,他们都将翻译一种语言转换为另一种语言。



我们通常在生成可执行二进制文件时将其命名为编译器。但是,二进制只是另一种语言,可以由CPU解释。每个程序在相应的机器上都是可执行的。



我们通常将它命名为编译器,当它产生比输入更低的输出时,例如C到汇编程序。或Java到Java字节码。或者ES8到ES5。等等......这真的是一个不同的水平吗?



当输出与输入相似时,我们通常将其命名为transpiler,例如: Python到JavaScript或其他方式。但是,总会有一些部分使用一种语言的抽象,需要编译到另一种语言的低级实现。



所以要回答你的问题:


我认为编译器与转换器有很大不同。


否。


Babel是一个转换程序还是编译器,或者可能同时提供这两个选项? / p>

是。


或者是网站的title' Babel - 用于编写下一代JavaScript的编译器'只是不正确?


否。该标题侧重于下一代功能,即真正需要编译到更不同的输出的更高级别的抽象。尽管输出仍然是普通的,主要是人类可读的JavaScript。


我正在编写有关Babel的文档,我想确保我的描述是准确的


在这种情况下,我会在官方网站上使用他们自己的术语。如果您想将该工具与其他工具进行比较,请选择您自己的描述。


I've been using Babel for a while now, and I've always been under the impression that Babel was a transpiler for converting my ES6 and ES7 JavaScript into ES5 JavaScript, as I was under the assumption that you could technically treat ES5 and ES6 as two different language.

However, I couldn't help but notice that Babel's website title describes it as a compiler, which I believe is something very different from a transpiler.

Is Babel a transpiler or a compiler, or perhaps offers both options? Or is the website's title simply incorrect?

Disclosure: I know this sounds like a very pedantic question, but I am writing documentation relating to Babel, and I want to ensure my description is accurate

解决方案

The definitions of "transpiler" and "compiler" are blurry. Both of them do translate a program from one language to another language while keeping the behaviour.

We usually name it a "compiler" when it produces an executable binary. However, binary is just another language, which can be interpreted by a CPU. Every program is "executable" on the respective machine.

We usually name it a "compiler" when it produces a lower-level output than the input was, e.g. C to assembler. Or Java to Java bytecode. Or ES8 to ES5. Wait… is that really a different level?

We usually name it a "transpiler" when its output is on a similar level as the input, e.g. Python to JavaScript or the other way round. However, there always will be parts that use an abstraction available in one language that need to be "compiled" to a lower-level implementation in the other language.

So to answer your questions:

I believe a compiler is something very different from a transpiler.

No.

Is Babel a transpiler or a compiler, or perhaps offers both options?

Yes.

Or is the website's title 'Babel - The compiler for writing next generation JavaScript' simply incorrect?

No. That title focuses on next-generation features, i.e. higher-level abstractions that really need to be compiled into a very different output. Even though the output is still ordinary, mostly human-readable, JavaScript.

I am writing documentation relating to Babel, and I want to ensure my description is accurate

In that case, I'd use their own terminology from the official website. If you want to compare the tool to others, choose your own description.

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

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