Architecture Overview
This library provides a high-performance JavaScript and TypeScript toolchain built in Rust. Its architecture emphasizes modularity, allowing developers to use individual components like parsers, transformers, linters, and formatters independently or compose them into a complete toolchain. Developers interact with the primary toolchain capabilities through the oxlint CLI for linting and the oxfmt CLI for code formatting. For programmatic use within Node.js, the N-API bindings offer access to Oxc's Rust core.
Under the hood, Oxc's architecture is built around a robust parsing engine. The oxc-parser crate is fundamental, taking source code and producing an Abstract Syntax Tree (AST). This AST is then processed by various internal modules for transformation and linting. The design emphasizes a clear separation of concerns, allowing for independent development and integration of different processing stages. The oxc-transformer crate handles code transformations, supporting features like JSX, TypeScript syntax, and modern ECMAScript proposals, operating on the AST produced by oxc-parser.
The core parsing process begins with the Syntax Scanner (Lexer), which reads source code and groups it into meaningful tokens. These tokens are then fed into the JavaScript Parser Core, which applies grammar rules to construct the AST. This AST serves as the common data model for all subsequent analysis. The AST Representation and Traversal module defines these structures and provides robust visitor patterns, enabling efficient navigation and manipulation of the code representation by other Oxc components.
The linting functionality is powered by oxlint, which utilizes the AST generated by oxc-parser. The Linter Rule Execution Engine within oxlint orchestrates the application of predefined and user-configured rules against the AST, identifying violations and providing feedback. Transformations within oxc-transformer specifically address TypeScript Syntax Transformations and Modern ECMAScript Feature Transformations, ensuring compatibility and enabling the use of the latest language constructs.
What makes Oxc special is its commitment to high performance through its Rust implementation and a modular design. This allows for granular use of its components. For example, developers can leverage the oxc-parser directly for custom AST generation or integrate the transformer for specific transpilation needs. The architecture is designed for flexibility, enabling the composition of these components into custom build tools or workflows.
For developers looking to contribute, understanding the oxc-parser crate and its AST Representation and Traversal is a key starting point, as this forms the bedrock of the entire toolchain. Familiarity with the oxlint and oxc-transformer crates will provide insight into how the AST is utilized for linting and transformation. The N-API Bindings directory is also crucial for understanding how Oxc's Rust core is exposed to the JavaScript ecosystem. Exploring the parser.rs and visitor.rs files within oxc_parser will reveal the core parsing and traversal mechanisms.