swc_css_minifier/compressor/
time.rs

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
28
29
30
31
32
33
34
35
36
37
38
39
use swc_css_ast::*;

use super::Compressor;

impl Compressor {
    pub(super) fn compress_time(&self, time: &mut Time) {
        match &*time.unit.value {
            "ms" if time.value.value == 0.0 || time.value.value >= 100.0 => {
                let new_value = time.value.value / 1000.0;

                time.value = Number {
                    span: time.value.span,
                    value: new_value,
                    raw: None,
                };
                time.unit = Ident {
                    span: time.unit.span,
                    value: "s".into(),
                    raw: None,
                };
            }
            "s" if time.value.value > 0.0 && time.value.value < 0.1 => {
                let new_value = time.value.value * 1000.0;

                time.value = Number {
                    value: new_value,
                    raw: None,
                    span: time.span,
                };
                time.unit = Ident {
                    span: time.unit.span,
                    value: "ms".into(),
                    raw: None,
                };
            }
            _ => {}
        }
    }
}