aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-05-07 07:36:25 +0800
committerGitHub <noreply@github.com>2018-05-07 07:36:25 +0800
commitdf8a99439a3cab07670fd462ad2f8d6d240a8312 (patch)
treed8e4d2a92fbba72cf276d41d43eed44aca690419 /lib
parent6b91d12ec352ad0494752aa6a74ee16cc99b5158 (diff)
downloadtracifyjs-df8a99439a3cab07670fd462ad2f8d6d240a8312.tar.gz
tracifyjs-df8a99439a3cab07670fd462ad2f8d6d240a8312.zip
fix various corner cases (#3126)
- augment ufuzz/reminify test options fixes #3125
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js31
1 files changed, 21 insertions, 10 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 03fb1c11..8c565c21 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -491,7 +491,10 @@ merge(Compressor.prototype, {
mark_escaped(tw, d, scope, parent, value, level + 1, depth + 1);
if (value) return;
}
- if (level == 0) d.direct_access = true;
+ if (level > 0) return;
+ if (parent instanceof AST_Sequence && node !== parent.tail_node()) return;
+ if (parent instanceof AST_SimpleStatement) return;
+ d.direct_access = true;
}
var suppressor = new TreeWalker(function(node) {
@@ -509,17 +512,21 @@ merge(Compressor.prototype, {
walk_defuns(tw, this);
return true;
});
- def(AST_Assign, function(tw) {
+ def(AST_Assign, function(tw, descend, compressor) {
var node = this;
- if (!(node.left instanceof AST_SymbolRef)) return;
- var d = node.left.definition();
+ var sym = node.left;
+ if (!(sym instanceof AST_SymbolRef)) return;
+ var d = sym.definition();
var fixed = d.fixed;
if (!fixed && node.operator != "=") return;
- if (!safe_to_assign(tw, d, node.left.scope, node.right)) return;
- d.references.push(node.left);
+ if (!safe_to_assign(tw, d, sym.scope, node.right)) return;
+ var eq = node.operator == "=";
+ var value = eq ? node.right : node;
+ if (is_modified(compressor, tw, node, value, 0)) return;
+ d.references.push(sym);
d.assignments++;
- if (node.operator != "=") d.chained = true;
- d.fixed = node.operator == "=" ? function() {
+ if (!eq) d.chained = true;
+ d.fixed = eq ? function() {
return node.right;
} : function() {
return make_node(AST_Binary, node, {
@@ -531,6 +538,7 @@ merge(Compressor.prototype, {
mark(tw, d, false);
node.right.walk(tw);
mark(tw, d, true);
+ mark_escaped(tw, d, sym.scope, node, value, 0, 1);
return true;
});
def(AST_Binary, function(tw) {
@@ -4682,13 +4690,16 @@ merge(Compressor.prototype, {
func = func.fixed_value();
}
if (func instanceof AST_Lambda && !func.contains_this()) {
- return make_sequence(this, [
+ return (self.args.length ? make_sequence(this, [
self.args[0],
make_node(AST_Call, self, {
expression: exp.expression,
args: self.args.slice(1)
})
- ]).optimize(compressor);
+ ]) : make_node(AST_Call, self, {
+ expression: exp.expression,
+ args: []
+ })).optimize(compressor);
}
break;
}