diff --git a/lib/compress.js b/lib/compress.js index 74e09299b2..1e358599f5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1378,6 +1378,7 @@ Compressor.prototype.compress = function(node) { def(AST_LambdaDefinition, function(tw, descend, compressor) { var fn = this; var def = fn.name.definition(); + if (!safe_to_trim(fn)) def.fixed = false; var parent = tw.parent(); if (parent instanceof AST_ExportDeclaration || parent instanceof AST_ExportDefault) def.single_use = false; if (!safe_to_visit(tw, fn)) return true; @@ -3545,17 +3546,10 @@ Compressor.prototype.compress = function(node) { if (node instanceof AST_Symbol) { var def = node.definition(); var scope = def.scope.resolve(); - var found = false; - var avoid = def.orig.reduce(function(scopes, sym) { + def.orig.forEach(function(sym) { if (sym instanceof AST_SymbolDefun) { if (sym.scope !== scope) push_uniq(scopes, sym.scope); - } else { - found = true; } - return scopes; - }, []); - if (found) avoid.forEach(function(scope) { - push_uniq(scopes, scope); }); } }); diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index df6e113492..f1f4d61188 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -10357,3 +10357,81 @@ issue_5869: { } expect_stdout: TypeError("Cannot set properties of undefined") } + +issue_5915_1: { + options = { + collapse_vars: true, + } + input: { + f = void 0; + { + console.log(typeof f); + function f() {} + } + } + expect: { + f = void 0; + { + console.log(typeof f); + function f() {} + } + } + expect_stdout: true +} + +issue_5915_2: { + options = { + collapse_vars: true, + } + input: { + f = void 0; + { + function f() {} + console.log(typeof f); + } + } + expect: { + f = void 0; + { + function f() {} + console.log(typeof f); + } + } + expect_stdout: true +} + +issue_5915_3: { + options = { + collapse_vars: true, + } + input: { + f = void 0; + function f() {} + { + console.log(typeof f); + } + } + expect: { + function f() {} + console.log(typeof (f = void 0)); + } + expect_stdout: "undefined" +} + +issue_5915_4: { + options = { + collapse_vars: true, + } + input: { + { + f = void 0; + function f() {} + console.log(typeof f); + } + } + expect: { + function f() {} + console.log(typeof (f = void 0)); + } + expect_stdout: "undefined" +} diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index edd95bd009..8108f18d10 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -8493,3 +8493,96 @@ issue_5892: { } expect_stdout: "PASS" } + +issue_5915_1: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + f = void 0; + if (console) { + console.log(typeof f); + function f() {} + } + } + expect: { + f = void 0; + if (console) { + console.log(typeof f); + function f() {} + } + } + expect_stdout: true +} + +issue_5915_2: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + f = void 0; + if (console) { + function f() {} + console.log(typeof f); + } + } + expect: { + f = void 0; + if (console) { + function f() {} + console.log(typeof f); + } + } + expect_stdout: true +} + +issue_5915_3: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + f = void 0; + function f() {} + if (console) { + console.log(typeof f); + } + } + expect: { + void 0; + if (console) + console.log("undefined"); + } + expect_stdout: "undefined" +} + +issue_5915_4: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + if (console) { + f = void 0; + function f() {} + console.log(typeof f); + } + } + expect: { + if (console) { + void 0; + console.log("undefined"); + } + } + expect_stdout: "undefined" +}