Skip to content

Commit

Permalink
fix corner case in unused
Browse files Browse the repository at this point in the history
fixes #5843
  • Loading branch information
alexlamsl committed Jun 16, 2024
1 parent 0934c0e commit cb56ae1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -8284,6 +8284,7 @@ Compressor.prototype.compress = function(node) {
if (prop instanceof AST_Spread) return prop;
var key = prop_keys[index];
if (key instanceof AST_Node) return prop;
if (key === "__proto__") return prop;
if (drop_keys.has(key)) {
var mapped = drop_keys.get(key);
if (!mapped) return prop;
Expand Down Expand Up @@ -8317,7 +8318,10 @@ Compressor.prototype.compress = function(node) {
if (value.has_side_effects(compressor) && prop.value.match_symbol(function(node) {
return node instanceof AST_PropAccess;
})) break;
value = make_node(AST_Sub, node, {
value = is_identifier_string(prop.key) ? make_node(AST_Dot, node, {
expression: value,
property: prop.key,
}) : make_node(AST_Sub, node, {
expression: value,
property: make_node_from_constant(prop.key, prop),
});
Expand Down
55 changes: 53 additions & 2 deletions test/compress/destructured.js
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ side_effects_object: {
}
}
expect: {
var a = null, c = (console, 42["c"]);
var a = null, c = (console, 42..c);
try {
c[a = "PASS"];
} catch (e) {
Expand Down Expand Up @@ -1684,7 +1684,7 @@ singleton_1: {
expect: {
var b, a = "P"[0], o = {};
o.p = [ "FAIL"["1"] ][0];
o.q = { foo: "S"[0] }["foo"];
o.q = { foo: "S"[0] }.foo;
[ b = "S" ] = [];
console.log(a + o.p + o.q + b);
}
Expand Down Expand Up @@ -3886,3 +3886,54 @@ issue_5651: {
expect_stdout: true
node_version: ">=6"
}

issue_5843_1: {
options = {
unused: true,
}
input: {
var { p: a } = {
__proto__: {
p: "PASS",
},
};
console.log(a);
}
expect: {
var a = {
__proto__: {
p: "PASS",
},
}.p;
console.log(a);
}
expect_stdout: "PASS"
node_version: ">=6"
}

issue_5843_2: {
options = {
side_effects: true,
unused: true,
}
input: {
var a;
({ p: a } = {
__proto__: {
p: "PASS",
},
});
console.log(a);
}
expect: {
var a;
a = {
__proto__: {
p: "PASS",
},
}.p;
console.log(a);
}
expect_stdout: "PASS"
node_version: ">=6"
}

0 comments on commit cb56ae1

Please sign in to comment.