Skip to content

Commit df8a994

Browse files
authoredMay 6, 2018
fix various corner cases (#3126)
- augment ufuzz/reminify test options fixes #3125
1 parent 6b91d12 commit df8a994

File tree

4 files changed

+132
-10
lines changed

4 files changed

+132
-10
lines changed
 

‎lib/compress.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,10 @@ merge(Compressor.prototype, {
491491
mark_escaped(tw, d, scope, parent, value, level + 1, depth + 1);
492492
if (value) return;
493493
}
494-
if (level == 0) d.direct_access = true;
494+
if (level > 0) return;
495+
if (parent instanceof AST_Sequence && node !== parent.tail_node()) return;
496+
if (parent instanceof AST_SimpleStatement) return;
497+
d.direct_access = true;
495498
}
496499

497500
var suppressor = new TreeWalker(function(node) {
@@ -509,17 +512,21 @@ merge(Compressor.prototype, {
509512
walk_defuns(tw, this);
510513
return true;
511514
});
512-
def(AST_Assign, function(tw) {
515+
def(AST_Assign, function(tw, descend, compressor) {
513516
var node = this;
514-
if (!(node.left instanceof AST_SymbolRef)) return;
515-
var d = node.left.definition();
517+
var sym = node.left;
518+
if (!(sym instanceof AST_SymbolRef)) return;
519+
var d = sym.definition();
516520
var fixed = d.fixed;
517521
if (!fixed && node.operator != "=") return;
518-
if (!safe_to_assign(tw, d, node.left.scope, node.right)) return;
519-
d.references.push(node.left);
522+
if (!safe_to_assign(tw, d, sym.scope, node.right)) return;
523+
var eq = node.operator == "=";
524+
var value = eq ? node.right : node;
525+
if (is_modified(compressor, tw, node, value, 0)) return;
526+
d.references.push(sym);
520527
d.assignments++;
521-
if (node.operator != "=") d.chained = true;
522-
d.fixed = node.operator == "=" ? function() {
528+
if (!eq) d.chained = true;
529+
d.fixed = eq ? function() {
523530
return node.right;
524531
} : function() {
525532
return make_node(AST_Binary, node, {
@@ -531,6 +538,7 @@ merge(Compressor.prototype, {
531538
mark(tw, d, false);
532539
node.right.walk(tw);
533540
mark(tw, d, true);
541+
mark_escaped(tw, d, sym.scope, node, value, 0, 1);
534542
return true;
535543
});
536544
def(AST_Binary, function(tw) {
@@ -4682,13 +4690,16 @@ merge(Compressor.prototype, {
46824690
func = func.fixed_value();
46834691
}
46844692
if (func instanceof AST_Lambda && !func.contains_this()) {
4685-
return make_sequence(this, [
4693+
return (self.args.length ? make_sequence(this, [
46864694
self.args[0],
46874695
make_node(AST_Call, self, {
46884696
expression: exp.expression,
46894697
args: self.args.slice(1)
46904698
})
4691-
]).optimize(compressor);
4699+
]) : make_node(AST_Call, self, {
4700+
expression: exp.expression,
4701+
args: []
4702+
})).optimize(compressor);
46924703
}
46934704
break;
46944705
}

‎test/compress/functions.js

+16
Original file line numberDiff line numberDiff line change
@@ -2303,3 +2303,19 @@ issue_3076: {
23032303
}
23042304
expect_stdout: "PASS"
23052305
}
2306+
2307+
issue_3125: {
2308+
options = {
2309+
inline: true,
2310+
unsafe: true,
2311+
}
2312+
input: {
2313+
console.log(function() {
2314+
return "PASS";
2315+
}.call());
2316+
}
2317+
expect: {
2318+
console.log("PASS");
2319+
}
2320+
expect_stdout: "PASS"
2321+
}

‎test/compress/reduce_vars.js

+88
Original file line numberDiff line numberDiff line change
@@ -6058,3 +6058,91 @@ conditional_nested_2: {
60586058
}
60596059
expect_stdout: "1"
60606060
}
6061+
6062+
issue_2436: {
6063+
options = {
6064+
evaluate: true,
6065+
reduce_vars: true,
6066+
toplevel: true,
6067+
unsafe: true,
6068+
}
6069+
input: {
6070+
var c;
6071+
console.log(((c = {
6072+
a: 1,
6073+
b: 2
6074+
}).a = 3, {
6075+
x: c.a,
6076+
y: c.b
6077+
}));
6078+
}
6079+
expect: {
6080+
var c;
6081+
console.log(((c = {
6082+
a: 1,
6083+
b: 2
6084+
}).a = 3, {
6085+
x: c.a,
6086+
y: c.b
6087+
}));
6088+
}
6089+
expect_stdout: true
6090+
}
6091+
6092+
issue_2916: {
6093+
options = {
6094+
collapse_vars: true,
6095+
evaluate: true,
6096+
inline: true,
6097+
passes: 2,
6098+
reduce_vars: true,
6099+
side_effects: true,
6100+
unsafe: true,
6101+
unused: true,
6102+
}
6103+
input: {
6104+
var c = "FAIL";
6105+
(function(b) {
6106+
(function(d) {
6107+
d[0] = 1;
6108+
})(b);
6109+
+b && (c = "PASS");
6110+
})([]);
6111+
console.log(c);
6112+
}
6113+
expect: {
6114+
var c = "FAIL";
6115+
(function(b) {
6116+
b[0] = 1;
6117+
+b && (c = "PASS");
6118+
})([]);
6119+
console.log(c);
6120+
}
6121+
expect_stdout: "PASS"
6122+
}
6123+
6124+
issue_3125: {
6125+
options = {
6126+
evaluate: true,
6127+
reduce_vars: true,
6128+
toplevel: true,
6129+
unsafe: true,
6130+
}
6131+
input: {
6132+
var o;
6133+
console.log((function() {
6134+
this.p++;
6135+
}.call(o = {
6136+
p: 6
6137+
}), o.p));
6138+
}
6139+
expect: {
6140+
var o;
6141+
console.log((function() {
6142+
this.p++;
6143+
}.call(o = {
6144+
p: 6
6145+
}), o.p));
6146+
}
6147+
expect_stdout: "7"
6148+
}

‎test/ufuzz.json

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
{
1919
"toplevel": true
2020
},
21+
{
22+
"compress": {
23+
"passes": 1e6,
24+
"unsafe": true
25+
},
26+
"toplevel": true
27+
},
2128
{
2229
"compress": {
2330
"keep_fargs": false,

0 commit comments

Comments
 (0)
Please sign in to comment.