@@ -30,11 +30,12 @@ pub struct CompressOptions {
3030 /// @default true
3131 pub drop_debugger : Option < bool > ,
3232
33- /// Drop unreferenced functions and variables.
33+ /// Pass `true` to drop unreferenced functions and variables.
3434 ///
35- /// Simple direct variable assignments do not count as references unless set to "keep_assign".
36- #[ napi( ts_type = "true | false | 'keep_assign'" ) ]
37- pub unused : Option < String > ,
35+ /// Simple direct variable assignments do not count as references unless set to `keep_assign`.
36+ /// @default true
37+ #[ napi( ts_type = "boolean | 'keep_assign'" ) ]
38+ pub unused : Option < Either < bool , String > > ,
3839
3940 /// Keep function / class names.
4041 pub keep_names : Option < CompressOptionsKeepNames > ,
@@ -69,8 +70,15 @@ impl TryFrom<&CompressOptions> for oxc_minifier::CompressOptions {
6970 drop_debugger : o. drop_debugger . unwrap_or ( default. drop_debugger ) ,
7071 join_vars : o. join_vars . unwrap_or ( true ) ,
7172 sequences : o. sequences . unwrap_or ( true ) ,
72- // TODO
73- unused : oxc_minifier:: CompressOptionsUnused :: Keep ,
73+ unused : match & o. unused {
74+ Some ( Either :: A ( true ) ) => oxc_minifier:: CompressOptionsUnused :: Remove ,
75+ Some ( Either :: A ( false ) ) => oxc_minifier:: CompressOptionsUnused :: Keep ,
76+ Some ( Either :: B ( s) ) => match s. as_str ( ) {
77+ "keep_assign" => oxc_minifier:: CompressOptionsUnused :: KeepAssign ,
78+ _ => return Err ( format ! ( "Invalid unused option: `{s}`." ) ) ,
79+ } ,
80+ None => default. unused ,
81+ } ,
7482 keep_names : o. keep_names . as_ref ( ) . map ( Into :: into) . unwrap_or_default ( ) ,
7583 treeshake : TreeShakeOptions :: default ( ) ,
7684 max_iterations : o. passes ,
0 commit comments