Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/docs/contribute/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,37 @@ outline: deep

# Formatter (Prettier)

We are currently porting prettier to Oxc.
We are currently porting Prettier and Biome Formatter to Oxc to create a high-performance, Prettier-compatible formatter.

## Architecture Overview

The Oxc formatter is built around the same core concepts as Prettier but with significant performance optimizations:

- **Document Model**: Uses Prettier and Biome's document IR (Intermediate Representation)
- **Pretty Printing**: Implements Wadler's pretty printing algorithm
- **AST Integration**: Leverages Oxc's fast parser for optimal performance

## Performance Considerations

### Optimization Strategies

- **Memory Arena**: AST allocated in bump allocator
- **String Interning**: Reuse common strings
- **Lazy Evaluation**: Defer expensive computations

## Current Challenges

### Technical Challenges

1. **Comment Handling**: Preserving comment placement and formatting
2. **JavaScript Quirks**: Handling edge cases in JavaScript syntax
3. **Performance vs Compatibility**: Balancing speed with exact Prettier output
4. **Memory Management**: Efficient handling of large files

### Missing Features

- [ ] Plugin system compatibility
- [ ] Configuration file support
- [ ] Editor integrations
- [ ] CLI tool
- [ ] Language server protocol
89 changes: 85 additions & 4 deletions src/docs/contribute/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,91 @@ title: Introduction
outline: deep
---

# Introduction
# Contributing to Oxc

Thank you for your interest in contributing to Oxc!
Thank you for your interest in contributing to Oxc! We're building the next generation of JavaScript tooling, and we'd love your help.

