From 5e76065c9e12f77bbc39b426ee7068bdd6a0056a Mon Sep 17 00:00:00 2001 From: Dan Wolff Date: Sun, 4 Feb 2018 22:36:52 +0100 Subject: [PATCH] more efficient to check option and operator only once --- lib/compress.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 66b7f037..4a4a3f2d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4797,6 +4797,7 @@ merge(Compressor.prototype, { if (compressor.option("comparisons")) switch (self.operator) { case "===": case "!==": + var is_strict_comparison = true; if ((self.left.is_string(compressor) && self.right.is_string(compressor)) || (self.left.is_number(compressor) && self.right.is_number(compressor)) || (self.left.is_boolean() && self.right.is_boolean()) || @@ -4827,6 +4828,11 @@ merge(Compressor.prototype, { && is_object(self.left.fixed_value())) { return make_node(self.operator[0] == "=" ? AST_True : AST_False, self); } + // void 0 == x => null == x + else if (!is_strict_comparison + && is_undefined(self.left, compressor)) { + self.left = make_node(AST_Null, self.left); + } break; case "&&": case "||": @@ -4858,12 +4864,6 @@ merge(Compressor.prototype, { } break; } - // void 0 == x => null == x - if (compressor.option("comparisons") && - (self.operator == "==" || self.operator == "!=") && - is_undefined(self.left, compressor)) { - self.left = make_node(AST_Null, self.left); - } if (self.operator == "+" && compressor.in_boolean_context()) { var ll = self.left.evaluate(compressor); var rr = self.right.evaluate(compressor);