Skip to content

Commit 87c9edb

Browse files
authored
fix corner case in unused (#5847)
fixes #5843
1 parent 8dc99fa commit 87c9edb

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

lib/compress.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8284,6 +8284,7 @@ Compressor.prototype.compress = function(node) {
82848284
if (prop instanceof AST_Spread) return prop;
82858285
var key = prop_keys[index];
82868286
if (key instanceof AST_Node) return prop;
8287+
if (key === "__proto__") return prop;
82878288
if (drop_keys.has(key)) {
82888289
var mapped = drop_keys.get(key);
82898290
if (!mapped) return prop;
@@ -8317,7 +8318,10 @@ Compressor.prototype.compress = function(node) {
83178318
if (value.has_side_effects(compressor) && prop.value.match_symbol(function(node) {
83188319
return node instanceof AST_PropAccess;
83198320
})) break;
8320-
value = make_node(AST_Sub, node, {
8321+
value = is_identifier_string(prop.key) ? make_node(AST_Dot, node, {
8322+
expression: value,
8323+
property: prop.key,
8324+
}) : make_node(AST_Sub, node, {
83218325
expression: value,
83228326
property: make_node_from_constant(prop.key, prop),
83238327
});

test/compress/default-values.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ issue_5340_3: {
22932293
}
22942294
expect: {
22952295
var a;
2296-
(function() {})(a = true["p"]);
2296+
(function() {})(a = true.p);
22972297
console.log(a);
22982298
}
22992299
expect_stdout: "undefined"

test/compress/destructured.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ side_effects_object: {
13821382
}
13831383
}
13841384
expect: {
1385-
var a = null, c = (console, 42["c"]);
1385+
var a = null, c = (console, 42..c);
13861386
try {
13871387
c[a = "PASS"];
13881388
} catch (e) {
@@ -1684,7 +1684,7 @@ singleton_1: {
16841684
expect: {
16851685
var b, a = "P"[0], o = {};
16861686
o.p = [ "FAIL"["1"] ][0];
1687-
o.q = { foo: "S"[0] }["foo"];
1687+
o.q = { foo: "S"[0] }.foo;
16881688
[ b = "S" ] = [];
16891689
console.log(a + o.p + o.q + b);
16901690
}
@@ -3886,3 +3886,54 @@ issue_5651: {
38863886
expect_stdout: true
38873887
node_version: ">=6"
38883888
}
3889+
3890+
issue_5843_1: {
3891+
options = {
3892+
unused: true,
3893+
}
3894+
input: {
3895+
var { p: a } = {
3896+
__proto__: {
3897+
p: "PASS",
3898+
},
3899+
};
3900+
console.log(a);
3901+
}
3902+
expect: {
3903+
var a = {
3904+
__proto__: {
3905+
p: "PASS",
3906+
},
3907+
}.p;
3908+
console.log(a);
3909+
}
3910+
expect_stdout: "PASS"
3911+
node_version: ">=6"
3912+
}
3913+
3914+
issue_5843_2: {
3915+
options = {
3916+
side_effects: true,
3917+
unused: true,
3918+
}
3919+
input: {
3920+
var a;
3921+
({ p: a } = {
3922+
__proto__: {
3923+
p: "PASS",
3924+
},
3925+
});
3926+
console.log(a);
3927+
}
3928+
expect: {
3929+
var a;
3930+
a = {
3931+
__proto__: {
3932+
p: "PASS",
3933+
},
3934+
}.p;
3935+
console.log(a);
3936+
}
3937+
expect_stdout: "PASS"
3938+
node_version: ">=6"
3939+
}

test/compress/exports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ hoist_exports_2: {
260260
}
261261
}
262262
expect: {
263-
let e, a = 42["foo"];
263+
let e, a = 42..foo;
264264
function f(t, { [e]: o }) {
265265
t(o, f);
266266
}

test/compress/yields.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ issue_5076_1: {
13861386
expect: {
13871387
var a;
13881388
console.log("PASS"),
1389-
a = 42["a"];
1389+
a = 42..a;
13901390
}
13911391
expect_stdout: "PASS"
13921392
node_version: ">=6"

0 commit comments

Comments
 (0)