Awesome
<p align="center"> <img alt="OXC Logo" src="https://cdn.jsdelivr.net/gh/oxc-project/oxc-assets/preview-universal.png" width="700"> </p> <div align="center"> </div>β Oxc
The Oxidation Compiler is creating a collection of high-performance tools for JavaScript and TypeScript.
Oxc is building a parser, linter, formatter, transformer, minifier, resolver ... all written in Rust.
See more at oxc.rs!
πWho's using Oxc?
- Rolldown uses the oxc crate for parsing and transformation.
- Nova engine uses the oxc crate for parsing.
- Rolldown, Biome and swc-node uses the oxc_resolver crate for module resolution.
- Projects and companies like Preact, Shopify, ByteDance and Shopee uses oxlint for linting.
- ...and many more
β‘οΈ Linter Quick Start
The linter is ready to catch mistakes for you. It comes with 93 rules turned on by default (out of 400+ in total) and no configuration is required.
To get started, run oxlint or via npx
:
npx oxlint@latest
To give you an idea of its capabilities, here is an example from the vscode repository, which finishes linting 4800+ files in 0.7 seconds.
<p float="left" align="left"> <img src="https://cdn.jsdelivr.net/gh/oxc-project/oxc-assets/linter-screenshot.png" width="60%"> </p>β‘οΈ Performance
- The parser aims to be the fastest Rust-based ready-for-production parser.
- The linter is more than 50 times faster than ESLint, and scales with the number of CPU cores.
β¨οΈ Rust, Node.js and Wasm Usage
Rust
Individual crates are published, you may use them to build your own JavaScript tools.
- The umbrella crate oxc exports all public crates from this repository.
- The AST and parser crates oxc_ast and oxc_parser are production ready.
- The resolver crate oxc_resolver for module resolution is also production ready.
- Example usages of these crates can be found in their respective
crates/*/examples
directory.
While Rust has gained a reputation for its comparatively slower compilation speed, we have dedicated significant effort to fine-tune the Rust compilation speed. Our aim is to minimize any impact on your development workflow, ensuring that developing your own Oxc based tools remains a smooth and efficient experience.
This is demonstrated by our CI runs, where warm runs complete in 3 minutes.
Node.js
- via napi: [oxc-parser][npm-napi], oxc-transform
Wasm
π― Tools
πΈ AST and Parser
Oxc maintains its own AST and parser, which is by far the fastest and most conformant JavaScript and TypeScript (including JSX and TSX) parser written in Rust.
As the parser often represents a key performance bottleneck in JavaScript tooling, any minor improvements can have a cascading effect on our downstream tools. By developing our parser, we have the opportunity to explore and implement well-researched performance techniques.
While many existing JavaScript tools rely on estree as their AST specification, a notable drawback is its abundance of ambiguous nodes. This ambiguity often leads to confusion during development with estree.
The Oxc AST differs slightly from the estree AST by removing ambiguous nodes and introducing distinct types.
For example, instead of using a generic estree Identifier
,
the Oxc AST provides specific types such as BindingIdentifier
, IdentifierReference
, and IdentifierName
.
This clear distinction greatly enhances the development experience by aligning more closely with the ECMAScript specification.
π Parser Performance
Our benchmark reveals that the Oxc parser surpasses the speed of the swc parser by approximately 3 times and the Biome parser by 5 times.
<details> <summary>How is it so fast?</summary> <ul> <li>AST is allocated in a memory arena (<a href="https://crates.io/crates/bumpalo">bumpalo</a>) for fast AST memory allocation and deallocation.</li> <li>Short strings are inlined by <a href="https://crates.io/crates/compact_str">CompactString</a>.</li> <li>No other heap allocations are done except the above two.</li> <li>Scope binding, symbol resolution and some syntax errors are not done in the parser, they are delegated to the semantic analyzer.</li> </ul> </details>πΈ Linter
The linter embraces convention over configuration, eliminating the need for extensive configuration and plugin setup. Unlike other linters like ESLint, which often require intricate configurations and plugin installations (e.g. @typescript-eslint), our linter only requires a single command that you can immediately run on your codebase:
npx oxlint@latest
π Linter Performance
The linter is 50 - 100 times faster than ESLint depending on the number of rules and number of CPU cores used. It completes in less than a second for most codebases with a few hundred files and completes in a few seconds for larger monorepos. See bench-javascript-linter for details.
As an upside, the binary is approximately 5MB, whereas ESLint and its associated plugin dependencies can easily exceed 100.
You may also download the linter binary from the latest release tag as a standalone binary, this lets you run the linter without a Node.js installation in your CI.
<details> <summary>How is it so fast?</summary> <ul> <li>Oxc parser is used.</li> <li>AST visit is a fast operation due to linear memory scan from the memory arena.</li> <li>Files are linted in a multi-threaded environment, so scales with the total number of CPU cores.</li> <li>Every single lint rule is tuned for performance.</li> </ul> </details>πΈ Resolver
Module resolution plays a crucial role in JavaScript tooling, especially for tasks like multi-file analysis or bundling. However, it can often become a performance bottleneck. To address this, we developed oxc_resolver.
The resolver is production-ready and is currently being used in Rolldown. Usage and examples can be found in its own repository.
πΈ Transformer
A transformer is responsible for turning higher versions of ECMAScript to a lower version that can be used in older browsers.
TypeScript and React transforms are complete. See Milestone 2 for current goals.
oxc-transform can be used for experimentation.
πΈ Isolated Declarations
TypeScript Isolated Declarations Emit without using the TypeScript compiler.
Our benchmark indications that our implementation is at least 20 times faster than the TypeScript compiler.
The npm package or crate can be used for this task.
πΈ Minifier
JavaScript minification plays a crucial role in optimizing website performance as it reduces the amount of data sent to users, resulting in faster page loads. This holds tremendous economic value, particularly for e-commerce websites, where every second can equate to millions of dollars.
However, existing minifiers typically require a trade-off between compression quality and speed. You have to choose between the slowest for the best compression or the fastest for less compression. But what if we could develop a faster minifier without compromising on compression?
We are actively working on a prototype that aims to achieve this goal, by porting all test cases from well-known minifiers such as google-closure-compiler, terser, esbuild, and tdewolff-minify.
Preliminary results indicate that we are on track to achieve our objectives. With the Oxc minifier, you can expect faster minification times without sacrificing compression quality.
πΈ Formatter
While prettier has established itself as the de facto code formatter for JavaScript, there is a significant demand in the developer community for a less opinionated alternative. Recognizing this need, our ambition is to undertake research and development to create a new JavaScript formatter that offers increased flexibility and customization options.
The prototype is currently work in progress.
π§ͺTest Infrastructure
In Oxc, correctness and reliability are taken extremely seriously.
We spend half of our time on strengthening the test infrastructure to prevent problems from propagating to downstream tools.
Test Infrastructure documents our test procedures:
- Conformance suite on Test262, Babel, TypeScript
- Lots of fuzzing
- Linter snapshot diagnostics
- oxlint ecosystem ci
- Idempotency testing
- Code coverage
- End to end 3000 top npm packages
βοΈ Contribute
See CONTRIBUTING.md for guidance.
Check out some of the good first issues or ask us on Discord.
If you are unable to contribute by code, you can still participate by:
- Add a GitHub Star to the project.
- Join us on Discord.
- Follow me on twitter and tweet about this project.
π Learning Resources
- My small tutorial on how to write a JavaScript Parser in Rust
- My small article Pursuit of Performance on Building a JavaScript Compiler
- And more
π€ Credits
This project was incubated with the assistance of these exceptional mentors and their projects:
- Biome - @ematipico
- Ruff - @charliermarsh, @MichaReiser
- quick-lint-js - @strager
- elm-review - @jfmengels
Special thanks go to
- @domonji for bootstrapping this project together, and also completing the TypeScript parser.
- @tongtong-lu and @guan-wy for designing the project logo.
β€ Who's Sponsoring Oxc?
<p align="center"> <a href="https://github.com/sponsors/Boshen"> <img src="https://raw.githubusercontent.com/Boshen/sponsors/main/sponsors.svg" alt="My sponsors" /> </a> </p>π License
Oxc is free and open-source software licensed under the MIT License.
Oxc ports or copies code from other open source projects, their licenses are listed in Third-party library licenses.