From 774feeadb8507f5522e5d33a11c625d653a8e76c Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 16 Jan 2022 17:14:52 +0000 Subject: [PATCH] minor clean-ups (#5300) --- lib/compress.js | 26 ++++++++------------------ test/compress/let.js | 2 +- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index e3a52a71..cc558eec 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2530,7 +2530,7 @@ Compressor.prototype.compress = function(node) { } if (names.has(sym.name)) continue; names.set(sym.name, true); - if (value) arg = !arg || is_undefined(arg) ? value : null; + if (value) arg = is_undefined(arg) ? value : null; if (!arg && !value) { arg = make_node(AST_Undefined, sym).transform(compressor); } else if (arg instanceof AST_Lambda && arg.pinned()) { @@ -3423,10 +3423,6 @@ Compressor.prototype.compress = function(node) { return false; } - function is_return_void(value) { - return !value || value instanceof AST_UnaryPrefix && value.operator == "void"; - } - function match_target(target) { return last_of(compressor, function(node) { return node === target; @@ -3434,7 +3430,7 @@ Compressor.prototype.compress = function(node) { } function can_drop_abort(ab) { - if (ab instanceof AST_Return) return in_lambda && is_return_void(ab.value); + if (ab instanceof AST_Return) return in_lambda && is_undefined(ab.value); if (!(ab instanceof AST_LoopControl)) return false; var lct = compressor.loopcontrol_target(ab); if (ab instanceof AST_Continue) return match_target(loop_body(lct)); @@ -3481,9 +3477,7 @@ Compressor.prototype.compress = function(node) { block = last.body; } block.pop(); - if (ab.value) block.push(make_node(AST_SimpleStatement, ab.value, { - body: ab.value.expression - })); + if (ab.value) block.push(make_node(AST_SimpleStatement, ab.value, { body: ab.value })); return body; } @@ -4000,7 +3994,8 @@ Compressor.prototype.compress = function(node) { } function is_undefined(node, compressor) { - return node.is_undefined + return node == null + || node.is_undefined || node instanceof AST_Undefined || node instanceof AST_UnaryPrefix && node.operator == "void" @@ -9915,7 +9910,7 @@ Compressor.prototype.compress = function(node) { if (argname instanceof AST_DefaultValue) { if (!has_default) has_default = 1; var arg = has_default == 1 && self.args[index]; - if (arg && !is_undefined(arg)) has_default = 2; + if (!is_undefined(arg)) has_default = 2; if (has_arg_refs(fn, argname.value)) return false; argname = argname.name; } @@ -13176,7 +13171,6 @@ Compressor.prototype.compress = function(node) { if (!no_return) { if (async) scan_local_returns(inlined, function(node) { var value = node.value; - if (!value) return; if (is_undefined(value)) return; node.value = make_node(AST_Await, call, { expression: value }); }); @@ -13320,10 +13314,7 @@ Compressor.prototype.compress = function(node) { if (!no_return) scan_local_returns(inlined, function(node) { node.in_bool = false; var value = node.value; - if (op == "void") { - if (!value) return; - if (is_undefined(value)) return; - } + if (op == "void" && is_undefined(value)) return; node.value = make_node(AST_UnaryPrefix, self, { operator: op, expression: value || make_node(AST_Undefined, node).transform(compressor), @@ -13371,8 +13362,7 @@ Compressor.prototype.compress = function(node) { OPT(AST_Return, function(self, compressor) { var value = self.value; - if (compressor.option("side_effects") - && value + if (value && compressor.option("side_effects") && is_undefined(value, compressor) && !in_async_generator(compressor.find_parent(AST_Scope))) { self.value = null; diff --git a/test/compress/let.js b/test/compress/let.js index d3718923..1942fdec 100644 --- a/test/compress/let.js +++ b/test/compress/let.js @@ -1639,7 +1639,7 @@ issue_4438: { ; else { let a = console.log; - a("PASS"); + void a("PASS"); } } f();