fix corner case in dead_code (#4981)
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user