@@ -7132,13 +7132,12 @@ merge(Compressor.prototype, {
|
||||
prop_keys = [];
|
||||
prop_map = Object.create(null);
|
||||
value.properties.forEach(function(prop, index) {
|
||||
if (prop instanceof AST_ObjectSetter) return;
|
||||
if (prop instanceof AST_Spread) return prop_map = false;
|
||||
var key = prop.key;
|
||||
if (key instanceof AST_Node) key = key.evaluate(compressor, true);
|
||||
if (key instanceof AST_Node) {
|
||||
prop_map = false;
|
||||
} else if (prop_map) {
|
||||
} else if (prop_map && !(prop instanceof AST_ObjectSetter)) {
|
||||
prop_map[key] = prop;
|
||||
}
|
||||
prop_keys[index] = key;
|
||||
@@ -7184,7 +7183,13 @@ merge(Compressor.prototype, {
|
||||
if (drop_keys && !(key in drop_keys)) {
|
||||
if (mapped) {
|
||||
drop_keys[key] = mapped;
|
||||
if (value === null) prop_map[key] = false;
|
||||
if (value === null) {
|
||||
prop_map[key] = mapped.key instanceof AST_Node
|
||||
&& make_node(AST_ObjectKeyVal, mapped, {
|
||||
key: mapped.key,
|
||||
value: make_node(AST_Number, mapped, { value: 0 }),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
drop_keys[key] = true;
|
||||
}
|
||||
@@ -7201,25 +7206,26 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
value = save_value;
|
||||
drop = save_drop;
|
||||
if (drop_keys && prop_keys) value.properties = value.properties.filter(function(prop, index) {
|
||||
if (prop instanceof AST_ObjectSetter) return false;
|
||||
if (prop instanceof AST_Spread) return true;
|
||||
if (drop_keys && prop_keys) value.properties = List(value.properties, function(prop, index) {
|
||||
if (prop instanceof AST_Spread) return prop;
|
||||
var key = prop_keys[index];
|
||||
if (key instanceof AST_Node) return true;
|
||||
if (key instanceof AST_Node) return prop;
|
||||
if (key in drop_keys) {
|
||||
var mapped = drop_keys[key];
|
||||
if (!mapped) return true;
|
||||
if (mapped === prop) return prop_map[key];
|
||||
if (!mapped) return prop;
|
||||
if (mapped === prop) return prop_map[key] || List.skip;
|
||||
} else if (node.rest) {
|
||||
return true;
|
||||
return prop;
|
||||
}
|
||||
var trimmed = prop.value.drop_side_effect_free(compressor);
|
||||
if (!trimmed) {
|
||||
if (!(prop.key instanceof AST_Node)) return false;
|
||||
trimmed = make_node(AST_Number, prop, { value: 0 });
|
||||
if (trimmed) {
|
||||
prop.value = trimmed;
|
||||
return prop;
|
||||
}
|
||||
prop.value = trimmed;
|
||||
return true;
|
||||
return prop.key instanceof AST_Node ? make_node(AST_ObjectKeyVal, prop, {
|
||||
key: prop.key,
|
||||
value: make_node(AST_Number, prop, { value: 0 }),
|
||||
}) : List.skip;
|
||||
});
|
||||
if (value && !node.rest) switch (properties.length) {
|
||||
case 0:
|
||||
|
||||
@@ -1154,7 +1154,7 @@ drop_hole: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
keep_key: {
|
||||
keep_key_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
@@ -1174,6 +1174,39 @@ keep_key: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
keep_key_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var { 42: a } = { [(console.log("PASS"), 42)](){} };
|
||||
}
|
||||
expect: {
|
||||
var {} = { [(console.log("PASS"), 42)]: 0 };
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
keep_key_2_pure_getters: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
pure_getters: "strict",
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var { 42: a } = { [(console.log("PASS"), 42)](){} };
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
keep_reference: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
@@ -2816,3 +2849,102 @@ issue_5071_2: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5074_getter: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
({} = { get [(console.log("PASS"), 42)]() {} });
|
||||
}
|
||||
expect: {
|
||||
({} = { [(console.log("PASS"), 42)]: 0 });
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5074_getter_pure_getters: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
({} = { get [(console.log("PASS"), 42)]() {} });
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5074_setter: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
({} = { set [(console.log("PASS"), 42)](v) {} });
|
||||
}
|
||||
expect: {
|
||||
({} = { [(console.log("PASS"), 42)]: 0 });
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5074_setter_pure_getters: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
({} = { set [(console.log("PASS"), 42)](v) {} });
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5074_method: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
({} = { [(console.log("PASS"), 42)]() {} });
|
||||
}
|
||||
expect: {
|
||||
({} = { [(console.log("PASS"), 42)]: 0 });
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5074_method_pure_getters: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
({} = { [(console.log("PASS"), 42)]() {} });
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user