aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai.bazon@gmail.com>2013-01-24 05:51:33 -0800
committerMihai Bazon <mihai.bazon@gmail.com>2013-01-24 05:51:33 -0800
commit8bf83f42eae5855b331932748d5cad60ee373e3a (patch)
treeb383de96e268ebebfa9b6d660687aee168b77ba9
parent297af47c891006cb2f5b98e3c8675af1e00d15a6 (diff)
parent522566ea80011dc1674ca7f10a5666a24f24ac27 (diff)
downloadtracifyjs-8bf83f42eae5855b331932748d5cad60ee373e3a.tar.gz
tracifyjs-8bf83f42eae5855b331932748d5cad60ee373e3a.zip
Merge pull request #106 from gibson042/105
Fix #105: property comparison to undefined is not always safe
-rw-r--r--lib/compress.js3
-rw-r--r--test/compress/issue-105.js17
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 982b2b19..bc0b9ee5 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1739,7 +1739,8 @@ merge(Compressor.prototype, {
if (self.left instanceof AST_String
&& self.left.value == "undefined"
&& self.right instanceof AST_UnaryPrefix
- && self.right.operator == "typeof") {
+ && self.right.operator == "typeof"
+ && compressor.option("unsafe")) {
if (!(self.right.expression instanceof AST_SymbolRef)
|| !self.right.expression.undeclared()) {
self.left = self.right.expression;
diff --git a/test/compress/issue-105.js b/test/compress/issue-105.js
new file mode 100644
index 00000000..349d732d
--- /dev/null
+++ b/test/compress/issue-105.js
@@ -0,0 +1,17 @@
+typeof_eq_undefined: {
+ options = {
+ comparisons: true,
+ unsafe: false
+ };
+ input: { a = typeof b.c != "undefined" }
+ expect: { a = "undefined" != typeof b.c }
+}
+
+typeof_eq_undefined_unsafe: {
+ options = {
+ comparisons: true,
+ unsafe: true
+ };
+ input: { a = typeof b.c != "undefined" }
+ expect: { a = b.c !== void 0 }
+}