diff --git a/lib/compress.js b/lib/compress.js index 494f9db1..c6a82674 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10255,8 +10255,18 @@ Compressor.prototype.compress = function(node) { return all(this.definitions, function(defn) { return !defn.name.match_symbol(function(node) { if (!(node instanceof AST_SymbolDeclaration)) return false; - if (node.definition().first_decl !== node) return true; - return !safe_from_tdz(compressor, node); + var def = node.definition(); + if (def.first_decl !== node) return true; + if (!safe_from_tdz(compressor, node)) return true; + var defn_scope = node.scope; + if (defn_scope instanceof AST_Scope) return false; + return !all(def.references, function(ref) { + var scope = ref.scope; + do { + if (scope === defn_scope) return true; + } while (scope = scope.parent_scope); + return false; + }); }, true); }); }); diff --git a/test/compress/let.js b/test/compress/let.js index 7e5185c9..2321bfbc 100644 --- a/test/compress/let.js +++ b/test/compress/let.js @@ -2328,3 +2328,66 @@ issue_5741: { expect_stdout: "PASS" node_version: ">=4" } + +issue_5745_1: { + options = { + join_vars: true, + reduce_vars: true, + toplevel: true, + } + input: { + "use strict"; + { + let f = function() { + return f && "PASS"; + }; + var a = f(); + } + a; + console.log(a); + } + expect: { + "use strict"; + { + let f = function() { + return f && "PASS"; + }; + var a = f(); + } + a; + console.log(a); + } + expect_stdout: "PASS" + node_version: ">=4" +} + +issue_5745_2: { + options = { + join_vars: true, + reduce_vars: true, + toplevel: true, + } + input: { + "use strict"; + { + let f = function() { + return f && "PASS"; + }; + var a = f(); + a; + console.log(a); + } + } + expect: { + "use strict"; + { + let f = function() { + return f && "PASS"; + }, a = f(); + a; + console.log(a); + } + } + expect_stdout: "PASS" + node_version: ">=4" +} diff --git a/tools/node.js b/tools/node.js index 7ca19829..9e7960b1 100644 --- a/tools/node.js +++ b/tools/node.js @@ -100,7 +100,7 @@ function infer_options(options) { exports.default_options = function() { var defs = infer_options({ 0: 0 }); Object.keys(defs).forEach(function(component) { - var options = {}; + var options = { module: false }; options[component] = { 0: 0 }; if (options = infer_options(options)) { defs[component] = options;