#![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#"