1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use stc_utils::cache::Freeze;
use stc_visit::{VisitMut, VisitMutWith};
use swc_common::util::take::Take;
use triomphe::Arc;

use crate::{private::Freezed, ArcCow};

pub struct Freezer;

impl<T> VisitMut<ArcCow<T>> for Freezer
where
    T: Take + Freeze,
    ArcCow<T>: VisitMutWith<Self>,
{
    fn visit_mut(&mut self, n: &mut ArcCow<T>) {
        match n {
            ArcCow::Arc(_) => (),
            ArcCow::Owned(v) => {
                // Deep
                (**v).freeze();
                let v = (**v).take();

                *n = ArcCow::Arc(Freezed(Arc::new(v)))
            }
        }
    }
}