Skip to content

Commit

Permalink
fix corner case in unused (#5101)
Browse files Browse the repository at this point in the history
fixes #5100
  • Loading branch information
alexlamsl committed Jul 26, 2021
1 parent 657d525 commit 9b82f9b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7301,12 +7301,11 @@ merge(Compressor.prototype, {
if (value === null) {
value = make_node(AST_Number, node, { value: 0 });
} else if (value) {
if (value.may_throw_on_access(compressor, true)) value = make_sequence(node, [
value,
make_node(AST_Number, node, { value: 0 }),
]);
} else if (node instanceof AST_DestructuredArray) {
return make_node(AST_DestructuredArray, node, { elements: [] });
if (value.tail_node().write_only === true || value.may_throw_on_access(compressor, true)) {
value = make_node(AST_Array, node, {
elements: value instanceof AST_Sequence ? value.expressions : [ value ],
});
}
}
return make_node(AST_DestructuredObject, node, { properties: [] });
}
Expand Down
66 changes: 66 additions & 0 deletions test/compress/rests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,3 +1003,69 @@ issue_5089_2: {
expect_stdout: "undefined"
node_version: ">=8"
}

issue_5100_1: {
options = {
passes: 2,
pure_getters: "strict",
side_effects: true,
unused: true,
}
input: {
var a;
[ {
p: {},
...a
} ] = [ {
p: {
q: a,
} = 42,
r: "PASS",
} ];
console.log(a.r);
}
expect: {
var a;
[ {
p: {},
...a
} ] = [ {
p: [ a = 42["q"] ],
r: "PASS",
} ];
console.log(a.r);
}
expect_stdout: "PASS"
node_version: ">=8"
}

issue_5100_2: {
options = {
passes: 2,
pure_getters: "strict",
side_effects: true,
unused: true,
}
input: {
var a;
[ {
p: {},
...a
} ] = [ {
p: (console.log("PASS"), {
q: a,
} = 42),
} ];
}
expect: {
var a;
[ {
p: {},
...a
} ] = [ {
p: [ console.log("PASS"), a = 42["q"] ],
} ];
}
expect_stdout: "PASS"
node_version: ">=10"
}

0 comments on commit 9b82f9b

Please sign in to comment.