89 releases (50 breaking)
new 0.50.0 | Feb 12, 2025 |
---|---|
0.48.2 | Feb 2, 2025 |
0.44.0 | Dec 25, 2024 |
0.38.0 | Nov 26, 2024 |
0.0.1 | Mar 30, 2023 |
#15 in Programming languages
63,042 downloads per month
Used in 35 crates
(12 directly)
3MB
65K
SLoC
Oxc Parser for JavaScript and TypeScript
Oxc's Parser
has full support for
- The latest stable ECMAScript syntax
- TypeScript
- JSX and TSX
- Stage 3 Decorators
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 usesu32
instead ofusize
- Scope binding, symbol resolution and complicated syntax errors are not done in the parser, they are delegated to the semantic analyzer
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
}
}
Dependencies
~6MB
~99K SLoC