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 expect the above two
- SIMD is used for skipping whitespace and multiline comments
- [oxc_ast::Span] offsets uses
u32
instead ofusize
- Scope binding, symbol resolution and complicated syntax errors are not done in the parser, they are deligated 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
Babel Summary:
AST Parsed : 2065/2071
TypeScript Summary:
AST Parsed : 2337/2337
Usage
The parser has a minimal API with three inputs and one return struct ([ParserReturn]).
let parser_return = new.parse;
Example
https://github.com/Boshen/oxc/blob/main/crates/oxc_parser/examples/parser.rs
Visitor
See [oxc_ast::visit::Visit] and [oxc_ast::visit_mut::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