liveBook · Manning

Transpilation

As explained in Secrets of the JavaScript Ninja, Third Edition

The transformation of source code from one programming-language syntax or level of abstraction into another while preserving its behavior.

Transpilation rewrites source syntax into another form while aiming to preserve behavior. In JavaScript web builds, it can convert newer syntax into code understood by targeted browsers. section 13.3.2

Babel’s preset-env can use a Browserslist configuration to transform syntax as needed. TypeScript’s target setting instead selects an ECMAScript version; combining an esnext target with Babel allows browser-specific transforms. section 13.3.2

Keep the boundaries and tradeoffs in view:

  • Transpilation changes syntax, not browser APIs. Babel will not make an unsupported API such as ResizeObserver available. section 13.3.2
  • Expanded syntax can increase the bytes sent to users; otherwise modern sites may still ship bloated ES5 output. section 13.3.2
  • Bundlers can transpile newer JavaScript for older runtimes as part of a broader build pipeline that may also compile TypeScript and minify output. section 13.3
"browserslist": "baseline widely available"

A Browserslist query can define the browser target that guides Babel’s syntax transforms. section 13.3.2

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Explains Babel and TypeScript targeting choices, but stops short of tool setup and does not cover API polyfills.
Examples
Uses Browserslist targets, TypeScript’s esnext setting, and ResizeObserver to illustrate targeting and API limits.
What you can do after
Configure browser-targeted syntax transforms with Babel and Browserslist, while checking API compatibility separately.
How it connects
Connects transpilation with Babel, Browserslist, TypeScript, ECMAScript, and bundlers.

Also explained in

Compare how 6 books explain transpilation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.