case 1:
if (!drop) break;
var sym = elements[0];
- if (!(sym instanceof AST_Symbol)) break;
+ if (sym.has_side_effects(compressor)) break;
value = make_node(AST_Sub, node, {
expression: value,
property: make_node(AST_Number, node, { value: 0 }),
if (!drop) break;
var prop = properties[0];
if (prop.key instanceof AST_Node) break;
- if (!(prop.value instanceof AST_Symbol)) break;
+ if (prop.value.has_side_effects(compressor)) break;
value = make_node(AST_Sub, node, {
expression: value,
property: make_node_from_constant(prop.key, prop),
if (compressor.has_directive("use strict") && expr.is_constant()) return this;
}
if (left.has_side_effects(compressor)) return this;
- var right = this.right;
- if (!lazy_op[this.operator.slice(0, -1)]) {
- this.write_only = true;
- if (root_expr(left).is_constant_expression(compressor.find_parent(AST_Scope))) {
- return right.drop_side_effect_free(compressor);
- }
- }
- return this;
+ if (lazy_op[this.operator.slice(0, -1)]) return this;
+ this.write_only = true;
+ if (!root_expr(left).is_constant_expression(compressor.find_parent(AST_Scope))) return this;
+ return this.right.drop_side_effect_free(compressor);
});
def(AST_Await, function(compressor) {
if (!compressor.option("awaits")) return this;
node_version: ">=6"
}
+singleton_1: {
+ options = {
+ pure_getters: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var [ a ] = "P", b, o = {};
+ [ { 1: o.p } ] = [ "FAIL" ];
+ ({ foo: [ o.q ] } = { foo: "S" });
+ [ b = "S" ] = [];
+ console.log(a + o.p + o.q + b);
+ }
+ expect: {
+ var b, a = "P"[0], o = {};
+ o.p = [ "FAIL"["1"] ][0];
+ o.q = { foo: "S"[0] }["foo"];
+ [ b = "S" ] = [];
+ console.log(a + o.p + o.q + b);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+singleton_2: {
+ options = {
+ evaluate: true,
+ passes: 2,
+ pure_getters: true,
+ side_effects: true,
+ unsafe: true,
+ unused: true,
+ }
+ input: {
+ var [ a ] = "P", b, o = {};
+ [ { 1: o.p } ] = [ "FAIL" ];
+ ({ foo: [ o.q ] } = { foo: "S" });
+ [ b = "S" ] = [];
+ console.log(a + o.p + o.q + b);
+ }
+ expect: {
+ var b, a = "P", o = {};
+ o.p = "A";
+ o.q = "S";
+ [ b = "S" ] = [];
+ console.log(a + o.p + o.q + b);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+singleton_side_effects: {
+ options = {
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ [ 42[console.log("foo")] ] = [ console.log("bar") ];
+ }
+ expect: {
+ [ 42[console.log("foo")] ] = [ console.log("bar") ];
+ }
+ expect_stdout: [
+ "bar",
+ "foo",
+ ]
+ node_version: ">=6"
+}
+
issue_4280: {
options = {
evaluate: true,