swc/examples/usage.rs
강동윤 c6dce67494
fix(swc): Report error correctly (#2065)
swc_common:
  - Add some utilities for `Handler`.

swc:
 - Remove `Compiler.handler`.
 - Accept `handler` for each operations. (#2035)
2021-08-13 07:05:40 +00:00

31 lines
644 B
Rust

use std::{path::Path, sync::Arc};
use swc::{self, config::Options};
use swc_common::{
errors::{ColorConfig, Handler},
SourceMap,
};
fn main() {
let cm = Arc::<SourceMap>::default();
let handler = Arc::new(Handler::with_tty_emitter(
ColorConfig::Auto,
true,
false,
Some(cm.clone()),
));
let c = swc::Compiler::new(cm.clone());
let fm = cm
.load_file(Path::new("foo.js"))
.expect("failed to load file");
c.process_js_file(
fm,
&handler,
&Options {
..Default::default()
},
)
.expect("failed to process file");
}