Skip to content

Commit

Permalink
fix corner case in unused (#3496)
Browse files Browse the repository at this point in the history
fixes #3495
  • Loading branch information
alexlamsl committed Oct 18, 2019
1 parent 0785a15 commit cd07231
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/compress.js
Expand Up @@ -3629,6 +3629,7 @@ merge(Compressor.prototype, {
return !(def.id in in_use_ids) || def.orig.length > 1;
};
// pass 3: we should drop declarations not in_use
var unused_fn_names = [];
var tt = new TreeTransformer(function(node, descend, in_list) {
var parent = tt.parent();
if (drop_vars) {
Expand Down Expand Up @@ -3656,7 +3657,7 @@ merge(Compressor.prototype, {
}
if (scope !== self) return;
if (node instanceof AST_Function && node.name && drop_fn_name(node.name.definition())) {
node.name = null;
unused_fn_names.push(node);
}
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
var trim = compressor.drop_fargs(node, parent);
Expand Down Expand Up @@ -3853,6 +3854,9 @@ merge(Compressor.prototype, {
});
tt.push(compressor.parent());
self.transform(tt);
unused_fn_names.forEach(function(fn) {
fn.name = null;
});

function verify_safe_usage(def, read, modified) {
if (def.id in in_use_ids) return;
Expand Down
19 changes: 19 additions & 0 deletions test/compress/drop-unused.js
Expand Up @@ -2062,3 +2062,22 @@ issue_3427_2: {
}
expect_stdout: "PASS"
}

issue_3495: {
options = {
dead_code: true,
pure_getters: "strict",
side_effects: true,
unused: true,
}
input: {
console.log(function f() {
f = 0;
var a = f.p;
}());
}
expect: {
console.log(void 0);
}
expect_stdout: "undefined"
}

0 comments on commit cd07231

Please sign in to comment.