diff --git a/lib/compress.js b/lib/compress.js index d0babad62b5..6de1ec4c06a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4265,8 +4265,17 @@ Compressor.prototype.compress = function(node) { prop = +prop; var len = value.elements.length; if (prop > len + 4) return; - while (len < prop) value.elements[len++] = make_node(AST_Hole, value); - value.elements[prop] = node.right; + if (prop < len) { + var element = value.elements[prop]; + if (element instanceof AST_Hole) { + value.elements[prop] = node.right; + } else { + value.elements[prop] = make_sequence(node, [ element, node.right ]).optimize(compressor); + } + } else { + while (prop > len) value.elements[len++] = make_node(AST_Hole, value); + value.elements[prop] = node.right; + } return true; } diff --git a/test/compress/join_vars.js b/test/compress/join_vars.js index 87b0371e5ad..80c89f330cc 100644 --- a/test/compress/join_vars.js +++ b/test/compress/join_vars.js @@ -32,7 +32,7 @@ join_array_assignments_1: { } expect: { console.log(function () { - var a = ["moz", "baz", "bar", , , , , "moo"]; + var a = [("foo", "moz"), "baz", "bar", , , , , "moo"]; return a; }().join()); } @@ -93,6 +93,7 @@ join_array_assignments_4: { options = { evaluate: true, join_vars: true, + side_effects: true, } input: { console.log(function () { @@ -1492,3 +1493,18 @@ issue_5175: { } expect_stdout: "PASS PASS" } + +issue_5831: { + options = { + evaluate: true, + join_vars: true, + } + input: { + var a = [ console.log("PASS") ]; + a[0] = 42; + } + expect: { + var a = [ (console.log("PASS"), 42) ]; + } + expect_stdout: "PASS" +}