diff --git a/lib/scope.js b/lib/scope.js index e1f29c76..de92fc94 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -318,6 +318,9 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init){ var def = this.variables.get(symbol.name); if (def) { def.orig.push(symbol); + if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) { + def.init = init; + } } else { def = new SymbolDef(this, symbol, init); this.variables.set(symbol.name, def); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 8fd21e86..3d993b90 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -5237,3 +5237,42 @@ defun_catch_6: { } expect_stdout: "42" } + +duplicate_lambda_defun_name_1: { + options = { + reduce_vars: true, + } + input: { + console.log(function f(a) { + function f() {} + return f.length; + }()); + } + expect: { + console.log(function f(a) { + function f() {} + return f.length; + }()); + } + expect_stdout: "0" +} + +duplicate_lambda_defun_name_2: { + options = { + passes: 2, + reduce_vars: true, + unused: true, + } + input: { + console.log(function f(a) { + function f() {} + return f.length; + }()); + } + expect: { + console.log(function(a) { + return function() {}.length; + }()); + } + expect_stdout: "0" +} diff --git a/test/compress/typeof.js b/test/compress/typeof.js index 9eaf05e4..72e77beb 100644 --- a/test/compress/typeof.js +++ b/test/compress/typeof.js @@ -138,3 +138,43 @@ typeof_defun_2: { "2", ] } + +duplicate_defun_arg_name: { + options = { + evaluate: true, + reduce_vars: true, + typeofs: true, + } + input: { + function long_name(long_name) { + return typeof long_name; + } + console.log(typeof long_name, long_name()); + } + expect: { + function long_name(long_name) { + return typeof long_name; + } + console.log(typeof long_name, long_name()); + } + expect_stdout: "function undefined" +} + +duplicate_lambda_arg_name: { + options = { + evaluate: true, + reduce_vars: true, + typeofs: true, + } + input: { + console.log(function long_name(long_name) { + return typeof long_name; + }()); + } + expect: { + console.log(function long_name(long_name) { + return typeof long_name; + }()); + } + expect_stdout: "undefined" +}