Introduction to Transpiling
suggest changeExamples
ES6/ES2015 to ES5 (via Babel):
This ES2015 syntax
// ES2015 arrow function syntax
[1,2,3].map(n => n + 1);
is interpreted and translated to this ES5 syntax:
// Conventional ES5 anonymous function syntax
[1,2,3].map(function(n) {
return n + 1;
});
CoffeeScript to JavaScript (via built-in CoffeeScript compiler):
This CoffeeScript
# Existence:
alert "I knew it!" if elvis?
is interpreted and translated to JavaScript:
if (typeof elvis !== "undefined" && elvis !== null) {
alert("I knew it!");
}
How do I transpile?
Most compile-to-JavaScript languages have a transpiler built-in (like in CoffeeScript or TypeScript). In this case, you may just need to enable the languageās transpiler via config settings or a checkbox. Advanced settings can also be set in relation to the transpiler.
Babel is the usual transpiler from newer ECMAScript syntax to older syntax. It does not polyfill new library features such as Promise or Map. Those still need a separate polyfill.
Why should I transpile?
The most cited benefits include:
- Newer syntax in environments that have not implemented it
- A build step that emits older syntax, which is not the same as supporting every new API
- Languages such as CoffeeScript or TypeScript that compile to JavaScript
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents