aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js31
-rw-r--r--test/compress/default-values.js25
-rw-r--r--test/compress/destructured.js33
3 files changed, 68 insertions, 21 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 73cc2df5..e8a4815e 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6042,27 +6042,16 @@ merge(Compressor.prototype, {
function compose(child, level, find) {
var parent = compressor.parent(level);
if (!parent) return find;
- if (parent instanceof AST_DestructuredKeyVal) {
- var destructured = compressor.parent(level + 1);
- if (parent.key === child) {
- var fn = compressor.parent(level + 2);
- if (fn instanceof AST_Lambda) {
- return compose(fn, level + 3, fn.argnames.indexOf(destructured) >= 0 ? function(name) {
- var def = find(name);
- if (def) return def;
- def = fn.variables.get(name);
- if (def) {
- var sym = def.orig[0];
- if (sym instanceof AST_SymbolFunarg || sym instanceof AST_SymbolLambda) return def;
- }
- } : function(name) {
- return find(name) || fn.variables.get(name);
- });
- }
- }
- return compose(destructured, level + 2, find);
- }
- return compose(parent, level + 1, parent.variables ? function(name) {
+ var in_arg = parent instanceof AST_Lambda && member(child, parent.argnames);
+ return compose(parent, level + 1, in_arg ? function(name) {
+ var def = find(name);
+ if (def) return def;
+ def = parent.variables.get(name);
+ if (def) {
+ var sym = def.orig[0];
+ if (sym instanceof AST_SymbolFunarg || sym instanceof AST_SymbolLambda) return def;
+ }
+ } : parent.variables ? function(name) {
return find(name) || parent.variables.get(name);
} : find);
}
diff --git a/test/compress/default-values.js b/test/compress/default-values.js
index c65ccd35..d1637524 100644
--- a/test/compress/default-values.js
+++ b/test/compress/default-values.js
@@ -1726,3 +1726,28 @@ issue_4916: {
expect_stdout: "undefined"
node_version: ">=6"
}
+
+issue_4994: {
+ options = {
+ loops: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function(b = function() {
+ for (a in { PASS: 42 });
+ }()) {
+ var a;
+ })();
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ (function(b = function() {
+ for (a in { PASS: 42 });
+ }()) {})();
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
diff --git a/test/compress/destructured.js b/test/compress/destructured.js
index 78cd6863..41e337be 100644
--- a/test/compress/destructured.js
+++ b/test/compress/destructured.js
@@ -2592,3 +2592,36 @@ issue_4608_2: {
expect_stdout: "f"
node_version: ">=6"
}
+
+issue_4994: {
+ options = {
+ loops: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function([
+ {
+ [function() {
+ for (a in { PASS: null });
+ }()]: b,
+ },
+ ]) {
+ var a;
+ })([ 42 ]);
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ (function([
+ {
+ [function() {
+ for (a in { PASS: null });
+ }()]: b,
+ },
+ ]) {})([ 42 ]);
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}