fix corner case in unused (#3234)

fixes #3233
This commit is contained in:
Alex Lam S.L
2018-08-23 06:03:39 +08:00
committed by GitHub
parent 57fb58b263
commit 694ca5d045
3 changed files with 36 additions and 14 deletions

View File

@@ -450,8 +450,7 @@ merge(Compressor.prototype, {
return value instanceof AST_Node && def.fixed.parent_scope === scope;
}
return all(def.orig, function(sym) {
return !(sym instanceof AST_SymbolDefun
|| sym instanceof AST_SymbolLambda);
return !(sym instanceof AST_SymbolDefun || sym instanceof AST_SymbolLambda);
});
}
@@ -3329,13 +3328,14 @@ merge(Compressor.prototype, {
} else if (node instanceof AST_Unary && node.write_only) {
sym = node.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;
}
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;
}
return sym;
return sym instanceof AST_SymbolRef && all(sym.definition().orig, function(sym) {
return !(sym instanceof AST_SymbolLambda);
}) && sym;
};
var in_use = [];
var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use
@@ -3430,7 +3430,7 @@ merge(Compressor.prototype, {
var parent = tt.parent();
if (drop_vars) {
var props = [], sym = assign_as_unused(node, props);
if (sym instanceof AST_SymbolRef) {
if (sym) {
var def = sym.definition();
var in_use = def.id in in_use_ids;
var value = null;
@@ -3629,8 +3629,7 @@ merge(Compressor.prototype, {
function scan_ref_scoped(node, descend) {
var node_def, props = [], sym = assign_as_unused(node, props);
if (sym instanceof AST_SymbolRef
&& self.variables.get(sym.name) === (node_def = sym.definition())) {
if (sym && self.variables.get(sym.name) === (node_def = sym.definition())) {
props.forEach(function(prop) {
prop.walk(tw);
});