diff --git a/lib/compress.js b/lib/compress.js index e4d72d3b..27002f0a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8387,9 +8387,8 @@ Compressor.prototype.compress = function(node) { var scopes = [ this ]; if (orig instanceof AST_SymbolDeclaration) orig.definition().references.forEach(function(ref) { var s = ref.scope; - if (member(s, scopes)) return; do { - push_uniq(scopes, s); + if (!push_uniq(scopes, s)) return; s = s.parent_scope; } while (s && s !== this); }); @@ -12251,12 +12250,19 @@ Compressor.prototype.compress = function(node) { if (fixed instanceof AST_DefClass) fixed = to_class_expr(fixed); if (fixed instanceof AST_LambdaDefinition) fixed = to_func_expr(fixed); if (is_lambda(fixed)) { - var scope = self.scope.resolve(); + var scopes = []; + var scope = self.scope; + do { + scopes.push(scope); + if (scope === def.scope) break; + } while (scope = scope.parent_scope); fixed.enclosed.forEach(function(def) { if (fixed.variables.has(def.name)) return; - if (scope.var_names().has(def.name)) return; - scope.enclosed.push(def); - scope.var_names().set(def.name, true); + for (var i = 0; i < scopes.length; i++) { + var scope = scopes[i]; + if (!push_uniq(scope.enclosed, def)) return; + scope.var_names().set(def.name, true); + } }); } var value; diff --git a/lib/scope.js b/lib/scope.js index 7b9e33de..3d197571 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -286,7 +286,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { // ensure mangling works if `catch` reuses a scope variable var redef = def.redefined(); if (redef) for (var s = node.scope; s; s = s.parent_scope) { - push_uniq(s.enclosed, redef); + if (!push_uniq(s.enclosed, redef)) break; if (s === redef.scope) break; } } else if (node instanceof AST_SymbolConst) { @@ -480,7 +480,7 @@ AST_Lambda.DEFMETHOD("init_vars", function(parent_scope) { AST_Symbol.DEFMETHOD("mark_enclosed", function(options) { var def = this.definition(); for (var s = this.scope; s; s = s.parent_scope) { - push_uniq(s.enclosed, def); + if (!push_uniq(s.enclosed, def)) break; if (!options) { s._var_names = undefined; } else { diff --git a/test/compress/functions.js b/test/compress/functions.js index 10a4b1f5..dd6f26a8 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -8646,3 +8646,42 @@ module_inline: { } expect_stdout: "true" } + +single_use_inline_collision: { + options = { + inline: true, + reduce_funcs: true, + reduce_vars: true, + unused: true, + } + input: { + var a = "PASS"; + (function() { + var f = function() { + while (console.log(a)); + }; + (function() { + (function() { + f(); + })(); + (function(a) { + a || a("FAIL"); + })(console.log); + })(); + })(); + } + expect: { + var a = "PASS"; + (function() { + (function() { + while (console.log(a)); + return; + })(); + (function(a) { + a || a("FAIL"); + })(console.log); + return; + })(); + } + expect_stdout: "PASS" +} diff --git a/test/reduce.js b/test/reduce.js index 5da2b152..82670842 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -160,6 +160,11 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) return expr instanceof U.AST_Spread ? expr.expression : expr; } } + else if (node instanceof U.AST_Await) { + node.start._permute++; + CHANGED = true; + return node.expression; + } else if (node instanceof U.AST_Binary) { var permute = ((node.start._permute += step) * steps | 0) % 4; var expr = [