aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js12
-rw-r--r--test/compress/destructured.js24
2 files changed, 34 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 538b906e..ca2880ec 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3894,7 +3894,13 @@ merge(Compressor.prototype, {
if (node instanceof AST_Unary && UNARY_POSTFIX[node.operator]) modified(node.expression);
});
function modified(node) {
- if (node instanceof AST_PropAccess) {
+ if (node instanceof AST_DestructuredArray) {
+ node.elements.forEach(modified);
+ } else if (node instanceof AST_DestructuredObject) {
+ node.properties.forEach(function(prop) {
+ modified(prop.value);
+ });
+ } else if (node instanceof AST_PropAccess) {
modified(node.expression);
} else if (node instanceof AST_SymbolRef) {
node.definition().references.forEach(function(ref) {
@@ -3928,7 +3934,6 @@ merge(Compressor.prototype, {
if (!HOP(lhs, "_eval") && lhs instanceof AST_SymbolRef && lhs.fixed && lhs.definition().fixed) {
node = lhs;
} else if (op == "=") {
- lhs.walk(scan_modified);
node = this.right;
} else {
node = make_node(AST_Binary, this, {
@@ -3937,6 +3942,7 @@ merge(Compressor.prototype, {
right: this.right,
});
}
+ lhs.walk(scan_modified);
var value = node._eval(compressor, ignore_side_effects, cached, depth);
if (typeof value == "object") return this;
modified(lhs);
@@ -4011,6 +4017,7 @@ merge(Compressor.prototype, {
}
var def = e instanceof AST_SymbolRef && e.definition();
if (!non_converting_unary[op] && !(def && def.fixed)) depth++;
+ e.walk(scan_modified);
var v = e._eval(compressor, ignore_side_effects, cached, depth);
if (v === e) {
if (ignore_side_effects && op == "void") return;
@@ -4054,6 +4061,7 @@ merge(Compressor.prototype, {
}
}
if (!(e instanceof AST_SymbolRef && e.definition().fixed)) depth++;
+ e.walk(scan_modified);
var v = e._eval(compressor, ignore_side_effects, cached, depth);
if (v === e) return this;
modified(e);
diff --git a/test/compress/destructured.js b/test/compress/destructured.js
index c506e8f0..70c4392a 100644
--- a/test/compress/destructured.js
+++ b/test/compress/destructured.js
@@ -2302,3 +2302,27 @@ issue_4485_3: {
expect_stdout: true
node_version: ">=6"
}
+
+issue_4500: {
+ options = {
+ evaluate: true,
+ keep_fnames: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = function f(b) {
+ return [ b ] = [], b;
+ }("FAIL");
+ console.log(a || "PASS");
+ }
+ expect: {
+ var a = function f(b) {
+ return [ b ] = [], b;
+ }("FAIL");
+ console.log(a || "PASS");
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}