Skip to content

Commit

Permalink
fix(es/minifier): Track if a var is used with in (#9508)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9499
  • Loading branch information
kdy1 committed Aug 28, 2024
1 parent da52930 commit 7d6269e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/sour-pumpkins-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_usage_analyzer: patch
swc_core: patch
---

fix(es/minifier): Track if a var is used with `in`
13 changes: 13 additions & 0 deletions crates/swc_ecma_minifier/tests/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down

0 comments on commit 7d6269e

Please sign in to comment.