fix corner case in dead_code (#4981)

This commit is contained in:
Alex Lam S.L
2021-05-29 20:16:18 +01:00
committed by GitHub
parent 260431f4e0
commit 8d23496e0f
2 changed files with 42 additions and 1 deletions

View File

@@ -3638,11 +3638,17 @@ merge(Compressor.prototype, {
}
function extract_declarations_from_unreachable_code(compressor, stat, target) {
if (!(stat instanceof AST_Definitions || stat instanceof AST_LambdaDefinition)) {
if (!(stat instanceof AST_DefClass
|| stat instanceof AST_Definitions
|| stat instanceof AST_LambdaDefinition)) {
AST_Node.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start);
}
var block;
stat.walk(new TreeWalker(function(node, descend) {
if (node instanceof AST_DefClass) {
push(node);
return true;
}
if (node instanceof AST_Definitions) {
var defns = [];
if (node.remove_initializers(compressor, defns)) {

View File

@@ -260,6 +260,9 @@ block_scoped: {
expect: {
"use strict";
0;
{
class A {}
}
if (console) {
class B {}
}
@@ -269,6 +272,38 @@ block_scoped: {
node_version: ">=4"
}
retain_declaration: {
options = {
dead_code: true,
}
input: {
"use strict";
var a = "FAIL";
try {
console.log(function() {
return a;
class a {}
}());
} catch (e) {
console.log("PASS");
}
}
expect: {
"use strict";
var a = "FAIL";
try {
console.log(function() {
return a;
class a {}
}());
} catch (e) {
console.log("PASS");
}
}
expect_stdout: "PASS"
node_version: ">=4"
}
drop_extends: {
options = {
inline: true,