Babel is a JavaScript compiler.

Babel is a JavaScript compiler.

Learn more about Babel with our getting started guide or check out some videos on the people and concepts behind it.

We're a small group of volunteers that spend their free time maintaining this project, funded by the community. If Babel has benefited you in your work, becoming a contributor or sponsoring might just be a great way to give back!

Is Babel a compiler or transpiler?

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.

原文地址:https://www.cnblogs.com/chucklu/p/14308103.html