fix corner case in loops (#4684)

fixes #4683
This commit is contained in:
Alex Lam S.L
2021-02-24 20:41:21 +00:00
committed by GitHub
parent b8672b55b2
commit a5e6946f74
2 changed files with 23 additions and 4 deletions

View File

@@ -1512,7 +1512,7 @@ merge(Compressor.prototype, {
return !is_lexical_definition(stat); return !is_lexical_definition(stat);
}) ? thing.body : [ thing ]; }) ? thing.body : [ thing ];
if (thing instanceof AST_EmptyStatement) return []; if (thing instanceof AST_EmptyStatement) return [];
if (thing instanceof AST_Statement) return [ thing ]; if (is_statement(thing)) return [ thing ];
throw new Error("Can't convert thing to statement array"); throw new Error("Can't convert thing to statement array");
} }
@@ -3382,7 +3382,7 @@ merge(Compressor.prototype, {
return in_list ? List.skip : make_node(AST_EmptyStatement, node); return in_list ? List.skip : make_node(AST_EmptyStatement, node);
} }
if (node instanceof AST_Scope) return node; if (node instanceof AST_Scope) return node;
if (!(node instanceof AST_Statement)) return node; if (!is_statement(node)) return node;
})); }));
} }
} }
@@ -7504,7 +7504,7 @@ merge(Compressor.prototype, {
|| first instanceof AST_Continue && external_target(first) || first instanceof AST_Continue && external_target(first)
|| first instanceof AST_Exit)) { || first instanceof AST_Exit)) {
var body = []; var body = [];
if (self.init instanceof AST_Statement) { if (is_statement(self.init)) {
body.push(self.init); body.push(self.init);
} else if (self.init) { } else if (self.init) {
body.push(make_node(AST_SimpleStatement, self.init, { body.push(make_node(AST_SimpleStatement, self.init, {
@@ -7606,7 +7606,7 @@ merge(Compressor.prototype, {
if (!cond) { if (!cond) {
if (compressor.option("dead_code")) { if (compressor.option("dead_code")) {
var body = []; var body = [];
if (self.init instanceof AST_Statement) { if (is_statement(self.init)) {
body.push(self.init); body.push(self.init);
} else if (self.init) { } else if (self.init) {
body.push(make_node(AST_SimpleStatement, self.init, { body.push(make_node(AST_SimpleStatement, self.init, {

View File

@@ -596,3 +596,22 @@ issue_4681: {
expect_stdout: "function" expect_stdout: "function"
node_version: ">=12" node_version: ">=12"
} }
issue_4683: {
options = {
dead_code: true,
evaluate: true,
loops: true,
}
input: {
"use strict";
for (class extends null {}; void console.log("PASS"); );
}
expect: {
"use strict";
(class extends null {});
void console.log("PASS");
}
expect_stdout: "PASS"
node_version: ">=4"
}