108 releases (61 breaking)

Uses new Rust 2024

0.61.2 Mar 23, 2025
0.60.0 Mar 18, 2025
0.44.0 Dec 25, 2024
0.38.0 Nov 26, 2024
0.0.1 Mar 30, 2023

#427 in Programming languages

Download history 15293/week @ 2024-12-08 14668/week @ 2024-12-15 7107/week @ 2024-12-22 10015/week @ 2024-12-29 15757/week @ 2025-01-05 15344/week @ 2025-01-12 14951/week @ 2025-01-19 14794/week @ 2025-01-26 17497/week @ 2025-02-02 22218/week @ 2025-02-09 20439/week @ 2025-02-16 20079/week @ 2025-02-23 21705/week @ 2025-03-02 21654/week @ 2025-03-09 23528/week @ 2025-03-16 20798/week @ 2025-03-23

89,225 downloads per month
Used in 41 crates (15 directly)

MIT license

3.5MB
65K SLoC

Oxc Parser for JavaScript and TypeScript

Oxc's Parser has full support for

Usage

The parser has a minimal API with three inputs (a memory arena, a source string, and a SourceType) and one return struct (a [ParserReturn]).

let parser_return = Parser::new(&allocator, &source_text, source_type).parse();

Abstract Syntax Tree (AST)

Oxc's AST is located in a separate oxc_ast crate. You can find type definitions for AST nodes here.

Performance

The following optimization techniques are used:

  • AST is allocated in a memory arena (bumpalo) for fast AST drop
  • oxc_span::Span offsets uses u32 instead of usize
  • Scope binding, symbol resolution and complicated syntax errors are not done in the parser, they are delegated to the semantic analyzer
Because [`oxc_span::Span`] uses `u32` instead of `usize`, Oxc can only parse files up to 4 GiB in size. This shouldn't be a limitation in almost all cases.

Examples

https://github.com/oxc-project/oxc/blob/main/crates/oxc_parser/examples/parser.rs

Parsing TSX

Visitor

See Visit and VisitMut.

Visiting without a visitor

For ad-hoc tasks, the semantic analyzer can be used to get a parent pointing tree with untyped nodes, the nodes can be iterated through a sequential loop.

for node in semantic.nodes().iter() {
    match node.kind() {
        // check node
    }
}

See full linter example

Dependencies

~6MB
~99K SLoC