Developer and Text Tools

How Babel Transpiles JSX, TypeScript and Modern JavaScript

What a JavaScript transpiler does, how preset-env targets work, and how to compile JSX and TypeScript to older browsers in your browser with source maps.

Saizul Amin
Saizul Amin7 Nov 2026 · 4 min read
How Babel Transpiles JSX, TypeScript and Modern JavaScript

Modern JavaScript is pleasant to write: arrow functions, template literals, optional chaining and JSX all make code shorter and clearer. Not every browser your users run understands all of it, though, and no browser understands TypeScript types or JSX directly. A transpiler sits in between and rewrites new syntax into older syntax that does the same thing. Babel is the most widely used one.

What transpiling means

A transpiler reads source code, builds a tree of it, changes that tree and prints new code. Babel does this with plugins, each responsible for one feature. An arrow function becomes an ordinary function expression. A template literal becomes string concatenation. The exponent operator becomes a Math.pow call. Optional chaining becomes an explicit check that the value is not null or undefined before reading a property.

Presets are bundles of plugins. preset-react compiles JSX tags into function calls such as React.createElement, or into imports from react/jsx-runtime with the newer automatic runtime. preset-typescript removes type annotations, interfaces and type-only imports and compiles enums into plain objects. preset-env is the clever one: you tell it which browsers you support, and it applies only the transforms those browsers need.

Targets decide the output

preset-env reads a Browserslist query. defaults gives sensible output for public websites. A query such as chrome >= 80, safari >= 14 keeps most modern syntax because those browsers already understand it. ie 11 turns on almost everything, since Internet Explorer stopped at ES5. Changing the targets and watching the output change is the quickest way to understand what each transform does.

Trying it without a build setup

Setting up a bundler just to see what Babel does with a snippet is overkill. The free Babel JavaScript Transpiler runs it in the browser. Press the load button and the official @babel/standalone package, pinned to a specific version and about 3.2 MB, is downloaded once from jsDelivr. From then on every edit is compiled within a moment, with your source on the left and the output on the right.

You choose the targets, switch JSX and TypeScript on or off, pick the JSX runtime and pragma, keep ES modules or convert them to CommonJS, minify, drop comments and generate a source map, either as a separate file or inlined. Errors come back with a line and column. The exact options are shown and can be downloaded as a babel.config.json, so the same result can be reproduced in a real project.

A built-in engine for offline use

Before Babel is loaded, or when you are offline, a small built-in engine handles the everyday cases: JSX, common TypeScript annotations, interfaces, type aliases, enums, generics, arrow functions, template literals, let and const, shorthand object members, exponent, nullish coalescing and optional chaining. Load the modern JavaScript sample at ES5 and you can watch it turn r ** 2 into Math.pow(r, 2), turn user?.address?.city ?? "unknown" into a chain of null checks with a fallback, and expand shorthand properties and methods.

The engine is honest about its limits. Anything it does not transform, such as classes, async functions, destructuring, spread or modules, is listed with its line number and left as written, with a suggestion to load Babel for those.

Syntax is not the whole story

A transpiler changes syntax, not the runtime. If your code calls Promise, fetch, Array.prototype.includes or Object.entries, a very old browser still fails, because those are built-in objects and methods rather than syntax. Projects add polyfills, usually from core-js, for those. Keep that in mind when you see clean ES5 output and assume it will run everywhere.

Babel also does not check types. preset-typescript strips them without looking at them, so a type error passes straight through. Run the TypeScript compiler with tsc --noEmit for type checking and let Babel do the fast compile.

Source maps keep debugging sane

Compiled code is harder to read, especially when minified. A source map links each position in the output back to the original file, so browser developer tools show your real source in stack traces and breakpoints. Tick the source map option, download the .map file next to the compiled script, or inline it while experimenting.

Use it to learn, then automate

Watching Babel rewrite a snippet is one of the best ways to understand modern JavaScript features and what they cost in older browsers. Once you know the settings you want, put them in your build and let it run on every save.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages