77 releases (41 breaking)

new 0.41.0 Dec 13, 2024
0.39.0 Dec 4, 2024
0.38.0 Nov 26, 2024
0.22.1 Jul 28, 2024
0.0.1 Mar 30, 2023

#63 in Programming languages

Download history 46439/week @ 2024-08-23 39526/week @ 2024-08-30 36620/week @ 2024-09-06 39557/week @ 2024-09-13 49543/week @ 2024-09-20 56488/week @ 2024-09-27 52918/week @ 2024-10-04 41876/week @ 2024-10-11 18104/week @ 2024-10-18 15474/week @ 2024-10-25 14608/week @ 2024-11-01 16227/week @ 2024-11-08 17331/week @ 2024-11-15 13421/week @ 2024-11-22 14181/week @ 2024-11-29 13145/week @ 2024-12-06

60,961 downloads per month
Used in 17 crates (11 directly)

MIT license

3MB
68K 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 oxc_ast::Visit and oxc_ast::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

~5MB
~89K SLoC