Skip to content

Instantly share code, notes, and snippets.

@UltiRequiem
Created January 27, 2022 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UltiRequiem/968e64b752256a9bf7af7cf5b62e1aac to your computer and use it in GitHub Desktop.
Save UltiRequiem/968e64b752256a9bf7af7cf5b62e1aac to your computer and use it in GitHub Desktop.
Got swc working for tsx, pogs
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