Please check out our [good first issues](https://github.com/oxc-project/oxc/contribute) or ask for guidance on [Discord](https://discord.gg/9uXCAwqQZW).
## Quick Start

We welcome and appreciate any form of contributions.
The fastest way to get started is through our [good first issues](https://github.com/oxc-project/oxc/contribute). These are carefully selected tasks that are perfect for new contributors.

Need guidance? Join our [Discord community](https://discord.gg/9uXCAwqQZW) where our team and community members are happy to help.

## Ways to Contribute

We welcome and appreciate any form of contributions:

### πŸ› Bug Reports

- Report parsing errors or incorrect linting behavior
- Share performance issues or regressions
- Document edge cases we haven't considered

### πŸš€ Feature Development

- Add new linting rules
- Improve parser conformance
- Enhance transformer capabilities
- Build new tools in the Oxc ecosystem

### πŸ“š Documentation

- Improve getting started guides
- Add examples and tutorials
- Document architecture decisions
- Translate content to other languages

### πŸ§ͺ Testing

- Add test cases from real-world codebases
- Improve test coverage
- Create performance benchmarks
- Test against ecosystem projects

### πŸ”§ Infrastructure

- Improve build and CI systems
- Enhance development tooling
- Optimize performance critical paths
- Maintain compatibility with other tools

### Understanding the Codebase

Oxc is organized into several crates:

- **`oxc_parser`**: High-performance JavaScript/TypeScript parser
- **`oxc_linter`**: Fast linting engine with 500+ rules
- **`oxc_transformer`**: TypeScript and JSX transformation
- **`oxc_minifier`**: JavaScript minification (in development)
- **`oxc_formatter`**: Code formatting (in development)

### Your First Contribution

1. **Browse Issues**: Look for issues labeled [`good first issue`](https://github.com/oxc-project/oxc/labels/good%20first%20issue)
2. **Ask Questions**: Don't hesitate to ask for clarification on Discord or GitHub
3. **Start Small**: Begin with documentation improvements or small bug fixes
4. **Learn the Patterns**: Study existing code to understand our conventions

## Community

### Communication Channels

- **GitHub Discussions**: For design discussions and questions
- **Discord**: Real-time chat with the team and community
- **GitHub Issues**: Bug reports and feature requests
- **Twitter**: Follow [@boshen_c](https://twitter.com/boshen_c) for updates

### Code of Conduct

We are committed to providing a welcoming and inclusive experience for everyone. Please read our [Code of Conduct](https://github.com/oxc-project/oxc/blob/main/CODE_OF_CONDUCT.md) before participating.

## Next Steps

Ready to contribute? Here are some great places to start:

- πŸ“– **Learn More**: Check out our [development guide](./development.md)
- πŸ” **Find an Issue**: Browse our [good first issues](https://github.com/oxc-project/oxc/contribute)
- πŸ’¬ **Join the Community**: Connect with us on [Discord](https://discord.gg/9uXCAwqQZW)
- πŸ› οΈ **Pick a Tool**: Dive into [parser](./parser.md), [linter](./linter.md), [transformer](./transformer.md), or [other tools](./formatter.md)

We can't wait to see what you'll build with us! πŸš€
53 changes: 53 additions & 0 deletions src/docs/contribute/minifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,65 @@ However, existing minifiers typically require a trade-off between compression qu
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?

## Project Goals

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.

### Target Performance

- **Speed**: faster than Terser, competitive with esbuild
- **Compression**: Match or exceed Terser's compression ratio
- **Correctness**: Pass all major minifier test suites

## Architecture Overview

### Design Principles

The Oxc minifier is built around several key principles:

1. **Semantic-Aware**: Uses semantic analysis to enable safe optimizations
2. **Incremental**: Designed for incremental compilation workflows
3. **Configurable**: Supports various optimization levels and targets
4. **Correct**: Prioritizes correctness over aggressive optimization

## Current Status

### Implemented Features

- βœ… **Dead Code Elimination**: Remove unreachable code
- βœ… **Constant Folding**: Evaluate constant expressions
- βœ… **Tree Shaking**: Remove unused exports (basic)
- βœ… **Variable Merging**: Merge variable declarations
- βœ… **Statement Merging**: Combine compatible statements
- βœ… **Name Mangling**: Shorten variable and function names
- βœ… **Control Flow Optimization**: Simplify control structures
- βœ… **Function Inlining**: Inline small functions
- βœ… **Advanced Tree Shaking**: Cross-module optimization

### Performance Optimization

Key strategies for maintaining performance:

1. **Minimal AST Traversals**: Combine multiple optimizations in single passes
2. **Efficient Data Structures**: Use arena allocation and compact representations
3. **Early Termination**: Skip optimizations when no benefit is possible

## Resources

### Documentation

- [Minifier API Documentation](https://docs.rs/oxc_minifier)

### External References

- [Google Closure Compiler Optimizations](https://github.com/google/closure-compiler/wiki/JS-Modules)
- [Terser Options](https://github.com/terser/terser#minify-options)
- [esbuild Minification](https://esbuild.github.io/api/#minification)

[google-closure-compiler]: https://github.com/google/closure-compiler
[terser]: https://github.com/terser/terser
[esbuild]: https://github.com/evanw/esbuild
Expand Down
92 changes: 84 additions & 8 deletions src/docs/contribute/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,103 @@ outline: deep

# Parser

We aim to be the fastest Rust-based ready-for-production parser.
The Oxc parser is designed to be the fastest and most conformant JavaScript and TypeScript parser available. Contributing to the parser requires understanding both the implementation details and the extensive test infrastructure.

## Conformance Tests
## Architecture Overview

The parser follows a traditional compiler frontend architecture:

```
Source Text β†’ Lexer β†’ Tokens β†’ Parser β†’ AST
```

### Key Components

- **Lexer**: Tokenizes source text into structured tokens
- **Parser**: Recursive descent parser that builds the AST
- **AST**: Memory-efficient abstract syntax tree
- **Error Recovery**: Advanced error handling and recovery
- **Semantic Analysis**: Symbol resolution and scope management

### Design Goals

We aim to be the fastest Rust-based ready-for-production parser with:

- **Speed**: 3x faster than SWC, 5x faster than Biome
- **Conformance**: 100% Test262 compliance, 99%+ Babel/TypeScript compatibility
- **Memory Efficiency**: Arena-based allocation, minimal heap usage
- **Error Quality**: Helpful error messages with recovery

## Development Workflow

### Setting Up

```bash
# Run parser tests
cargo test -p oxc_parser

# Run conformance tests
just c # or `just coverage`
```

### Project Structure

```
crates/oxc_parser/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ lib.rs # Public API
β”‚ β”œβ”€β”€ lexer/ # Tokenization
β”‚ β”œβ”€β”€ parser/ # Parsing logic
β”‚ β”œβ”€β”€ cursor.rs # Token stream management
β”‚ └── diagnostics.rs # Error handling
β”œβ”€β”€ tests/ # Unit tests
└── examples/ # Usage examples
```

### Core Parser Files

- **`parser/mod.rs`**: Main parser entry point
- **`parser/statement.rs`**: Statement parsing
- **`parser/expression.rs`**: Expression parsing
- **`parser/typescript.rs`**: TypeScript-specific parsing
- **`parser/jsx.rs`**: JSX parsing logic

## Conformance Testing

### Running Conformance Tests

```bash
just c
```

Aliased to `just coverage`, runs the following conformance test suites by using the conformance runner found in [tasks/coverage](https://github.com/oxc-project/oxc/tree/main/tasks/coverage).
This runs conformance test suites using the runner in [tasks/coverage](https://github.com/oxc-project/oxc/tree/main/tasks/coverage):

### Test262
### Test262 - ECMAScript Conformance

JavaScript has the [ECMAScript Test Suite](https://github.com/tc39/test262) called Test262.
The goal of Test262 is to provide test material that covers every observable behavior specified in the specification.

Parser conformance uses the [parse phase tests](https://github.com/tc39/test262/blob/main/INTERPRETING.md#negative).

### Babel
**Current Status**: `43765/43765 (100.00%)`

### Babel Parser Tests

When new language features are added to JavaScript, it is required to have them implemented by Babel,
this means Babel has another set of [parser tests](https://github.com/babel/babel/tree/main/packages/babel-parser/test).
When new language features are added to JavaScript, Babel implements them first.
Babel has comprehensive [parser tests](https://github.com/babel/babel/tree/main/packages/babel-parser/test) for cutting-edge features.

### TypeScript
**Current Status**: `2093/2101 (99.62%)`

### TypeScript Conformance

The TypeScript conformance tests can be found [here](https://github.com/microsoft/TypeScript/tree/main/tests/cases/conformance).

**Current Status**: `6470/6479 (99.86%)`

### Viewing Results

Test results are stored in snapshot files for tracking changes:

- [`parser_test262.snap`](https://github.com/oxc-project/oxc/blob/main/tasks/coverage/parser_test262.snap)
- [`parser_babel.snap`](https://github.com/oxc-project/oxc/blob/main/tasks/coverage/parser_babel.snap)
- [`parser_typescript.snap`](https://github.com/oxc-project/oxc/blob/main/tasks/coverage/parser_typescript.snap)
Loading