swc_ecma_usage_analyzer/alias/
ctx.rs1use std::ops::{Deref, DerefMut};
2
3use bitflags::bitflags;
4
5use super::InfectionCollector;
6
7impl InfectionCollector {
8 pub(super) fn with_ctx(&mut self, ctx: Ctx) -> WithCtx {
9 let orig_ctx = self.ctx;
10 self.ctx = ctx;
11
12 WithCtx {
13 analyzer: self,
14 orig_ctx,
15 }
16 }
17}
18
19bitflags! {
20 #[derive(Debug, Default, Clone, Copy)]
21 pub struct Ctx: u8 {
22 const TrackExprIdent = 1 << 0;
23 const IsCallee = 1 << 1;
24 const IsPatDecl = 1 << 2;
25 }
26}
27
28pub(super) struct WithCtx<'a> {
29 analyzer: &'a mut InfectionCollector,
30 orig_ctx: Ctx,
31}
32
33impl Deref for WithCtx<'_> {
34 type Target = InfectionCollector;
35
36 fn deref(&self) -> &Self::Target {
37 self.analyzer
38 }
39}
40
41impl DerefMut for WithCtx<'_> {
42 fn deref_mut(&mut self) -> &mut Self::Target {
43 self.analyzer
44 }
45}
46
47impl Drop for WithCtx<'_> {
48 fn drop(&mut self) {
49 self.analyzer.ctx = self.orig_ctx;
50 }
51}