Oxc Transform
TypeScript and React JSX Transform
import assert from "assert";
import { transformSync } from "oxc-transform";
const { code, declaration, errors } = transformSync("test.ts", "class A<T> {}", {
typescript: {
declaration: true,
},
});
assert.equal(code, "class A {}\n");
assert.equal(declaration, "declare class A<T> {}\n");
assert(errors.length == 0);
Conforms to TypeScript compiler's --isolatedDeclarations .d.ts emit.
Usage
import assert from "assert";
import { isolatedDeclarationSync } from "oxc-transform";
const { map, code, errors } = isolatedDeclarationSync("test.ts", "class A {}");
assert.equal(code, "declare class A {}\n");
assert(errors.length == 0);
API
Transform Functions
transformSync(
filename: string,
sourceText: string,
options?: TransformOptions,
): TransformResult
transform(
filename: string,
sourceText: string,
options?: TransformOptions,
): Promise<TransformResult>
Isolated Declaration Functions
isolatedDeclarationSync(
filename: string,
sourceText: string,
options?: IsolatedDeclarationsOptions,
): IsolatedDeclarationsResult
isolatedDeclaration(
filename: string,
sourceText: string,
options?: IsolatedDeclarationsOptions,
): Promise<IsolatedDeclarationsResult>
Use the Sync versions for synchronous operations. Use async versions for asynchronous operations, which can be beneficial in I/O-bound or concurrent scenarios, though they add async overhead.
See index.d.ts for complete type definitions.
Supports WASM
See https://stackblitz.com/edit/oxc-transform for usage example.