Created
January 27, 2022 00:56
-
-
Save UltiRequiem/968e64b752256a9bf7af7cf5b62e1aac to your computer and use it in GitHub Desktop.
Got swc working for tsx, pogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{path::Path, sync::Arc}; | |
use swc::{ | |
self, | |
config::{JscConfig, Options}, | |
}; | |
use swc_common::{ | |
errors::{ColorConfig, Handler}, | |
SourceMap, | |
}; | |
fn main() { | |
let cm = Arc::<SourceMap>::default(); | |
let fm = cm | |
.load_file(Path::new("typescript.tsx")) | |
.expect("failed to load file"); | |
let handler = Arc::new(Handler::with_tty_emitter( | |
ColorConfig::Auto, | |
true, | |
false, | |
Some(cm.clone()), | |
)); | |
let c = swc::Compiler::new(cm.clone()); | |
let output = c | |
.process_js_file( | |
fm, | |
&handler, | |
&Options { | |
config: swc::config::Config { | |
jsc: JscConfig { | |
syntax: Some(swc_ecma_parser::Syntax::Typescript( | |
swc_ecma_parser::TsConfig { | |
tsx: true, | |
..Default::default() | |
}, | |
)), | |
..Default::default() | |
}, | |
..Default::default() | |
}, | |
..Default::default() | |
}, | |
) | |
.expect("failed to process file"); | |
println!("{:#?}", output.code); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment