mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
2c9a947363
Technically a breaking change, but one that's extremely unlikely to affect any real-world applications. On 64-bit systems, the maximum source text length was exactly `u32::MAX`. Lower it by 256 bytes, for 2 reasons: 1. `oxc_lexer` will require source text to be followed by 64 bytes of padding. Reducing max source length ensures _padded_ length can always fit in a `u32`. 2. Counts of tokens, comments and errors are all bounded by source length plus a small constant. By reducing max source length, these can all be stored as `u32`s without any possibility of overflow. `oxc_lexer` only needs 64 bytes of padding. Have gone with 256 to leave headroom in case later redesigns require more than 64. This avoids another breaking change later. We can always switch to 64 later on if we want, and this later relaxation would not be a breaking change. All the changes to other crates in this PR are just updating comments which talk about max source length.
Oxc Codegen
High-performance code generation from AST back to JavaScript/TypeScript source code.
Overview
This crate converts AST nodes back into source code strings, supporting JavaScript, TypeScript, and JSX. It's designed for speed and correctness, producing clean, readable output.
Key Features
- Fast code generation: Optimized for performance with minimal allocations
- Source map support: Generate accurate source maps during output
- Configurable formatting: Control whitespace, semicolons, and other formatting options
- Comment preservation: Maintain comments during code generation
- Binary expression optimization: Intelligent parentheses insertion
Architecture
Code Generation Pipeline
- AST Traversal: Walk through AST nodes systematically
- Token Generation: Convert nodes to appropriate tokens/strings
- Formatting: Apply whitespace, indentation, and style rules
- Source Mapping: Track original source positions if enabled
Design Principles
- Correctness: Generated code must be functionally equivalent to original
- Performance: Minimize string allocations and copying
- Readability: Produce clean, well-formatted output
- Fidelity: Preserve semantic meaning and behavior
The codegen is adapted from esbuild's approach, optimized for Rust and oxc's AST structure.