mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
c6dce67494
swc_common: - Add some utilities for `Handler`. swc: - Remove `Compiler.handler`. - Accept `handler` for each operations. (#2035)
31 lines
644 B
Rust
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");
|
|
}
|