Ergonomic JavaScript code generation using OXC AST builders
This crate provides a high-level, type-safe API for generating JavaScript code using the OXC (Oxidation Compiler) AST infrastructure.
Features
- Type-safe AST building - Leverage Rust's type system for correct JavaScript generation
- Zero-copy string handling - Efficient string interning via OXC's
Atom - Ergonomic API - Intuitive method names that mirror JavaScript syntax
- Full module support - Generate imports, exports, and ES modules
- Modern JS features - Arrow functions, template literals, destructuring, and more
Examples
Basic Usage
use ProgramBuilder;
use Allocator;
use Statement;
let allocator = default;
let mut js = new;
// Build: const x = 42;
let stmt = js.const_decl;
js.push;
// Build: import React from 'react';
let import = js.import_default;
// ModuleDeclarations need to be converted to Statements
js.push;
// Generate code
let code = js.generate?;
println!;
# Ok::
Building Complex Expressions
use ProgramBuilder;
use Allocator;
let allocator = default;
let mut js = new;
// Build: console.log("Hello, world!")
let console_log = js.call;
let stmt = js.expr_stmt;
js.push;
let code = js.generate?;
# Ok::
Arrow Functions and Arrays
use ProgramBuilder;
use Allocator;
let allocator = default;
let mut js = new;
// Build: const double = x => x * 2;
let arrow = js.arrow_fn;
let stmt = js.const_decl;
js.push;
let code = js.generate?;
# Ok::