aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index b37dcfe7..369094ee 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -473,6 +473,7 @@ function Compressor(options, false_by_default) {
switch (this.operator) {
case "!": return !ev(e);
case "typeof": return typeof ev(e);
+ case "void": return void ev(e);
case "~": return ~ev(e);
case "-": return -ev(e);
case "+": return +ev(e);
@@ -1251,6 +1252,25 @@ function Compressor(options, false_by_default) {
(this.left.is_boolean() && this.right.is_boolean())) {
this.operator = this.operator.substr(0, 2);
}
+ // XXX: intentionally falling down to the next case
+ case "==":
+ case "!=":
+ if (this.left instanceof AST_UnaryPrefix
+ && this.left.operator == "typeof"
+ && this.right instanceof AST_String
+ && this.right.value == "undefined") {
+ this.left = this.left.expression;
+ this.right = make_node(AST_Undefined, this.right).optimize(compressor);
+ if (this.operator.length == 2) this.operator += "=";
+ }
+ else if (this.left instanceof AST_String
+ && this.left.value == "undefined"
+ && this.right instanceof AST_UnaryPrefix
+ && this.right.operator == "typeof") {
+ this.left = this.right.expression;
+ this.right = make_node(AST_Undefined, this.left).optimize(compressor);
+ if (this.operator.length == 2) this.operator += "=";
+ }
break;
}
if (compressor.option("booleans") && compressor.in_boolean_context()) switch (this.operator) {