diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-02-17 05:11:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-17 05:11:31 +0800 |
commit | 7fdd2082a65fd11d3d99c5e62241264ae6e82afc (patch) | |
tree | 9b1b7f1cdb367c78a6525ebaaf4c7d7cc891cad0 /lib/compress.js | |
parent | e529f54e90c2ff63f043333c50e6c96f6b3c7e6d (diff) | |
download | tracifyjs-7fdd2082a65fd11d3d99c5e62241264ae6e82afc.tar.gz tracifyjs-7fdd2082a65fd11d3d99c5e62241264ae6e82afc.zip |
drop unused "class" definition IIFEs (#2923)
fixes #805
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/lib/compress.js b/lib/compress.js index 63830d09..08248309 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2004,7 +2004,7 @@ merge(Compressor.prototype, { if (this.properties[i].value instanceof AST_Accessor) return true; return false; }); - def(AST_Function, return_false); + def(AST_Lambda, return_false); def(AST_UnaryPostfix, return_false); def(AST_UnaryPrefix, function() { return this.operator == "void"; @@ -2023,8 +2023,9 @@ merge(Compressor.prototype, { }) def(AST_Dot, function(compressor) { if (!is_strict(compressor)) return false; - if (this.expression instanceof AST_Function && this.property == "prototype") return false; - return true; + var exp = this.expression; + if (exp instanceof AST_SymbolRef) exp = exp.fixed_value(); + return !(exp instanceof AST_Lambda && this.property == "prototype"); }); def(AST_Sequence, function(compressor) { return this.tail_node()._dot_throw(compressor); @@ -3009,11 +3010,18 @@ merge(Compressor.prototype, { if (self.uses_eval || self.uses_with) return; var drop_funcs = !(self instanceof AST_Toplevel) || compressor.toplevel.funcs; var drop_vars = !(self instanceof AST_Toplevel) || compressor.toplevel.vars; - var assign_as_unused = /keep_assign/.test(compressor.option("unused")) ? return_false : function(node) { + var assign_as_unused = /keep_assign/.test(compressor.option("unused")) ? return_false : function(node, props) { + var sym; if (node instanceof AST_Assign && (node.write_only || node.operator == "=")) { - return node.left; + sym = node.left; + } else if (node instanceof AST_Unary && node.write_only) { + sym = node.expression; } - if (node instanceof AST_Unary && node.write_only) return node.expression; + 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; }; var in_use = []; var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use @@ -3089,17 +3097,26 @@ merge(Compressor.prototype, { function before(node, descend, in_list) { var parent = tt.parent(); if (drop_vars) { - var sym = assign_as_unused(node); + var props = [], sym = assign_as_unused(node, props); if (sym instanceof AST_SymbolRef) { var def = sym.definition(); var in_use = def.id in in_use_ids; + var value = null; if (node instanceof AST_Assign) { - if (!in_use || def.id in fixed_ids && fixed_ids[def.id] !== node) { - return maintain_this_binding(parent, node, node.right.transform(tt)); + if (!in_use || node.left === sym && def.id in fixed_ids && fixed_ids[def.id] !== node) { + value = node.right; } - } else if (!in_use) return make_node(AST_Number, node, { - value: 0 - }); + } else if (!in_use) { + value = make_node(AST_Number, node, { + value: 0 + }); + } + if (value) { + props.push(value); + return maintain_this_binding(parent, node, make_sequence(node, props.map(function(prop) { + return prop.transform(tt); + }))); + } } } if (scope !== self) return; @@ -3277,12 +3294,15 @@ merge(Compressor.prototype, { self.transform(tt); function scan_ref_scoped(node, descend) { - var node_def, sym = assign_as_unused(node); + var node_def, props = [], sym = assign_as_unused(node, props); if (sym instanceof AST_SymbolRef && self.variables.get(sym.name) === (node_def = sym.definition())) { + props.forEach(function(prop) { + prop.walk(tw); + }); if (node instanceof AST_Assign) { node.right.walk(tw); - if (!node_def.chained && node.left.fixed_value() === node.right) { + if (node.left === sym && !node_def.chained && sym.fixed_value() === node.right) { fixed_ids[node_def.id] = node; } } |