/
transform.rs
37 lines (32 loc) · 1.03 KB
/
transform.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::{path::Path, sync::Arc};
use anyhow::Context;
use swc::{self, config::Options, try_with_handler, HandlerOpts};
use swc_common::{SourceMap, GLOBALS};
fn main() {
let cm = Arc::<SourceMap>::default();
let c = swc::Compiler::new(cm.clone());
let output = GLOBALS
.set(&Default::default(), || {
try_with_handler(
cm.clone(),
HandlerOpts {
..Default::default()
},
|handler| {
let fm = cm
.load_file(Path::new("examples/transform-input.js"))
.expect("failed to load file");
c.process_js_file(
fm,
handler,
&Options {
..Default::default()
},
)
.context("failed to process file")
},
)
})
.unwrap();
println!("{}", output.code);
}