aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js14
-rw-r--r--test/compress/collapse_vars.js54
2 files changed, 66 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 74e2c6fc..a34272ca 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1610,7 +1610,12 @@ merge(Compressor.prototype, {
if (parent.condition !== node) return node;
return find_stop_value(parent, level + 1);
}
- if (parent instanceof AST_ObjectKeyVal) return find_stop_value(scanner.parent(level + 1), level + 2);
+ if (parent instanceof AST_ObjectKeyVal) {
+ var obj = scanner.parent(level + 1);
+ return all(obj.properties, function(prop) {
+ return prop instanceof AST_ObjectKeyVal;
+ }) ? find_stop_value(obj, level + 2) : obj;
+ }
if (parent instanceof AST_PropAccess) return find_stop_value(parent, level + 1);
if (parent instanceof AST_Sequence) {
return (parent.tail_node() === node ? find_stop_value : find_stop_unused)(parent, level + 1);
@@ -1651,7 +1656,12 @@ merge(Compressor.prototype, {
if (parent instanceof AST_Exit) return find_stop_unused(parent, level + 1);
if (parent instanceof AST_If) return find_stop_unused(parent, level + 1);
if (parent instanceof AST_IterationStatement) return node;
- if (parent instanceof AST_ObjectKeyVal) return find_stop_unused(scanner.parent(level + 1), level + 2);
+ if (parent instanceof AST_ObjectKeyVal) {
+ var obj = scanner.parent(level + 1);
+ return all(obj.properties, function(prop) {
+ return prop instanceof AST_ObjectKeyVal;
+ }) ? find_stop_unused(obj, level + 2) : obj;
+ }
if (parent instanceof AST_PropAccess) {
var exp = parent.expression;
if (exp === node) return find_stop_unused(parent, level + 1);
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 9fe5a93f..16cbadf8 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -7345,3 +7345,57 @@ issue_3626_2: {
}
expect_stdout: "foo 42 null"
}
+
+issue_3628_1: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var a = "bar", b;
+ ({
+ get p() {
+ a = "foo";
+ },
+ q: b = a
+ }).p;
+ console.log(a, b);
+ }
+ expect: {
+ var a = "bar", b;
+ ({
+ get p() {
+ a = "foo";
+ },
+ q: b = a
+ }).p;
+ console.log(a, b);
+ }
+ expect_stdout: "foo bar"
+}
+
+issue_3628_2: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var a = "bar", b;
+ ({
+ get p() {
+ a = "foo";
+ },
+ q: (b = a, 42)
+ }).p;
+ console.log(a, b);
+ }
+ expect: {
+ var a = "bar", b;
+ ({
+ get p() {
+ a = "foo";
+ },
+ q: (b = a, 42)
+ }).p;
+ console.log(a, b);
+ }
+ expect_stdout: "foo bar"
+}