Quickly transpile TypeScript, JSX, or JS to modern JavaScript.
Symbol
Transpiler
class Transpiler
const transpiler = new Bun.Transpiler();
transpiler.transformSync(`
const App = () => <div>Hello World</div>;
export default App;
`);
// This outputs:
const output = `
const App = () => jsx("div", {
children: "Hello World"
}, undefined, false, undefined, this);
export default App;
`
Get a list of import paths and paths from a TypeScript, JSX, TSX, or JavaScript file.
@param codeThe code to scan
const {imports, exports} = transpiler.scan(` import {foo} from "baz"; export const hello = "hi!"; `); console.log(imports); // ["baz"] console.log(exports); // ["hello"]
Get a list of import paths from a TypeScript, JSX, TSX, or JavaScript file.
@param codeThe code to scan
const imports = transpiler.scanImports(` import {foo} from "baz"; import type {FooType} from "bar"; import type {DogeType} from "wolf"; `); console.log(imports); // ["baz"]
This is a fast path which performs less work than
scan
.Transpile code from TypeScript or JSX into valid JavaScript. This function does not resolve imports.
@param codeThe code to transpile
Transpile code from TypeScript or JSX into valid JavaScript. This function does not resolve imports.
@param codeThe code to transpile
Transpile code from TypeScript or JSX into valid JavaScript. This function does not resolve imports.
@param codeThe code to transpile
@param ctxAn object to pass to macros
Transpile code from TypeScript or JSX into valid JavaScript. This function does not resolve imports.
@param codeThe code to transpile