Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions crates/oxc_minifier/src/peephole/remove_unused_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ impl<'a> PeepholeOptimizations {
if !Self::can_remove_unused_declarators(ctx) {
return false;
}
if let BindingPatternKind::BindingIdentifier(ident) = &decl.id.kind {
// Unsafe to remove `using`, unable to statically determine usage of [Symbol.dispose].
if decl.kind.is_using() {
return false;
}
if let Some(symbol_id) = ident.symbol_id.get() {
return ctx.scoping().symbol_is_unused(symbol_id);
// Unsafe to remove `using`, unable to statically determine usage of [Symbol.dispose].
if decl.kind.is_using() {
return false;
}
match &decl.id.kind {
BindingPatternKind::BindingIdentifier(ident) => {
if let Some(symbol_id) = ident.symbol_id.get() {
return ctx.scoping().symbol_is_unused(symbol_id);
}
false
}
BindingPatternKind::ArrayPattern(ident) => ident.is_empty(),
BindingPatternKind::ObjectPattern(ident) => ident.is_empty(),
BindingPatternKind::AssignmentPattern(_) => false,
}
false
}

pub fn remove_unused_variable_declaration(
Expand Down Expand Up @@ -117,6 +122,13 @@ mod test {
test_options("var x", "", &options);
test_options("var x = 1", "", &options);
test_options("var x = foo", "foo", &options);
test_options("var [] = []", "", &options);
test_options("var [] = [1]", "", &options);
test_options("var [] = [foo]", "foo", &options);
test_options("var {} = {}", "", &options);
test_options("var {} = { a: 1 }", "", &options);
test_options("var {} = { foo }", "foo", &options);
test_options("var {} = { foo: { a } }", "a", &options);
test_same_options("var x; foo(x)", &options);
test_same_options("export var x", &options);
test_same_options("using x = foo", &options);
Expand Down
Loading