diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-30 08:54:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-30 16:54:29 +0800 |
commit | 0cd4a199b09a3647a4596bfdb0074a2d09fb8cda (patch) | |
tree | 1183e98bd002afb7f4cdd5d3667a46d7c399a1d1 /lib/compress.js | |
parent | 35435d4bd302e33011e91260f2c4b94f429b7a52 (diff) | |
download | tracifyjs-0cd4a199b09a3647a4596bfdb0074a2d09fb8cda.tar.gz tracifyjs-0cd4a199b09a3647a4596bfdb0074a2d09fb8cda.zip |
fix corner case in `conditionals` (#4599)
fixes #4598
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/compress.js b/lib/compress.js index a662b991..d65861a6 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4913,10 +4913,10 @@ merge(Compressor.prototype, { return self; }); - function trim_block(node) { + function trim_block(node, in_list) { switch (node.body.length) { case 0: - return make_node(AST_EmptyStatement, node); + return in_list ? List.skip : make_node(AST_EmptyStatement, node); case 1: var stat = node.body[0]; if (!(stat instanceof AST_Const || stat instanceof AST_Let)) return stat; @@ -5983,12 +5983,8 @@ merge(Compressor.prototype, { return node; } }, function(node, in_list) { - if (node instanceof AST_BlockStatement) switch (node.body.length) { - case 0: - return in_list ? List.skip : make_node(AST_EmptyStatement, node); - case 1: - var stat = node.body[0]; - if (!(stat instanceof AST_Const || stat instanceof AST_Let)) return stat; + if (node instanceof AST_BlockStatement) { + return trim_block(node, in_list); } else if (node instanceof AST_For) { // Certain combination of unused name + side effect leads to invalid AST: // https://github.com/mishoo/UglifyJS/issues/44 @@ -7515,7 +7511,7 @@ merge(Compressor.prototype, { var exprs = []; for (var i = 0; i < stat.body.length; i++) { var line = stat.body[i]; - if (line instanceof AST_Defun) { + if (is_defun(line)) { defuns.push(line); } else if (line instanceof AST_EmptyStatement) { continue; @@ -7532,7 +7528,7 @@ merge(Compressor.prototype, { } return exprs; } - if (stat instanceof AST_Defun) { + if (is_defun(stat)) { defuns.push(stat); return []; } |