Files
overlookmotel 2c9a947363 feat(parser)!: reduce MAX_LEN to 256 bytes below u32::MAX (#26352)
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.
2026-09-05 15:33:52 +00:00
..

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

  1. AST Traversal: Walk through AST nodes systematically
  2. Token Generation: Convert nodes to appropriate tokens/strings
  3. Formatting: Apply whitespace, indentation, and style rules
  4. 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.