fix various corner cases (#3126)
- augment ufuzz/reminify test options fixes #3125
This commit is contained in:
@@ -491,7 +491,10 @@ merge(Compressor.prototype, {
|
|||||||
mark_escaped(tw, d, scope, parent, value, level + 1, depth + 1);
|
mark_escaped(tw, d, scope, parent, value, level + 1, depth + 1);
|
||||||
if (value) return;
|
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) {
|
var suppressor = new TreeWalker(function(node) {
|
||||||
@@ -509,17 +512,21 @@ merge(Compressor.prototype, {
|
|||||||
walk_defuns(tw, this);
|
walk_defuns(tw, this);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
def(AST_Assign, function(tw) {
|
def(AST_Assign, function(tw, descend, compressor) {
|
||||||
var node = this;
|
var node = this;
|
||||||
if (!(node.left instanceof AST_SymbolRef)) return;
|
var sym = node.left;
|
||||||
var d = node.left.definition();
|
if (!(sym instanceof AST_SymbolRef)) return;
|
||||||
|
var d = sym.definition();
|
||||||
var fixed = d.fixed;
|
var fixed = d.fixed;
|
||||||
if (!fixed && node.operator != "=") return;
|
if (!fixed && node.operator != "=") return;
|
||||||
if (!safe_to_assign(tw, d, node.left.scope, node.right)) return;
|
if (!safe_to_assign(tw, d, sym.scope, node.right)) return;
|
||||||
d.references.push(node.left);
|
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++;
|
d.assignments++;
|
||||||
if (node.operator != "=") d.chained = true;
|
if (!eq) d.chained = true;
|
||||||
d.fixed = node.operator == "=" ? function() {
|
d.fixed = eq ? function() {
|
||||||
return node.right;
|
return node.right;
|
||||||
} : function() {
|
} : function() {
|
||||||
return make_node(AST_Binary, node, {
|
return make_node(AST_Binary, node, {
|
||||||
@@ -531,6 +538,7 @@ merge(Compressor.prototype, {
|
|||||||
mark(tw, d, false);
|
mark(tw, d, false);
|
||||||
node.right.walk(tw);
|
node.right.walk(tw);
|
||||||
mark(tw, d, true);
|
mark(tw, d, true);
|
||||||
|
mark_escaped(tw, d, sym.scope, node, value, 0, 1);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
def(AST_Binary, function(tw) {
|
def(AST_Binary, function(tw) {
|
||||||
@@ -4682,13 +4690,16 @@ merge(Compressor.prototype, {
|
|||||||
func = func.fixed_value();
|
func = func.fixed_value();
|
||||||
}
|
}
|
||||||
if (func instanceof AST_Lambda && !func.contains_this()) {
|
if (func instanceof AST_Lambda && !func.contains_this()) {
|
||||||
return make_sequence(this, [
|
return (self.args.length ? make_sequence(this, [
|
||||||
self.args[0],
|
self.args[0],
|
||||||
make_node(AST_Call, self, {
|
make_node(AST_Call, self, {
|
||||||
expression: exp.expression,
|
expression: exp.expression,
|
||||||
args: self.args.slice(1)
|
args: self.args.slice(1)
|
||||||
})
|
})
|
||||||
]).optimize(compressor);
|
]) : make_node(AST_Call, self, {
|
||||||
|
expression: exp.expression,
|
||||||
|
args: []
|
||||||
|
})).optimize(compressor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2303,3 +2303,19 @@ issue_3076: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3125: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
return "PASS";
|
||||||
|
}.call());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -6058,3 +6058,91 @@ conditional_nested_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2436: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c;
|
||||||
|
console.log(((c = {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
}).a = 3, {
|
||||||
|
x: c.a,
|
||||||
|
y: c.b
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c;
|
||||||
|
console.log(((c = {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
}).a = 3, {
|
||||||
|
x: c.a,
|
||||||
|
y: c.b
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2916: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function(b) {
|
||||||
|
(function(d) {
|
||||||
|
d[0] = 1;
|
||||||
|
})(b);
|
||||||
|
+b && (c = "PASS");
|
||||||
|
})([]);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function(b) {
|
||||||
|
b[0] = 1;
|
||||||
|
+b && (c = "PASS");
|
||||||
|
})([]);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3125: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o;
|
||||||
|
console.log((function() {
|
||||||
|
this.p++;
|
||||||
|
}.call(o = {
|
||||||
|
p: 6
|
||||||
|
}), o.p));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o;
|
||||||
|
console.log((function() {
|
||||||
|
this.p++;
|
||||||
|
}.call(o = {
|
||||||
|
p: 6
|
||||||
|
}), o.p));
|
||||||
|
}
|
||||||
|
expect_stdout: "7"
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,13 @@
|
|||||||
{
|
{
|
||||||
"toplevel": true
|
"toplevel": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"compress": {
|
||||||
|
"passes": 1e6,
|
||||||
|
"unsafe": true
|
||||||
|
},
|
||||||
|
"toplevel": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"compress": {
|
"compress": {
|
||||||
"keep_fargs": false,
|
"keep_fargs": false,
|
||||||
|
|||||||
Reference in New Issue
Block a user