aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-12-05 05:08:37 +0800
committerGitHub <noreply@github.com>2019-12-05 05:08:37 +0800
commit9074f05129318c2acc095d8a58c60c0a61ff0cee (patch)
tree60e1ea08637f35382040a3f689a29cf1b5cc105f /lib
parent04fbb1f94978884128ef1582405a77a1974c6522 (diff)
downloadtracifyjs-9074f05129318c2acc095d8a58c60c0a61ff0cee.tar.gz
tracifyjs-9074f05129318c2acc095d8a58c60c0a61ff0cee.zip
fix corner case in `collapse_vars` (#3629)
fixes #3628
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js14
1 files changed, 12 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);