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) {
|
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);
|
AST_Node.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start);
|
||||||
}
|
}
|
||||||
var block;
|
var block;
|
||||||
stat.walk(new TreeWalker(function(node, descend) {
|
stat.walk(new TreeWalker(function(node, descend) {
|
||||||
|
if (node instanceof AST_DefClass) {
|
||||||
|
push(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (node instanceof AST_Definitions) {
|
if (node instanceof AST_Definitions) {
|
||||||
var defns = [];
|
var defns = [];
|
||||||
if (node.remove_initializers(compressor, defns)) {
|
if (node.remove_initializers(compressor, defns)) {
|
||||||
|
|||||||
@@ -260,6 +260,9 @@ block_scoped: {
|
|||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
"use strict";
|
||||||
0;
|
0;
|
||||||
|
{
|
||||||
|
class A {}
|
||||||
|
}
|
||||||
if (console) {
|
if (console) {
|
||||||
class B {}
|
class B {}
|
||||||
}
|
}
|
||||||
@@ -269,6 +272,38 @@ block_scoped: {
|
|||||||
node_version: ">=4"
|
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: {
|
drop_extends: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user