diff options
author | Dan <dan.d.wolff@gmail.com> | 2018-02-05 08:00:23 +0100 |
---|---|---|
committer | Alex Lam S.L <alexlamsl@gmail.com> | 2018-02-05 15:00:23 +0800 |
commit | 9637f51b6865d0987dcd950bc7113c871ca6cb3c (patch) | |
tree | 06084642d4f8e6d2fdd498925020c09f8a811bd1 /lib | |
parent | 3026bd89759446c9c5d6fa1cd69651f853ffe08d (diff) | |
download | tracifyjs-9637f51b6865d0987dcd950bc7113c871ca6cb3c.tar.gz tracifyjs-9637f51b6865d0987dcd950bc7113c871ca6cb3c.zip |
change `undefined == x` to `null == x` (#2882)
fixes #2871
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 321ee5fc..a48d0c9a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4790,6 +4790,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()) || @@ -4799,8 +4800,12 @@ merge(Compressor.prototype, { // XXX: intentionally falling down to the next case case "==": case "!=": + // void 0 == x => null == x + if (!is_strict_comparison && is_undefined(self.left, compressor)) { + self.left = make_node(AST_Null, self.left); + } // "undefined" == typeof x => undefined === x - if (compressor.option("typeofs") + else if (compressor.option("typeofs") && self.left instanceof AST_String && self.left.value == "undefined" && self.right instanceof AST_UnaryPrefix |