Fix #105: property comparison to undefined is not always safe
This commit is contained in:
@@ -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;
|
||||
|
||||
17
test/compress/issue-105.js
Normal file
17
test/compress/issue-105.js
Normal file
@@ -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 }
|
||||
}
|
||||
Reference in New Issue
Block a user