transpilation
Transpilation is the automatic rewriting of source code into equivalent source code in the same or a closely related language, usually turning newer or extended JavaScript into a version that a target engine can run.
A tool that performs it is called a transpiler, or a source-to-source compiler. It parses the source and then prints new code with the same behavior. In JavaScript, it has two main jobs. One is downleveling, which rewrites syntax from a newer ECMAScript edition into older syntax for engines that predate it. The other is turning a language built on JavaScript, such as TypeScript or JSX, into plain JavaScript.
Babel and esbuild are widely used transpilers, and bundlers such as webpack often run one as a build step. Each takes a target, such as an ECMAScript edition or a list of browsers, and rewrites only the syntax that the target lacks.
Transpilation rewrites syntax only, and the runtime still supplies every built-in. A built-in method that an engine is missing, such as Array.prototype.at(), has to come from a polyfill instead, so each kind of new feature takes its own path:
Example
Say a web app must still run in an embedded browser whose engine predates ES2020, the edition that added optional chaining and nullish coalescing. The app’s source module uses both operators:
theme.mjs
export function getTheme(user) {
return user.settings?.theme ?? "light";
}
Transpiling the module with esbuild for an ES2019 target rewrites both operators:
$ npx esbuild theme.mjs --target=es2019
export function getTheme(user) {
var _a, _b;
return (_b = (_a = user.settings) == null ? void 0 : _a.theme) != null ? _b : "light";
}
The output stores each intermediate value in a temporary variable, so every property is read only once. It then replaces ?. and ?? with loose == null and != null checks, which match both null and undefined.
The export statement stays even with older targets, because esbuild converts ES modules to another module format only when its --format option asks for one. With an ES2020 target, esbuild leaves the function unchanged.
Related Resources
Tutorial
JavaScript vs TypeScript: One Bug, Two Different Results
JavaScript vs TypeScript: see what type labels add, what they cost, and which to pick, with one bug in both and Node 26 running .ts files directly.
For additional information on related topics, take a look at the following resources:
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 21, 2026