Skip to content

Commit

Permalink
fix corner case in dead_code (#4981)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed May 29, 2021
1 parent 260431f commit 8d23496
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
35 changes: 35 additions & 0 deletions test/compress/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ block_scoped: {
expect: {
"use strict";
0;
{
class A {}
}
if (console) {
class B {}
}
Expand All @@ -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,
Expand Down

0 comments on commit 8d23496

Please sign in to comment.