mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
60fa13878c
### 💥 BREAKING CHANGES -66744f0parser: [**BREAKING**] Rename `panicked` to `fatal_error` in `ParserReturn` (#26382) (overlookmotel) -2c9a947parser: [**BREAKING**] Reduce `MAX_LEN` to 256 bytes below `u32::MAX` (#26352) (overlookmotel) ### 🚀 Features -32bdc5ballocator: Construct `ArenaHashSet` with any `Default` hasher (#26372) (Dunqing) -a17de58minifier: Process of return/throw in non last position and fix async * inlining (#26214) (Armano) -bfb4c57parser: Distinguish unapplied no-side-effects comments (#26120) (碳苯 Carbon) -1d9b9d3ast: Add `GetNodeId` trait (#26145) (camc314) ### 🐛 Bug Fixes -b156333codegen: Order accessibility before abstract on accessors (#26392) (camc314) -116c8b8transformer/class-properties: Keep private methods in class-expression scope (#26308) (Changsu Seong) -1400a0fparser: Require a string source after `export ... from` (#26389) (camc314) -2da73b7codegen: Print matching quoted import names as identifiers (#26386) (camc314) -0a81d29codegen: Preserve private-in left operand precedence (#26383) (camc314) -9a02337parser: Correctly round large nondecimal literals (#26379) (camc314) -3d95477transformer: Gate async-only rewrites by owning transform (#26326) (Dunqing) -f45a9eetransformer: Limit arguments capture to lowered async functions (#26317) (Dunqing) -789969ftransformer: Gate this capture by owning async transform (#26227) (Dunqing) -affeb14minifier: Mangle class private members in Node API (#26118) (碳苯 Carbon) -8b35abdsemantic: Detect duplicate private class elements (#26361) (camc314) -457ed57semantic: Reject await and yield in rest parameter defaults (#26359) (camc314) -4b89c7bsemantic: Reject jumps across arrow functions (#26357) (camc314) -c966acaparser: Do not omit `<` token opening type argument list (#26328) (overlookmotel) -f07dca5ast_visit: Add the trimmed prefix length to translation table offsets (#26173) (Bharadwaj Pendyala) -3ab9bd1parser: Do not re-lex template substitution tail after fatal error (#26230) (overlookmotel) -07851b9parser: Fix debug assert failure when lexer error with tokens enabled (#26229) (overlookmotel) -00dea7aallocator: Gate `Allocator::data_end_ptr` behind fixed_size feature (#26248) (camc314) -853ffabecmascript: Avoid `charAt` panic on 32-bit (#26244) (camc314) -34feccbruntime: Remove stale regenerator exports (#26243) (camc314) ### ⚡ Performance -34a242eminifier: Use `Ident` for property mangler (#26334) (sapphi-red) -5303f5cminifier: Unify merging of last expression into target sequence (#26264) (Armano) -2ca7d29minifier: Consume nodes in minimize_statements in reverse order (#26258) (Armano) -d2354b4mangler: Use `Ident` for variable names to keep (#26333) (sapphi-red) -5b3e335minifier: Use `Ident` instead of `Str` in `KeepVar` (#26332) (sapphi-red) -51366fbminifier: Use `IdentHashSet` in `PrivateMemberUsageStack` (#26331) (sapphi-red) -d19c42aminifier: Merge nested if stmt in place instead of creating dummies (#26351) (Armano) -356def6parser: Shrink annotation comment ranges (#26356) (overlookmotel) -a5be474parser: Shave instruction off `parse_jsx_element_name` (#26355) (overlookmotel) -9780663parser: Remove fatal error guard from `parse_jsx_element_name` (#26354) (overlookmotel) -766e12fparser: Remove `token` field from `LexerCheckpoint` (#26350) (overlookmotel) ### 📚 Documentation -d4b4e61transformer: Document ES2015 target floor (#26378) (Dunqing) -67dd054ast_visit: Correct out-of-date comments on `Utf8ToUtf16` converter (#26285) (overlookmotel) -a8ed2a7minifier: Fix stale validation instructions (#26251) (camc314)
⚓ Oxc
The Oxidation Compiler is a high-performance web toolchain. This is an umbrella crate re-exporting all of oxc's different tools. It also adds higher-level APIs for stitching various components together that are not found in other oxc crates.
⚡️ Quick Start
The easiest way to get started with oxc is by adding this to your Cargo.toml:
[dependencies]
oxc = { version = "*", features = ["full"] }
In most cases, code using oxc will follow this general pipeline:
- Parse source code into an AST
- Run semantic analysis on the AST
- Use the AST and semantic data in one or more other tools
- Generate new code for the final processed program
Example
This example performs the first two steps of this pipeline:
use std::path::Path;
use oxc::{
allocator::Allocator,
parser::{Parser, ParserReturn},
span::SourceType,
semantic::{SemanticBuilder, SemanticBuilderReturn}
};
// In real code, this will likely come from a file read from disk.
let source_path = Path::new("test.tsx");
let source_text = "
import React from 'react';
export interface Props {
count: number;
onInc: () => void;
onDec: () => void;
}
export const Counter: React.FC<Props> = props => {
return (
<div>
<button onClick={props.onInc}>+</button>
<span id='count'>{props.count}</span>
<button onClick={props.onDec}>-</button>
</div>
);
};
";
// Memory arena where AST nodes are allocated.
let allocator = Allocator::default();
// Infer source type (TS/JS/ESM/JSX/etc) based on file extension
let source_type = SourceType::from_path(source_path).unwrap();
let mut errors = Vec::new();
// Step 1: Parsing
// Parse the TSX file into an AST. The root AST node is a `Program` struct.
let ParserReturn { program, diagnostics: parser_errors, fatal_error, .. } =
Parser::new(&allocator, source_text, source_type).parse();
errors.extend(parser_errors);
// Parsing failed completely. `program` is empty and `errors` isn't. If the
// parser could recover from errors, `program` will be a valid AST and
// `errors` will be populated. We can still perform semantic analysis in
// such cases (if we want).
if fatal_error {
for error in &errors {
eprintln!("{error:?}");
panic!("Parsing failed.");
}
}
// Step 2: Semantic analysis.
// Some of the more expensive syntax checks are deferred to this stage, and are
// enabled using `with_check_syntax_error`. You are not required to enable
// these, and they are disabled by default.
let SemanticBuilderReturn {
semantic,
errors: semantic_errors,
} = SemanticBuilder::new()
.with_check_syntax_error(true) // Enable extra syntax error checking
.with_cfg(true) // Build a Control Flow Graph
.build(&program); // Produce the `Semantic`
errors.extend(semantic_errors);
if errors.is_empty() {
println!("parsing and semantic analysis completed successfully.");
} else {
for error in errors {
eprintln!("{error:?}");
panic!("Failed to build Semantic for Counter component.");
}
}
// From here, you can now pass `program` and `semantic` to other tools.
💡 Features
These feature flags enable/disable various tools in oxc's toolchain:
full: Enable all features that provide access to a tool.semantic: Enable thesemanticmodule for semantic analysis on ASTs.transformer: Enable thetransformermodule for babel-like transpiling.minifier: Enable theminifierandmanglermodules for terser-like minification.codegen: Enable thecodegenmodule, which prints ASTs to source code and source maps.mangler: Enable themanglermodule without enablingminifier.cfg: Expose thecfgmodule. CFGs may still be created insemanticwithout turning this on.ast_visit: Enable theast_visitmodule for AST traversal.regular_expression: Enable regular expression parsing support.isolated_declarations: enable theisolated_declarationsmodule for generating typescript type declarations
These feature flags modify the behavior of oxc's tools. None of them are enabled
by the full feature.
serialize: ImplementsSerializeandDeserializefor various oxc data structures.conformance: Enables additional AST visitor hooks for conformance tests.
