aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-17 18:49:52 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-17 18:49:52 +0300
commitee669ba8784a37805cd699cc0ca38e335982eb59 (patch)
tree1b03266988496dbdaac6e3538dc2b51491107316 /lib/compress.js
parente370e3b5a4fcde13402f910a34b736847fe49a9e (diff)
downloadtracifyjs-ee669ba8784a37805cd699cc0ca38e335982eb59.tar.gz
tracifyjs-ee669ba8784a37805cd699cc0ca38e335982eb59.zip
moved `typeof foo == "undefined"` ==> `foo === undefined` under `--unsafe`
because https://github.com/mishoo/UglifyJS2/commit/43fd45154bac89b89330e13bd1f167e2a927a23c#commitcomment-1864505
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 8a2cd4cd..ba6f809f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1371,21 +1371,23 @@ function Compressor(options, false_by_default) {
// 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 += "=";
+ if (compressor.option("unsafe")) {
+ 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;
}