fix corner case in unused (#3747)

fixes #3746
This commit is contained in:
Alex Lam S.L
2020-03-06 18:27:42 +00:00
committed by GitHub
parent bdc8ef2218
commit 421bb7083a
2 changed files with 41 additions and 6 deletions

View File

@@ -3916,14 +3916,18 @@ merge(Compressor.prototype, {
} else if (node instanceof AST_Unary) {
if (node.write_only) sym = node.expression;
}
if (!/strict/.test(compressor.option("pure_getters"))) return sym instanceof AST_SymbolRef && sym;
while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) {
if (sym instanceof AST_Sub) props.unshift(sym.property);
sym = sym.expression;
if (/strict/.test(compressor.option("pure_getters"))) {
while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) {
if (sym instanceof AST_Sub) props.unshift(sym.property);
sym = sym.expression;
}
}
return sym instanceof AST_SymbolRef && all(sym.definition().orig, function(sym) {
if (!(sym instanceof AST_SymbolRef)) return;
if (compressor.exposed(sym.definition())) return;
if (!all(sym.definition().orig, function(sym) {
return !(sym instanceof AST_SymbolLambda);
}) && sym;
})) return;
return sym;
};
var in_use = [];
var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use

View File

@@ -2413,3 +2413,34 @@ issue_3673: {
}
expect_stdout: "PASS"
}
issue_3746: {
options = {
keep_fargs: "strict",
side_effects: true,
unused: true,
}
input: {
try {
A;
} catch (e) {
var e;
}
(function f(a) {
e = a;
})();
console.log("PASS");
}
expect: {
try {
A;
} catch (e) {
var e;
}
(function(a) {
e = a;
})();
console.log("PASS");
}
expect_stdout: "PASS"
}