Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .changeset/swc-args-destructure-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_minifier: patch
---

fix(es/minifier): mark destructured `let`/`const` bindings as having unknown param count
10 changes: 10 additions & 0 deletions crates/swc_ecma_minifier/src/usage_analyzer/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,16 @@ where
.var_or_default(var.id.to_id())
.store_param_count(Value::Unknown),
}
} else if !matches!(&decl.name, Pat::Ident(_)) {
// Destructuring binding (object/array/rest pattern). The
// bound identifiers are read from runtime properties or
// elements, so we cannot statically determine the arity
// of any callable that reaches them.
for id in find_pat_ids::<_, Id>(&decl.name) {
self.data
.var_or_default(id)
.store_param_count(Value::Unknown);
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/11829/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"unused": true,
"reduce_vars": false,
"reduce_funcs": false,
"inline": false,
"evaluate": false,
"collapse_vars": false,
"side_effects": false,
"keep_fargs": true,
"passes": 1,
"toplevel": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function run(opts) {
let { match } = opts;
if (!match) match = () => true;
return match("hello", "world");
}

console.log(run({ match: (a, b) => a + " " + b }));
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function run(opts) {
let { match } = opts;
if (!match) match = ()=>true;
return match("hello", "world");
}
console.log(run({
match: (a, b)=>a + " " + b
}));
Loading