Skip to content

Commit 6686cc4

Browse files
committed
fix(minifier): do not remove using x = (#13052)
fixes #13050
1 parent 92a3550 commit 6686cc4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

crates/oxc_ast/src/ast_impl/js.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,11 @@ impl VariableDeclarationKind {
11691169
matches!(self, Self::Const | Self::Let | Self::Using | Self::AwaitUsing)
11701170
}
11711171

1172+
/// Returns `true` if declared with `using` (such as `using x` or `await using x`)
1173+
pub fn is_using(self) -> bool {
1174+
self == Self::Using || self == Self::AwaitUsing
1175+
}
1176+
11721177
/// Returns `true` if declared using `await using` (such as `await using x`)
11731178
pub fn is_await(self) -> bool {
11741179
self == Self::AwaitUsing

crates/oxc_minifier/src/peephole/remove_unused_declaration.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ impl<'a> PeepholeOptimizations {
1313
return false;
1414
}
1515
if let BindingPatternKind::BindingIdentifier(ident) = &decl.id.kind {
16+
// Unsafe to remove `using`, unable to statically determine usage of [Symbol.dispose].
17+
if decl.kind.is_using() {
18+
return false;
19+
}
1620
if Self::keep_top_level_var_in_script_mode(ctx) {
1721
return false;
1822
}
@@ -97,6 +101,8 @@ mod test {
97101
test_options("var x = foo", "foo", &options);
98102
test_same_options("var x; foo(x)", &options);
99103
test_same_options("export var x", &options);
104+
test_same_options("using x = foo", &options);
105+
test_same_options("await using x = foo", &options);
100106
}
101107

102108
#[test]

0 commit comments

Comments
 (0)