25 releases (12 breaking)

new 0.12.3 Apr 11, 2024
0.11.1 Apr 3, 2024
0.11.0 Mar 30, 2024
0.4.0 Dec 8, 2023
0.0.1 Mar 30, 2023

#1128 in Programming languages

Download history 154/week @ 2023-12-23 99/week @ 2023-12-30 48/week @ 2024-01-06 94/week @ 2024-01-13 123/week @ 2024-01-20 284/week @ 2024-01-27 524/week @ 2024-02-03 227/week @ 2024-02-10 420/week @ 2024-02-17 431/week @ 2024-02-24 563/week @ 2024-03-02 1204/week @ 2024-03-09 2002/week @ 2024-03-16 1992/week @ 2024-03-23 2893/week @ 2024-03-30 2566/week @ 2024-04-06

9,667 downloads per month
Used in 11 crates (9 directly)

MIT license

1MB
25K SLoC

Oxc Parser for JavaScript and TypeScript

Performance

The following optimization techniques are used:

  • AST is allocated in a memory arena (bumpalo) for fast AST drop
  • Short strings are inlined by CompactString
  • No other heap allocations are done except the above two
  • 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

Conformance

The parser parses all of Test262 and most of Babel and TypeScript parser conformance tests.

See oxc coverage for details

Test262 Summary:
AST Parsed     : 44000/44000 (100.00%)

Babel Summary:
AST Parsed     : 2065/2071 (99.71%)

TypeScript Summary:
AST Parsed     : 2337/2337 (100.00%)

Usage

The parser has a minimal API with three inputs and one return struct ([ParserReturn]).

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

Example

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

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

~4–12MB
~98K SLoC