diff options
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/compress.js b/lib/compress.js index 4e276528..72f8e636 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4003,17 +4003,17 @@ merge(Compressor.prototype, { return this; }); def(AST_Binary, function(compressor, first_in_statement) { - var right = this.right.drop_side_effect_free(compressor); + var right = this.right.drop_side_effect_free(compressor, first_in_statement); if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement); if (lazy_op[this.operator]) { if (right === this.right) return this; var node = this.clone(); - node.right = right; + node.right = right.drop_side_effect_free(compressor); return node; } else { var left = this.left.drop_side_effect_free(compressor, first_in_statement); - if (!left) return this.right.drop_side_effect_free(compressor, first_in_statement); - return make_sequence(this, [ left, right ]); + if (!left) return right; + return make_sequence(this, [ left, right.drop_side_effect_free(compressor) ]); } }); def(AST_Call, function(compressor, first_in_statement) { @@ -4666,12 +4666,30 @@ merge(Compressor.prototype, { if (compressor.option("unsafe")) { if (is_undeclared_ref(exp)) switch (exp.name) { case "Array": - if (self.args.length != 1) { - return make_node(AST_Array, self, { - elements: self.args - }).optimize(compressor); + if (self.args.length == 1) { + var first = self.args[0]; + if (first instanceof AST_Number) try { + var length = first.getValue(); + if (length > 6) break; + var elements = Array(length); + for (var i = 0; i < length; i++) elements[i] = make_node(AST_Hole, self); + return make_node(AST_Array, self, { + elements: elements + }); + } catch (ex) { + compressor.warn("Invalid array length: {length} [{file}:{line},{col}]", { + length: length, + file: self.start.file, + line: self.start.line, + col: self.start.col + }); + break; + } + if (!first.is_boolean(compressor) && !first.is_string(compressor)) break; } - break; + return make_node(AST_Array, self, { + elements: self.args + }); case "Object": if (self.args.length == 0) { return make_node(AST_Object, self, { |