parse/parse.rs
1//! The example in README.md, kept compilable so the two cannot drift.
2use js_parse::{ast::StmtKind, parse_script};
3
4fn main() -> Result<(), js_parse::ParseError> {
5 let program = parse_script("var x = 1 + 2;")?;
6 for stmt in &program.body {
7 if let StmtKind::VarDecl(decl) = &stmt.kind {
8 assert_eq!(decl.declarators.len(), 1);
9 }
10 }
11 println!("{} statement(s)", program.body.len());
12 Ok(())
13}