swc_coverage_instrument/macros/
visit_mut_for_like.rs

1/// A macro creates body for the for-variant visitors (for, for-of, for-in) which
2/// shares same logic. This also works for other loops like while, do-while.
3#[macro_export]
4macro_rules! visit_mut_for_like {
5    ($self: ident, $for_like_stmt: ident) => {
6        let (old, ignore_current) = $self.on_enter($for_like_stmt);
7
8        match ignore_current {
9            Some(crate::hint_comments::IgnoreScope::Next) => {}
10            _ => {
11                // cover_statement's is_stmt prepend logic for individual child stmt visitor
12                $self.mark_prepend_stmt_counter(&$for_like_stmt.span);
13
14                let body = *$for_like_stmt.body.take();
15                // if for stmt body is not block, wrap it before insert statement counter
16                let body = if let Stmt::Block(body) = body {
17                    body
18                } else {
19                    let stmts = vec![body];
20                    BlockStmt {
21                        span: swc_core::common::DUMMY_SP,
22                        stmts,
23                        ..Default::default()
24                    }
25                };
26
27                $for_like_stmt.body = Box::new(Stmt::Block(body));
28                // Iterate children for inner stmt's counter insertion
29                $for_like_stmt.visit_mut_children_with($self);
30            }
31        }
32
33        $self.on_exit(old);
34    };
35}