Is Babel a compiler or transpiler?

后端 未结 3 1403
悲哀的现实
悲哀的现实 2020-12-09 07:53

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 Jav

3条回答
  •  情歌与酒
    2020-12-09 08:18

    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.

提交回复
热议问题