-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
lib.rs
29 lines (25 loc) · 873 Bytes
/
lib.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
#![allow(clippy::not_unsafe_ptr_arg_deref)]
#![feature(box_patterns)]
use styled_jsx::{visitor, visitor::Config};
use swc_core::{
common::{sync::Lrc, FileName, SourceMap},
ecma::{ast::Program, visit::FoldWith},
plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
};
#[plugin_transform]
fn styled_jsx_plugin(program: Program, data: TransformPluginProgramMetadata) -> Program {
let config = serde_json::from_str::<Config>(
&data
.get_transform_plugin_config()
.expect("failed to get plugin config for styled-jsx"),
)
.expect("invalid config for styled-jsx");
// TODO(kdy1): This is wrong, but it does not use cm
let cm = Lrc::new(SourceMap::default());
program.fold_with(&mut visitor::styled_jsx(
cm,
FileName::Anon,
config,
Default::default(),
))
}