aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--lib/compress.js8
-rw-r--r--test/compress/collapse_vars.js6
-rw-r--r--test/compress/comparing.js56
-rw-r--r--test/compress/if_return.js2
5 files changed, 29 insertions, 55 deletions
diff --git a/README.md b/README.md
index 4e30af25..e754e0bc 100644
--- a/README.md
+++ b/README.md
@@ -605,8 +605,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
side effects permitting.
- `comparisons` (default: `true`) -- apply certain optimizations to binary nodes,
- e.g. `!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
- nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.
+ e.g. `!(a <= b) → a > b`, attempts to negate binary nodes, e.g.
+ `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.
- `conditionals` (default: `true`) -- apply optimizations for `if`-s and conditional
expressions
@@ -730,12 +730,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
- `unsafe` (default: `false`) -- apply "unsafe" transformations (discussion below)
-- `unsafe_comps` (default: `false`) -- Reverse `<` and `<=` to `>` and `>=` to
- allow improved compression. This might be unsafe when an at least one of two
- operands is an object with computed values due the use of methods like `get`,
- or `valueOf`. This could cause change in execution order after operands in the
- comparison are switching. Compression only works if both `comparisons` and
- `unsafe_comps` are both set to true.
+- `unsafe_comps` (default: `false`) -- compress expressions like `a <= b` assuming
+ none of the operands can be (coerced to) `NaN`.
- `unsafe_Function` (default: `false`) -- compress and mangle `Function(args, code)`
when both `args` and `code` are string literals.
diff --git a/lib/compress.js b/lib/compress.js
index 9adef60e..e83524c5 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5041,11 +5041,9 @@ merge(Compressor.prototype, {
});
self = best_of(compressor, self, negated);
}
- if (compressor.option("unsafe_comps")) {
- switch (self.operator) {
- case "<": reverse(">"); break;
- case "<=": reverse(">="); break;
- }
+ switch (self.operator) {
+ case ">": reverse("<"); break;
+ case ">=": reverse("<="); break;
}
}
if (self.operator == "+") {
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 9a6e5a57..97efc21b 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -913,15 +913,15 @@ collapse_vars_unary: {
return delete x;
}
function f1(n) {
- return n > +!!n
+ return +!!n < n;
}
function f2(n) {
var k = 7;
- return k--
+ return k--;
}
function f3(n) {
var k = 7;
- return ++k
+ return ++k;
}
function f4(n) {
var k = 8 - n;
diff --git a/test/compress/comparing.js b/test/compress/comparing.js
index d56445e0..17b3ac47 100644
--- a/test/compress/comparing.js
+++ b/test/compress/comparing.js
@@ -1,62 +1,42 @@
-keep_comparisons: {
+comparisons: {
options = {
comparisons: true,
- unsafe_comps: false
}
input: {
- var obj1 = {
- valueOf: function() {triggeredFirst();}
- }
- var obj2 = {
- valueOf: function() {triggeredSecond();}
- }
+ var obj1, obj2;
var result1 = obj1 <= obj2;
var result2 = obj1 < obj2;
var result3 = obj1 >= obj2;
var result4 = obj1 > obj2;
}
expect: {
- var obj1 = {
- valueOf: function() {triggeredFirst();}
- }
- var obj2 = {
- valueOf: function() {triggeredSecond();}
- }
+ var obj1, obj2;
var result1 = obj1 <= obj2;
var result2 = obj1 < obj2;
- var result3 = obj1 >= obj2;
- var result4 = obj1 > obj2;
+ var result3 = obj2 <= obj1;
+ var result4 = obj2 < obj1;
}
}
-keep_comparisons_with_unsafe_comps: {
+unsafe_comps: {
options = {
comparisons: true,
- unsafe_comps: true
+ conditionals: true,
+ unsafe_comps: true,
}
input: {
- var obj1 = {
- valueOf: function() {triggeredFirst();}
- }
- var obj2 = {
- valueOf: function() {triggeredSecond();}
- }
- var result1 = obj1 <= obj2;
- var result2 = obj1 < obj2;
- var result3 = obj1 >= obj2;
- var result4 = obj1 > obj2;
+ var obj1, obj2;
+ obj1 <= obj2 ? f1() : g1();
+ obj1 < obj2 ? f2() : g2();
+ obj1 >= obj2 ? f3() : g3();
+ obj1 > obj2 ? f4() : g4();
}
expect: {
- var obj1 = {
- valueOf: function() {triggeredFirst();}
- }
- var obj2 = {
- valueOf: function() {triggeredSecond();}
- }
- var result1 = obj2 >= obj1;
- var result2 = obj2 > obj1;
- var result3 = obj1 >= obj2;
- var result4 = obj1 > obj2;
+ var obj1, obj2;
+ obj2 < obj1 ? g1() : f1();
+ obj1 < obj2 ? f2() : g2();
+ obj1 < obj2 ? g3() : f3();
+ obj2 < obj1 ? f4() : g4();
}
}
diff --git a/test/compress/if_return.js b/test/compress/if_return.js
index 981b437f..9b18bf11 100644
--- a/test/compress/if_return.js
+++ b/test/compress/if_return.js
@@ -243,7 +243,7 @@ issue_1089: {
expect: {
function x() {
var f = document.getElementById("fname");
- if (f.files[0].size > 12345)
+ if (12345 < f.files[0].size)
return alert("alert"), f.focus(), !1;
}
}