Skip to content

Commit 774feea

Browse files
authored
minor clean-ups (#5300)
1 parent d96c59f commit 774feea

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

lib/compress.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@ Compressor.prototype.compress = function(node) {
25302530
}
25312531
if (names.has(sym.name)) continue;
25322532
names.set(sym.name, true);
2533-
if (value) arg = !arg || is_undefined(arg) ? value : null;
2533+
if (value) arg = is_undefined(arg) ? value : null;
25342534
if (!arg && !value) {
25352535
arg = make_node(AST_Undefined, sym).transform(compressor);
25362536
} else if (arg instanceof AST_Lambda && arg.pinned()) {
@@ -3423,18 +3423,14 @@ Compressor.prototype.compress = function(node) {
34233423
return false;
34243424
}
34253425

3426-
function is_return_void(value) {
3427-
return !value || value instanceof AST_UnaryPrefix && value.operator == "void";
3428-
}
3429-
34303426
function match_target(target) {
34313427
return last_of(compressor, function(node) {
34323428
return node === target;
34333429
});
34343430
}
34353431

34363432
function can_drop_abort(ab) {
3437-
if (ab instanceof AST_Return) return in_lambda && is_return_void(ab.value);
3433+
if (ab instanceof AST_Return) return in_lambda && is_undefined(ab.value);
34383434
if (!(ab instanceof AST_LoopControl)) return false;
34393435
var lct = compressor.loopcontrol_target(ab);
34403436
if (ab instanceof AST_Continue) return match_target(loop_body(lct));
@@ -3481,9 +3477,7 @@ Compressor.prototype.compress = function(node) {
34813477
block = last.body;
34823478
}
34833479
block.pop();
3484-
if (ab.value) block.push(make_node(AST_SimpleStatement, ab.value, {
3485-
body: ab.value.expression
3486-
}));
3480+
if (ab.value) block.push(make_node(AST_SimpleStatement, ab.value, { body: ab.value }));
34873481
return body;
34883482
}
34893483

@@ -4000,7 +3994,8 @@ Compressor.prototype.compress = function(node) {
40003994
}
40013995

40023996
function is_undefined(node, compressor) {
4003-
return node.is_undefined
3997+
return node == null
3998+
|| node.is_undefined
40043999
|| node instanceof AST_Undefined
40054000
|| node instanceof AST_UnaryPrefix
40064001
&& node.operator == "void"
@@ -9915,7 +9910,7 @@ Compressor.prototype.compress = function(node) {
99159910
if (argname instanceof AST_DefaultValue) {
99169911
if (!has_default) has_default = 1;
99179912
var arg = has_default == 1 && self.args[index];
9918-
if (arg && !is_undefined(arg)) has_default = 2;
9913+
if (!is_undefined(arg)) has_default = 2;
99199914
if (has_arg_refs(fn, argname.value)) return false;
99209915
argname = argname.name;
99219916
}
@@ -13176,7 +13171,6 @@ Compressor.prototype.compress = function(node) {
1317613171
if (!no_return) {
1317713172
if (async) scan_local_returns(inlined, function(node) {
1317813173
var value = node.value;
13179-
if (!value) return;
1318013174
if (is_undefined(value)) return;
1318113175
node.value = make_node(AST_Await, call, { expression: value });
1318213176
});
@@ -13320,10 +13314,7 @@ Compressor.prototype.compress = function(node) {
1332013314
if (!no_return) scan_local_returns(inlined, function(node) {
1332113315
node.in_bool = false;
1332213316
var value = node.value;
13323-
if (op == "void") {
13324-
if (!value) return;
13325-
if (is_undefined(value)) return;
13326-
}
13317+
if (op == "void" && is_undefined(value)) return;
1332713318
node.value = make_node(AST_UnaryPrefix, self, {
1332813319
operator: op,
1332913320
expression: value || make_node(AST_Undefined, node).transform(compressor),
@@ -13371,8 +13362,7 @@ Compressor.prototype.compress = function(node) {
1337113362

1337213363
OPT(AST_Return, function(self, compressor) {
1337313364
var value = self.value;
13374-
if (compressor.option("side_effects")
13375-
&& value
13365+
if (value && compressor.option("side_effects")
1337613366
&& is_undefined(value, compressor)
1337713367
&& !in_async_generator(compressor.find_parent(AST_Scope))) {
1337813368
self.value = null;

test/compress/let.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ issue_4438: {
16391639
;
16401640
else {
16411641
let a = console.log;
1642-
a("PASS");
1642+
void a("PASS");
16431643
}
16441644
}
16451645
f();

0 commit comments

Comments
 (0)