swc/crates/swc_ecma_parser/tests/visitor.rs
Donny/강동윤 e48263b2f3
refactor(visit): Remove &dyn Node from Visit ()
swc_visit_macros:
 - Remove `&dyn Node` from `Visit`.
 - Implement `VisitWith<V>` for `[T]`.
2021-12-07 14:34:16 +09:00

38 lines
872 B
Rust

use swc_common::{input::StringInput, FileName};
use swc_ecma_ast::*;
use swc_ecma_parser::{lexer::Lexer, Parser};
use swc_ecma_visit::{All, VisitAll, VisitWith};
struct Issue1967;
impl VisitAll for Issue1967 {
fn visit_expr(&mut self, _: &Expr) {
panic!("intended")
}
}
#[test]
#[should_panic = "intended"]
fn issue_1967() {
testing::run_test2(false, |cm, _handler| {
let fm = cm.new_source_file(FileName::Anon, "function foo(){ return 'I'; }".to_string());
let lexer = Lexer::new(
Default::default(),
EsVersion::latest(),
StringInput::from(&*fm),
None,
);
let mut parser = Parser::new_from(lexer);
let m = parser.parse_module().unwrap();
m.visit_with(&mut All {
visitor: Issue1967 {},
});
Ok(())
})
.unwrap();
}