During a reactJS session that I was attending, the presenter used a term transpiler for some code conversion/porting happening. I've always used and heard the terms compiler and interpreter when it comes to converting a language code to a runnable form on a computer system/machine. Transpiler is new to me. How is a transpiler different from a compiler or an interpreter and why it is really needed?
A compiler is a software that converts high-level language to low-level assembly language and we are all quite familiar with its name and work. A transpiler is another software, sometimes called a source-to-source compiler, which converts a high-level language to another high-level language.
A compiler translates the entire source code in a single run. An interpreter translates the entire source code line by line. It consumes less time i.e., it is faster than an interpreter. It consumes much more time than the compiler i.e., it is slower than the compiler.
A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler is a type of translator that takes the source code of a program written in a programming language as its input and produces an equivalent source code in the same or a different programming language.
Compiler - compiles code to a lower level code.
Example:
"Developer code"
-> "Machine code"
PHP
-> C
Java
-> bytecode
Transpiler - compiles code to same level of code/abstraction.
Example:
"Developer code"
-> "Another developer code or version"
JavaScript ES2015+
-> JavaScript ES5
Interpreter - interprets code, not really in the same class/league/context with the two above.
Example: php.exe
index.php
" -> "Results to html
or just like pure index.html
"As is mentioned in this Wiki article, it is a type of compiler which translates source code from one programming language to another programming language. The source code might be in some language no longer used, or doesn't support latest hardware/software advancements, or as per programmer's convenience/favoritism.
A VB6 to VB.NET converter can be thought of as a Transpiler. I might think of COBOL to C# / C++ / Java tool as a transpiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With