Compile TypeScript to machine code ahead of time: `bun build --compile --aot` by Jarred-Sumner · Pull Request #45631 · oven-sh/bun

· GitHub

6 min read Original article ↗

@robobun mentioned this pull request

Oct 17, 2026
- --aot-explain reports each cause of untyped or tested code once, ranked by cost.
- int32 is proved at build time (TS100031 to TS100034); nothing is tested at run time.
- bun check --aot follows the build for standard decorators, numeric JSX keys and
  entry points under several tsconfig files.
- Typed node:http is taken out again.
- !!x and Boolean(x) convert a missing element; a value that may be missing keeps
  its doubt through arithmetic.
- Windows: virtual modules of plugins, paths in diagnostics.
- clippy, source lints, a leak in Program::release().
- Rust crates overlap again in rebuilds.
The tree is unchanged; the sources are formatted in one later change.

@autofix-ci

@autofix-ci

…er --aot-explain

- A request body's UTF-8 bytes go straight to the JSON parser.
- new Response(res.body, res) is one native call and makes no ReadableStream.
- --aot-explain puts causes that must be fixed together into one row and groups
  accesses by name under their variable.
- The first native error of the Postgres or MySQL client no longer aborts a
  compiled executable.
- Each entry point gets its own import.meta.
- A call is no longer reported as "always throws" because an unrelated class has
  a method of the same name.
- A function declared in one file and stored as a method in another is not
  refused on an object that inherits from a typed one.
- bun check --aot reports what the build reports for a package's typed version.
- Lint, clippy and type errors fixed; test shards sized from recorded durations.
The records follow the compiler changes of the last hour; no product code changes.
The tree is unchanged; the sources are formatted in one later change.

@autofix-ci

@autofix-ci

…code

Five programs send well-formed and malformed JSON.parse results into typed
functions, casts and subtypes; each must print what plain Bun prints.
The tree is unchanged; the sources are formatted in one later change.

@autofix-ci

@autofix-ci

…pe checks

- A sum of two values typed string that are missing at run time gives NaN as in
  plain Bun instead of throwing.
- Values that fit their type are no longer refused: a function with the asked
  member, an object with many keys returned as a mapped type, a generic closure
  called through a value, instantiations of one generic interface.
- A method named like a member of a host object no longer makes a call throw.
- --compile-trim-runtime (off by default) leaves out the parts of the runtime a
  compiled executable cannot reach.
- The verdict of bun check --aot and bun test --aot depends less on which other
  files, and in which order, are in the run; extensionless imports resolve as
  Bun resolves them.
- bun check --aot reports what the build reports for packages that need a define.
- bun test --aot names every refused change to a locked built-in in its summary.
- A class that is re-exported only as a type is not part of the namespace object.
- Tests, recorded counts and durations renewed.
Each test program is checked as a project of its own, so this one can no longer
lean on its neighbours' declarations; its recorded typedness follows.
The tree is unchanged; the sources are formatted in one later change.

@autofix-ci

@autofix-ci

…ls, Windows fixes

- An object literal passed to a callee that is only predicted is made as the
  parameter's record instead of being converted at the call.
- A class named through a namespace import is that class; an interface in a
  type-only namespace is the program's own.
- A sum of values typed string that are missing at run time may be stored in an
  unannotated literal, array, Set or Map; an unused chain of sums is removed.
- request.headers.get(name), response headers and constant names in an init
  literal need no Headers object.
- The globals of a Bun.ModuleGraph may replace the globals that Bun provides.
- bun check --aot no longer stops before type checking when a root file lies
  outside rootDir.
- A for..of over the URLSearchParams of a URL without a query makes no trip into
  the runtime; a Set is filled from an array by compiled code.
- The runtime trimmed by --compile-trim-runtime links under LTO.
- The builtins target knows $likely and $unlikely.
- Fixes for --aot on Windows: files held by an in-place executable can be
  opened, native addons, the incremental type check.
- The five Headers methods need no Headers object; a header name that is a
  parameter is compared with the constants the program passes.
- Tests, recorded counts and durations renewed.
new URLSearchParams(x) keeps its former form where the type of x holds no
string; two recorded typedness lines follow.
- new Set(array) is made by the runtime again.
- Helpers that return closures are followed when the program is built.
- Tests for the trimmed runtime; recorded counts and typedness renewed.
The lines were first recorded while a change that has since been taken out was
in; they are back at what the engine counted before it.
An untyped for loop over an array of numbers at module level takes 1.5
instructions more an element since string comparisons in loops went in line.
The tree is unchanged; the sources are formatted in one later change.

@autofix-ci

@autofix-ci

…ets by relative path

- The ci-build profile links with islands on Linux and macOS arm64, so
  --compile-trim-runtime is tested in CI.
- A relative path, copyFile and Bun.file().stat() work on an asset held in the
  executable.
- bun build --dts on Windows: the checker's and the bundler's paths agree.
- Tests that took POSIX paths for granted; recorded counts and typedness renewed.
- "Is this container filled from outside?" is a query of the solver with a memo
  per variable. `const parts = []; parts.push(parts[0] + parts[1])` made the
  analysis recurse without end; it is linear in the number of stores now.
- The table of islands says when a feature is kept; the bundler, Bun.color and
  HTMLRewriter are laid out as features of their own.

This was referenced

Nov 11, 2026

This was referenced

Nov 21, 2026

@alii alii mentioned this pull request

Nov 24, 2026

This was referenced

Nov 25, 2026