diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-08-23 06:03:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-23 06:03:39 +0800 |
commit | 694ca5d04590fc22001f7a1c9cc185198f32248f (patch) | |
tree | 278e456909f7c5bcb8783e921129838b6c866819 /lib/compress.js | |
parent | 57fb58b263677d8667eadc94634c2018934a0f52 (diff) | |
download | tracifyjs-694ca5d04590fc22001f7a1c9cc185198f32248f.tar.gz tracifyjs-694ca5d04590fc22001f7a1c9cc185198f32248f.zip |
fix corner case in `unused` (#3234)
fixes #3233
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js index eded00c7..ad86dd84 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); }); |