#![feature(bench_black_box)] #![deny(warnings)] extern crate swc_node_base; use std::{env, hint::black_box, path::PathBuf, time::Instant}; use swc_common::{errors::HANDLER, GLOBALS}; use swc_ecma_parser::parse_file_as_module; use walkdir::WalkDir; fn main() { let dirs = env::args().skip(1).collect::>(); let files = expand_dirs(dirs); eprintln!("Using {} files", files.len()); let start = Instant::now(); testing::run_test2(false, |cm, handler| { GLOBALS.with(|globals| { HANDLER.set(&handler, || { let _ = files .into_iter() .map(|path| -> Result<(), ()> { GLOBALS.set(globals, || { let fm = cm.load_file(&path).expect("failed to load file"); let program = parse_file_as_module( &fm, Default::default(), Default::default(), None, &mut vec![], ) .map_err(|err| { err.into_diagnostic(&handler).emit(); }) .unwrap(); black_box(program); Ok(()) }) }) .collect::>(); Ok(()) }) }) }) .unwrap(); eprintln!("Took {:?}", start.elapsed()); } /// Return the whole input files as abolute path. fn expand_dirs(dirs: Vec) -> Vec { dirs.into_iter() .map(PathBuf::from) .map(|dir| dir.canonicalize().unwrap()) .flat_map(|dir| { WalkDir::new(dir) .into_iter() .filter_map(Result::ok) .filter_map(|entry| { if entry.metadata().map(|v| v.is_file()).unwrap_or(false) { Some(entry.into_path()) } else { None } }) .filter(|path| path.extension().map(|ext| ext == "js").unwrap_or(false)) .collect::>() }) .collect() }