#![feature(box_syntax)] #![feature(box_patterns)] use insta::assert_debug_snapshot; use swc_core::ecma::{ ast::{JSXElement, JSXFragment}, parser::{Syntax, TsConfig}, transforms::testing::Tester, visit::{as_folder, VisitMut}, }; use swc_helper_jsx_transform::shared::Transform; const TSX_SYNTAX: Syntax = Syntax::Typescript(TsConfig { tsx: true, decorators: false, dts: false, no_early_errors: false, }); macro_rules! snapshot { ($name:ident, $value:expr) => { assert_debug_snapshot!(stringify!($name), $value.transform()) }; } macro_rules! test { ($name:ident, $src:literal) => { #[test] fn $name() { struct TransformVisitor; impl VisitMut for TransformVisitor { fn visit_mut_jsx_element(&mut self, element: &mut JSXElement) { snapshot!($name, element) } fn visit_mut_jsx_fragment(&mut self, fragment: &mut JSXFragment) { snapshot!($name, fragment) } } Tester::run(|tester| { tester.apply_transform(as_folder(TransformVisitor), "test.tsx", TSX_SYNTAX, $src) }); } }; ($($name:ident : $src:literal),+ $(,)?) => { $(test!($name,$src);)+ }; ($($mod:ident: { $($name:ident : $src:literal),+ $(,)? }),+ $(,)?) => { $( #[allow(non_snake_case)] mod $mod { use super::*; $(test!($name,$src);)+ } )+ }; } test!( Tag:{ native_div: r#"
"#, extra_component: r#""#, extra_custom: r#""#, extra_member: r#""#, }, AttrKey:{ attr: r#"
"#, event_prefix: r#"
"#, event_namespace: r#"
"#, namespace_attr: r#"
"#, spread: r#"
"#, }, AttrValue:{ lit: r#"
"#, const_undefined: r#"
"#, const_array: r#"
"#, const_obj: r#"
"#, expr: r#"
"#, element: r#"
>"#, element_container: r#"
}>"#, fragment: r#"
>
"#, fragment_container: r#"
}>
"#, empty: r#"
"#, boolean_attribute: r#"
"#, }, Element:{ is_static: r#"
"#, }, Fragment:{ children: r#" <>
"#, }, Text:{ clean_text:r#"
text1
text2
"#, }, );