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
16 changes: 15 additions & 1 deletion crates/swc_ecma_minifier/src/usage_analyzer/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,13 @@ where
n.visit_children_with(&mut *self.with_ctx(ctx));

for decl in &n.decls {
if let (Pat::Ident(var), Some(init)) = (&decl.name, decl.init.as_deref()) {
let init = if let Some(init) = decl.init.as_deref() {
init
} else {
continue;
};

if let Pat::Ident(var) = &decl.name {
let mut v = None;
for id in collect_infects_from(
init,
Expand Down Expand Up @@ -1513,6 +1519,14 @@ where
.var_or_default(var.id.to_id())
.store_param_count(Value::Unknown),
}
} else {
// Destructuring pulls values from an external object or iterable, so the
// callable arity of each binding is not known from this declaration.
for id in find_pat_ids(&decl.name) {
self.data
.var_or_default(id)
.store_param_count(Value::Unknown);
Comment on lines +1522 to +1528
Comment on lines +1522 to +1528
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/11829/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function run(options) {
let { cb } = options;
if (!cb) {
cb = () => true;
}
return cb("value");
}

run({
cb(value) {
if (value === undefined) {
throw new Error("missing argument");
}
console.log("PASS");
return true;
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!function(options) {
let { cb } = options;
cb || (cb = ()=>!0), cb("value");
}({
cb (value) {
if (void 0 === value) throw Error("missing argument");
return console.log("PASS"), !0;
}
});
Loading