quickjs-parse 0.9.0

ECMAScript 2025 lexer, AST and parser for the pure-Rust QuickJS port
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
//! The example in README.md, kept compilable so the two cannot drift.
use js_parse::{ast::StmtKind, parse_script};

fn main() -> Result<(), js_parse::ParseError> {
    let program = parse_script("var x = 1 + 2;")?;
    for stmt in &program.body {
        if let StmtKind::VarDecl(decl) = &stmt.kind {
            assert_eq!(decl.declarators.len(), 1);
        }
    }
    println!("{} statement(s)", program.body.len());
    Ok(())
}