12 releases
0.2.0 | Sep 14, 2023 |
---|---|
0.1.3 | Sep 3, 2023 |
0.1.1 | Aug 26, 2023 |
0.1.0 | Jul 27, 2023 |
0.0.1 | Mar 30, 2023 |
#1436 in Web programming
324 downloads per month
Used in 6 crates
785KB
19K
SLoC
Oxc Parser
Parser Conformance
The cargo coverage
command reports the following conformance summary
Test262 Summary:
AST Parsed : 44000/44000 (100.00%)
Positive Passed: 44000/44000 (100.00%)
Negative Passed: 3915/3915 (100.00%)
Babel Summary:
AST Parsed : 2065/2071 (99.71%)
Positive Passed: 2062/2071 (99.57%)
Negative Passed: 1332/1502 (88.68%)
TypeScript Summary:
AST Parsed : 2337/2337 (100.00%)
Positive Passed: 2331/2337 (99.74%)
Negative Passed: 673/2535 (26.55%)
Only some stage 3 are skipped.
lib.rs
:
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 ofusize
- 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
}
}
Dependencies
~4–15MB
~176K SLoC