From: Richard Gibson Date: Thu, 24 Jan 2013 04:52:04 +0000 (-0500) Subject: Fix #105: property comparison to undefined is not always safe X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=522566ea80011dc1674ca7f10a5666a24f24ac27;p=UglifyJS.git Fix #105: property comparison to undefined is not always safe --- 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 } +}