mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
5a6e37e5cf
### 🚀 Features -ca649e0ecma: Define math constants as known globals and resolve their types (#26585) (Armano) -9ef028ccodegen: Add `ascii_only` option (#25994) (Samuel Attard) -80a76a0minifier: Negate binary comparison for `typeof x < 'u'` (#26367) (Armano) ### 🐛 Bug Fixes -8ca76daparser: Reject `accessor` modifiers on methods (#26617) (camc314) -1916f31parser: Reject `readonly` modifier on constructors (#26612) (camc314) -1c42008parser: Handle escaped let in for loops (#26583) (camc314) -d21d5cfparser: Recognize annotated empty arrows in conditionals (#26537) (camc314) -d7713adparser: Classify Unicode line breaks in block comments (#26536) (camc314) -75cd919transformer: Preserve receivers in private optional chains (#26535) (camc314) -b32d25dparser: Reject escaped import-phase keywords (#26534) (camc314) -47b8311parser: Recognize contextual binding names in type lookaheads (#26532) (camc314) -d6b6705parser: Require arrow separator in TypeScript function types (#26529) (camc314) -e98beefparser: Disambiguate await using in for initializers (#26527) (camc314) -92afee6parser: Allow parenthesized JSX comma expressions with preserve_parens=false (#26524) (camc314) -31508b1parser: Reject return types on constructor overloads (#26523) (camc314) -a091fc4parser: Validate await context for await using declarations (#26495) (camc314) -5501e86parser: Disallow in expressions in using for-loop initializers (#26490) (camc314) -c8e5fa7parser: Allow escaped type names in import and export specifiers (#26487) (camc314) -2dcee2fparser: Reject async modifiers on class fields (#26486) (camc314) -973d58eparser: Require comma after TypeScript this parameter (#26480) (camc314) -32d00c5codegen: Preserve instantiation expression precedence (#26424) (camc314) -cfa47abparser: Allow `in` expressions in class static blocks (#26423) (camc314) -5986187packages/codegen: Preserve private-in right operand precedence (#26420) (camc314) -f8e6c6cpackages/codegen: Preserve in restriction through yield arguments (#26421) (camc314) -d61e3bfparser: Validate TS named tuple rest elements (#26419) (camc314) -ae6c386codegen: Preserve in restriction through yield arguments (#26413) (camc314) -42ac916codegen: Preserve private-in right operand precedence (#26411) (camc314) -10521b2parser: Allow escaped type default import bindings (#26409) (camc314) -72cb5e3parser: Reject rest parameters in getters (#26400) (camc314) -6e15ad5packages/codegen: Print matching quoted import names as identifiers (#26404) (camc314) -bbbb4bcpackages/codegen: Preserve private-in left operand precedence (#26403) (camc314) -a111b5bpackages/codegen: Print accessibility modifiers before abstract (#26402) (camc314) -4e76602parser: Allow `in` in arrow block bodies within `for` initializers (#26395) (camc314) -b20fc19parser: Reject partially parenthesized mixed coalesce expressions (#26394) (camc314) ### ⚡ Performance -1f902a6isolated_declarations: Key scope maps by `Ident` (#26380) (Dunqing) -a242469minfiier: Reduce allocs when creating indirect access (#26601) (Armano) -5b4787fminifier: Update chain expressions in place (#26544) (Armano) -0bc1661minifier: Try merging before creating new expression statements (#26556) (Armano) -c78d707minifier: Process newly created stmt in handle_if_statement (#26541) (Armano) -029c84bminfier: Update expressions in place when substituting alternate syntax (#26460) (Armano) -d198982codegen: Outline postfix source mapping work (#26450) (camc314) -53f006eecmascript: Format small integer literals with itoa (#26446) (camc314) -8bfb8c0codegen: Avoid duplicate sourcemap name lookups (#26441) (camc314) ### 📚 Documentation -38533acast: Move type annotation span comment to span field (#26522) (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.
