What is transpilation and how is it different from the compilation?
Compiling is a general term for taking source code written in one language and transforming it into another language. This transformation happens between languages of two different levels of abstractions. Whereas Transpilation is a compilation but between two languages of a similar level of abstraction.
What do I mean by Abstraction?
We write code in human-understandable languages but the computer understands more machine-readable languages.
- If a language is more human-understandable it is called a high-level language.
- If a language is not exactly human-readable and easier for a machine to understand, it is a low-level language.
A high-level language has higher abstraction and a low-level language has lower abstraction.
So the transformation of a language like Java(high-level language and has higher abstraction) to bytecode(low-level language and has lower abstraction) is called Compilation.
Whereas transformation of a language like TypeScript or CoffeeScript(high-level language and has higher abstraction) to Javascript(high-level language and has higher abstraction) is called Transpilation.
Both compilers and transpilers can optimize the code as part of the process.
A famous transpiler for javascript is Babel and a famous compiler for java is Javac.
The difference between transpiler and compiler is in the level of abstraction in the output. Generally, a compiler produces machine-executable code; whereas a transpiler produces another developer artifact.
This concludes today's article on compilation vs transpilation.
If you liked the article or have any suggestions for me please reach out on @aniketxparihar at Twitter! :)