Is Babel a compiler or transpiler?

Viewed 19049

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.

Babel website title - 'Babel - The compiler for writing next generation JavaScript

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

3 Answers

Babel is a transpiler, which is a special type of compiler, so both terms are techincally correct. You may use either at your preference.

It's irrefutable that Babel is a source-to-source compiler (aka transpiler) since its source and target languages are both some flavor of JavaScript:

A source-to-source compiler, transcompiler or transpiler is a type of compiler that takes the source code of a program written in one programming language as its input and produces the equivalent source code in another programming language.

However, not everyone agrees that the distinction between the terms is helpful, so some people prefer simply, "compiler".

I personally like the distinction because, to me, it implies something about the difference in level of abstraction from machine langauge between the source (input) and target (output) languages. That is, typical "compilers" translate from higher-to-lower level languages, "decompilers" translate from lower-to-higher level languages, and "transpilers" translate between languages at similar levels of abstraction.

Related