mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
### 💥 BREAKING CHANGES -94fbacbast: [**BREAKING**] Only export `AstBuilder` and `NONE` in `builder` module (#23876) (overlookmotel) -8de5122ecmascript: [**BREAKING**] Switch to new `AstBuilder` (#23834) (overlookmotel) -dc0ef38transformer: [**BREAKING**] Switch to new `AstBuilder` (#23831) (overlookmotel) -88f4455str: [**BREAKING**] `Str` and `Ident` methods take `&GetAllocator` (#23781) (overlookmotel) -36009ddallocator: [**BREAKING**] `GetAllocator::allocator` take `&self` (#23676) (overlookmotel) -bd74f9dallocator: [**BREAKING**] Rename `AllocatorAccessor` trait to `GetAllocator` (#23675) (overlookmotel) ### 🚀 Features -326fe25transformer_plugins: Support `typeof` `define` keys (#23605) (Alexander Lichter) -f2091b3ast: Unify old and new `AstBuilder`s (#23875) (overlookmotel) -cd1fd12codegen: Expose `Codegen::print_string` API (#23785) (camc314) -785461bast: Add custom builder methods to AST types (#23651) (overlookmotel) -05d1357ast: Add AST creation methods to AST types (#23650) (overlookmotel) -2580edastr: Add `Str::from_str_in` and `Ident::from_str_in` methods (#23767) (overlookmotel) -6883fcfminifier: Fold write-once falsy var to false in boolean context (#23540) (Dunqing) -fcbf993allocator: Add `Vec::from_value_in` method (#23718) (overlookmotel) -989ddb7allocator: Add `Vec::from_box_in` method (#23717) (overlookmotel) -9d1aa7fallocator: Improve `PartialEq` for `Vec` (#23716) (overlookmotel) ### 🐛 Bug Fixes -da0e5bfminifier: Don't reorder a closed-over TDZ read when inlining a var (#23771) (Dunqing) -0b3021fallocator: Remove `Vec::from_box_in` (#23873) (overlookmotel) -0ab64ecast: Silence deprecation warnings within files defining deprecated `AstBuilder` methods (#23889) (overlookmotel) -8c07cadall: Enable `disable_old_builder` Cargo feature for `oxc_ast` crate in tests (#23888) (overlookmotel) -3800f01ast: Legacy `AstBuilder` methods take `self` not `&self` (#23891) (overlookmotel) -869ac20semantic/cfg: Connect for update exit to loop test (#23791) (camc314) -d3e92d5semantic/cfg: Connect while branches from condition exit (#23790) (camc314) -025045dast: `ExportNamedDeclaration` plain builder methods return boxed nodes (#23783) (overlookmotel) -7537c58ast: Fix name of `AstBuilder` method for `Expression::V8IntrinsicExpression` (#23766) (overlookmotel) -3f574f5traverse: Fix unsoundness in `Traverse` walk functions (#23745) (overlookmotel) -585760fparser: String in AST reference arena (#23721) (overlookmotel) -7231d55allocator: Fix unsound lifetime extension in `Box::new_in` (#23685) (overlookmotel) ### ⚡ Performance -d5c916asemantic: Flatten hoisting_variables to avoid per-scope map allocation (#23927) (Lawrence Lin) -e71609dminifier: Bail member-expr folding before the side-effect walk (#23924) (Lawrence Lin) -e1f89abminifier: Reduce string allocations folding addition (#23846) (overlookmotel) -9f6ee3bisolated-declarations: Pool scope maps to avoid per-scope alloc/rehash (#23761) (Boshen) -0b07c4csemantic: Avoid heap alloc for catch-clause binding ids (#23911) (Lawrence Lin) -c5eef8bregular_expression: Skip capturing-group pre-parse when pattern has no `(` (#23908) (Lawrence Lin) -b4f5b4bisolated_declarations: Remove redundant clone of formal parameter pattern (#23912) (Lawrence Lin) -53d083fisolated_declarations: Use `TakeIn` not `CloneIn` (#23847) (overlookmotel) -3ea9304react_compiler: Use faster API to arena allocate strings (#23849) (overlookmotel) -a6d8e45parser: Avoid span lookup for arrow expression body (#23788) (camc314) -e1886a0transformer, minifier: Use `static_ident!` macro to create static `Ident`s (#23727) (overlookmotel) -5527beftransformer/object-rest-spread: Reduce iteration (#23720) (overlookmotel) -680ffbctransformer: Allocate AST nodes in arena directly (#23711) (overlookmotel) -1c63c66parser: Allocate AST nodes in arena directly (#23712) (overlookmotel) -3855f0cminifier: Allocate AST nodes in arena directly (#23710) (overlookmotel) -d025887isolated_declarations: Allocate AST nodes in arena directly (#23709) (overlookmotel) -10b96c6parser: Remove string search from parsing JSX element name (#23713) (overlookmotel) ### 📚 Documentation -3d61deaall: Correct capitalization in comments (#23887) (overlookmotel) -aa1ad74ast: Add `#[deprecated]` to legacy `AstBuilder` methods (#23877) (overlookmotel) -a4676dbast: Correct doc comment for `NONE` (#23765) (overlookmotel) -419ec80syntax: Fix typo in doc comment (#23674) (overlookmotel) ### 🛡️ Security -3cdd18fdeps: Update npm packages (#23690) (renovate[bot]) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com> Co-authored-by: Cameron <cameron.clark@hey.com>
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.