Class Transpiler

Quickly transpile TypeScript, JSX, or JS to modern JavaScript.

Example

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;
`

Hierarchy

  • Transpiler

Constructors

Methods

  • Get a list of import paths and paths from a TypeScript, JSX, TSX, or JavaScript file.

    Example

    const {imports, exports} = transpiler.scan(`
    import {foo} from "baz";
    const hello = "hi!";
    `);

    console.log(imports); // ["baz"]
    console.log(exports); // ["hello"]

    Parameters

    • code: StringOrBuffer

      The code to scan

    Returns { exports: string[]; imports: Import[] }

    • exports: string[]
    • imports: Import[]
  • Get a list of import paths from a TypeScript, JSX, TSX, or JavaScript file.

    Example

    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.

    Parameters

    • code: StringOrBuffer

      The code to scan

    Returns Import[]

  • Transpile code from TypeScript or JSX into valid JavaScript. This function does not resolve imports.

    Parameters

    Returns Promise<string>

  • Transpile code from TypeScript or JSX into valid JavaScript. This function does not resolve imports.

    Parameters

    • code: StringOrBuffer

      The code to transpile

    • loader: JavaScriptLoader
    • ctx: object

    Returns string

  • Transpile code from TypeScript or JSX into valid JavaScript. This function does not resolve imports.

    Parameters

    • code: StringOrBuffer

      The code to transpile

    • ctx: object

      An object to pass to macros

    Returns string

  • Transpile code from TypeScript or JSX into valid JavaScript. This function does not resolve imports.

    Parameters

    Returns string

Generated using TypeDoc