-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathoptions.rs
More file actions
89 lines (76 loc) · 2.1 KB
/
Copy pathoptions.rs
File metadata and controls
89 lines (76 loc) · 2.1 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use oxc_syntax::es_target::ESTarget;
#[derive(Debug, Clone, Copy)]
pub struct CompressOptions {
/// Set desired EcmaScript standard version for output.
///
/// e.g.
///
/// * catch optional binding when >= es2019
/// * `??` operator >= es2020
///
/// Default `ESTarget::ESNext`
pub target: ESTarget,
/// Keep function / class names.
pub keep_names: CompressOptionsKeepNames,
/// Remove `debugger;` statements.
///
/// Default `true`
pub drop_debugger: bool,
/// Remove `console.*` statements.
///
/// Default `false`
pub drop_console: bool,
}
#[expect(clippy::derivable_impls)]
impl Default for CompressOptions {
fn default() -> Self {
Self { drop_console: false, ..Self::smallest() }
}
}
impl CompressOptions {
pub fn smallest() -> Self {
Self {
target: ESTarget::ESNext,
keep_names: CompressOptionsKeepNames::all_false(),
drop_debugger: true,
drop_console: true,
}
}
pub fn safest() -> Self {
Self {
target: ESTarget::ESNext,
keep_names: CompressOptionsKeepNames::all_true(),
drop_debugger: false,
drop_console: false,
}
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct CompressOptionsKeepNames {
/// Keep function names so that `Function.prototype.name` is preserved.
///
/// This does not guarantee that the `undefined` name is preserved.
///
/// Default `false`
pub function: bool,
/// Keep class names so that `Class.prototype.name` is preserved.
///
/// This does not guarantee that the `undefined` name is preserved.
///
/// Default `false`
pub class: bool,
}
impl CompressOptionsKeepNames {
pub fn all_false() -> Self {
Self { function: false, class: false }
}
pub fn all_true() -> Self {
Self { function: true, class: true }
}
pub fn function_only() -> Self {
Self { function: true, class: false }
}
pub fn class_only() -> Self {
Self { function: false, class: true }
}
}