forked from vercel/next.js
/
fixture.rs
61 lines (56 loc) · 1.93 KB
/
fixture.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::path::PathBuf;
use swc_common::{chain, comments::SingleThreadedComments, Mark};
use swc_ecma_transforms_testing::test_fixture;
use swc_ecmascript::parser::{Syntax, TsConfig};
use swc_emotion::EmotionOptions;
use testing::fixture;
fn ts_syntax() -> Syntax {
Syntax::Typescript(TsConfig {
tsx: true,
..Default::default()
})
}
use swc_ecma_transforms_react::{jsx, Runtime};
#[fixture("tests/fixture/**/input.tsx")]
fn next_emotion_fixture(input: PathBuf) {
let output = input.parent().unwrap().join("output.ts");
test_fixture(
ts_syntax(),
&|tr| {
let top_level_mark = Mark::fresh(Mark::root());
let jsx = jsx::<SingleThreadedComments>(
tr.cm.clone(),
Some(tr.comments.as_ref().clone()),
swc_ecmascript::transforms::react::Options {
next: false.into(),
runtime: Some(Runtime::Automatic),
throw_if_namespace: false.into(),
development: false.into(),
use_builtins: true.into(),
use_spread: true.into(),
..Default::default()
},
top_level_mark,
);
let test_import_map =
serde_json::from_str(include_str!("./testImportMap.json")).unwrap();
chain!(
swc_emotion::emotion(
EmotionOptions {
enabled: Some(true),
sourcemap: Some(true),
auto_label: Some(true),
import_map: Some(test_import_map),
..Default::default()
},
&PathBuf::from("input.ts"),
tr.cm.clone(),
tr.comments.as_ref().clone(),
),
jsx
)
},
&input,
&output,
);
}