swc/crates/swc_ecma_transforms_testing/tests/visited.rs
Donny/강동윤 0259a7465f
build(cargo): Update rustc to nightly-2023-03-20 (#7170)
**Description:**

This PR also updates `rkyv` to `=0.7.40`.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6807.
2023-03-30 08:06:02 +00:00

41 lines
960 B
Rust

use swc_ecma_ast::*;
use swc_ecma_parser::{EsConfig, Syntax};
use swc_ecma_transforms_testing::test_transform;
use swc_ecma_visit::Fold;
struct Panicking;
impl Fold for Panicking {
fn fold_jsx_opening_element(&mut self, node: JSXOpeningElement) -> JSXOpeningElement {
let JSXOpeningElement { name, .. } = &node;
println!("HMM");
if let JSXElementName::Ident(Ident { sym, .. }) = name {
panic!("visited: {}", sym)
}
node
}
}
#[test]
#[should_panic = "visited"]
fn ensure_visited() {
test_transform(
Syntax::Es(EsConfig {
jsx: true,
..Default::default()
}),
|_| Panicking,
"
import React from 'react';
const comp = () => <amp-something className='something' />;
",
"
import React from 'react';
const comp = () => <amp-something className='something' />;
",
false,
);
}