mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
0389c4010e
### 🚀 Features -83cb516minifier: Improve negation of expressions in boolean context (#25755) (Armano) ### 🐛 Bug Fixes -134fb22isolated-declarations: Preserve unresolved parameter types (#25909) (Dunqing) -526c2b3codegen: Remove deprecated test APIs (#25889) (camc314) -344a9b2codegen: Align enum template sourcemaps (#25872) (camc314) ### ⚡ Performance -5ef0c93minifier: Unwrap all unary exprs without creating dummy expressions (#25891) (Armano) -8783524packages/codegen: Remove loop from `growMappingBuffer` (#25886) (overlookmotel) -b6b14c0packages/codegen: Remove redundant branch (#25885) (overlookmotel) -be6adf0packages/sourcemap: Make `location` passed to `recordSourceMapping` always a number (#25884) (overlookmotel) -f720f15packages/codegen: Take named-mapping only code off hot path in `recordSourceMapping` (#25883) (overlookmotel) -a734af5packages/codegen: Remove redundant setting of `last` in `printImportAttributes` and `printIf` (#25882) (overlookmotel) -c6e44c6packages/codegen: Combine 2 writes in `printJSXElement` (#25881) (overlookmotel) -8801662packages/codegen: Remove redundant mapping from `printParams` (#25880) (overlookmotel) ### 📚 Documentation -5ad330epackages/codegen: Reformat comments (#25876) (overlookmotel)
Oxc Transform
See usage instructions.
TypeScript and React JSX Transform
import assert from "node:assert";
import { transformSync } from "oxc-transform";
const { code, declaration, errors } = transformSync("test.ts", "class A<T> {}", {
typescript: {
declaration: true, // With isolated declarations in a single step.
},
});
// or `await transform(filename, code, options)`
assert.equal(code, "class A {}\n");
assert.equal(declaration, "declare class A<T> {}\n");
assert(errors.length == 0);
Isolated Declarations for Standalone DTS Emit
Conforms to TypeScript compiler's --isolatedDeclarations .d.ts emit.
Usage
import assert from "node:assert";
import { isolatedDeclarationSync } from "oxc-transform";
const { map, code, errors } = isolatedDeclarationSync("test.ts", "class A {}");
// or `await isolatedDeclaration(filename, code, options)`
assert.equal(code, "declare class A {}\n");
assert(errors.length == 0);
API
Transform Functions
// Synchronous transform
transformSync(
filename: string,
sourceText: string,
options?: TransformOptions,
): TransformResult
// Asynchronous transform
transform(
filename: string,
sourceText: string,
options?: TransformOptions,
): Promise<TransformResult>
Isolated Declaration Functions
// Synchronous isolated declaration
isolatedDeclarationSync(
filename: string,
sourceText: string,
options?: IsolatedDeclarationsOptions,
): IsolatedDeclarationsResult
// Asynchronous isolated declaration
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.