Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(swc_visit): 🐛 visit program in AndThen
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use swc_common::{chain, DUMMY_SP}; | ||
use swc_ecma_ast::{Module, Program}; | ||
use swc_ecma_visit::{Visit, VisitWith}; | ||
|
||
#[test] | ||
fn should_visit_program() { | ||
struct Pass1<'a>(&'a mut usize); | ||
struct Pass2; | ||
|
||
impl<'a> Visit for Pass1<'a> { | ||
fn visit_program(&mut self, _program: &Program) { | ||
*self.0 += 1; | ||
} | ||
} | ||
|
||
impl Visit for Pass2 {} | ||
|
||
let n = Program::Module(Module { | ||
span: DUMMY_SP, | ||
body: vec![], | ||
shebang: None, | ||
}); | ||
|
||
let mut counter = 0; | ||
let p1 = Pass1(&mut counter); | ||
let p2 = Pass2; | ||
let mut pass = chain!(p1, p2); | ||
n.visit_with(&mut pass); | ||
|
||
assert_eq!(counter, 1); | ||
} |