Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,11 @@ impl VariableDeclarationKind {
matches!(self, Self::Const | Self::Let | Self::Using | Self::AwaitUsing)
}

/// Returns `true` if declared with `using` (such as `using x` or `await using x`)
pub fn is_using(self) -> bool {
self == Self::Using || self == Self::AwaitUsing
}

/// Returns `true` if declared using `await using` (such as `await using x`)
pub fn is_await(self) -> bool {
self == Self::AwaitUsing
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_minifier/src/peephole/remove_unused_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ impl<'a> PeepholeOptimizations {
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 Self::keep_top_level_var_in_script_mode(ctx) {
return false;
}
Expand Down Expand Up @@ -97,6 +101,8 @@ mod test {
test_options("var x = foo", "foo", &options);
test_same_options("var x; foo(x)", &options);
test_same_options("export var x", &options);
test_same_options("using x = foo", &options);
test_same_options("await using x = foo", &options);
}

#[test]
Expand Down
Loading