fix(es/minifier): Track if a var is used with in (#9508)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/9499
This commit is contained in:
Donny/강동윤 2024-08-28 13:32:45 +09:00 committed by GitHub
parent da529304fe
commit 7d6269e3b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
swc_ecma_usage_analyzer: patch
swc_core: patch
---
fix(es/minifier): Track if a var is used with `in`

View File

@ -11347,6 +11347,19 @@ fn issue_9184_2() {
);
}
#[test]
fn issue_9499() {
run_default_exec_test(
"
const o = {'a': 1, 'b': 2};
function fn() {
return 'a' in o;
}
console.log(fn());
",
)
}
#[test]
fn issue_9356() {
run_default_exec_test("console.log((function ({ } = 42) { }).length)");

View File

@ -340,6 +340,7 @@ where
if e.op == op!("in") {
for_each_id_ref_in_expr(&e.right, &mut |obj| {
let var = self.data.var_or_default(obj.to_id());
var.mark_used_as_ref();
match &*e.left {
Expr::Lit(Lit::Str(prop)) if prop.value.parse::<f64>().is_err() => {