diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-07-23 10:17:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-23 17:17:20 +0800 |
commit | 6a3fe9d1dfd3ec4543dc71b72e990bed2c6022ef (patch) | |
tree | a3ccb1226a504b17421017955121977a6ddd2242 /lib | |
parent | ec7fadcb5b22153c77d68d80636f6e893542a5d2 (diff) | |
download | tracifyjs-6a3fe9d1dfd3ec4543dc71b72e990bed2c6022ef.tar.gz tracifyjs-6a3fe9d1dfd3ec4543dc71b72e990bed2c6022ef.zip |
fix corner cases in `reduce_vars` (#5097)
fixes #5096
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/lib/compress.js b/lib/compress.js index 5bb378e5..e0252646 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -884,15 +884,12 @@ merge(Compressor.prototype, { } if (ld && right instanceof AST_LambdaExpression) { walk_assign(); - if (ld.escaped.length) { - right.walk(tw); - } else { - right.parent_scope.resolve().fn_defs.push(right); - right.safe_ids = null; - if (!node.write_only) mark_fn_def(tw, ld, right); - } + right.parent_scope.resolve().fn_defs.push(right); + right.safe_ids = null; + if (!ld.fixed || !node.write_only) mark_fn_def(tw, ld, right); return true; - } else if (scan) { + } + if (scan) { right.walk(tw); walk_assign(); return true; @@ -1397,31 +1394,38 @@ merge(Compressor.prototype, { var node = this; var value = node.value; if (value instanceof AST_LambdaExpression && node.name instanceof AST_SymbolDeclaration) { + walk_defn(); value.parent_scope.resolve().fn_defs.push(value); value.safe_ids = null; + var ld = node.name.definition(); + if (!ld.fixed) mark_fn_def(tw, ld, value); } else if (value) { value.walk(tw); - } else if (!(tw.parent() instanceof AST_Let)) { - return; + walk_defn(); + } else if (tw.parent() instanceof AST_Let) { + walk_defn(); } - scan_declaration(tw, compressor, node.name, function() { - return node.value || make_node(AST_Undefined, node); - }, function(name, fixed) { - var d = name.definition(); - if (fixed && safe_to_assign(tw, d, true)) { - mark(tw, d); - tw.loop_ids[d.id] = tw.in_loop; - d.fixed = fixed; - d.fixed.assigns = [ node ]; - if (name instanceof AST_SymbolConst && d.redefined() - || !(can_drop_symbol(name) || is_safe_lexical(d))) { - d.single_use = false; - } - } else { - d.fixed = false; - } - }); return true; + + function walk_defn() { + scan_declaration(tw, compressor, node.name, function() { + return node.value || make_node(AST_Undefined, node); + }, function(name, fixed) { + var d = name.definition(); + if (fixed && safe_to_assign(tw, d, true)) { + mark(tw, d); + tw.loop_ids[d.id] = tw.in_loop; + d.fixed = fixed; + d.fixed.assigns = [ node ]; + if (name instanceof AST_SymbolConst && d.redefined() + || !(can_drop_symbol(name) || is_safe_lexical(d))) { + d.single_use = false; + } + } else { + d.fixed = false; + } + }); + } }); def(AST_While, function(tw, descend) { var save_loop = tw.in_loop; |