diff --git a/README.md b/README.md index de6f7c6f..6c58aa95 100644 --- a/README.md +++ b/README.md @@ -1407,3 +1407,17 @@ To allow for better optimizations, the compiler makes various assumptions: // Actual: SyntaxError: Unexpected reserved word ``` UglifyJS may modify the input which in turn may suppress those errors. +- Later versions of Chrome and Node.js will give incorrect results with the + following: + ```javascript + try { + f(); + function f() { + throw 42; + } + } catch (e) {} + console.log(typeof f); + // Expected: "function" + // Actual: "undefined" + ``` + UglifyJS may modify the input which in turn may suppress those errors. diff --git a/lib/compress.js b/lib/compress.js index 26964c8b..19bef6d3 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1559,7 +1559,10 @@ Compressor.prototype.compress = function(node) { AST_SymbolRef.DEFMETHOD("is_immutable", function() { var def = this.redef || this.definition(); - return (this.in_arg || def.orig.length == 1) && def.orig[0] instanceof AST_SymbolLambda; + if (!(def.orig[0] instanceof AST_SymbolLambda)) return false; + if (def.orig.length == 1) return true; + if (!this.in_arg) return false; + return !(def.orig[1] instanceof AST_SymbolFunarg); }); AST_Node.DEFMETHOD("convert_symbol", noop); diff --git a/test/compress/default-values.js b/test/compress/default-values.js index 941a3415..7fdd83cc 100644 --- a/test/compress/default-values.js +++ b/test/compress/default-values.js @@ -2448,3 +2448,17 @@ issue_5465: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5485: { + options = { + comparisons: true, + } + input: { + (function f(f, a = console.log(void 0 === f ? "PASS" : "FAIL")) {})(); + } + expect: { + (function f(f, a = console.log(void 0 === f ? "PASS" : "FAIL")) {})(); + } + expect_stdout: "PASS" + node_version: ">=6" +} diff --git a/test/compress/destructured.js b/test/compress/destructured.js index e88152e6..60b0b69d 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -3626,3 +3626,23 @@ issue_5454: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5485: { + options = { + comparisons: true, + } + input: { + (function f({ + p: f, + [console.log(void 0 === f ? "PASS" : "FAIL")]: a, + }) {})(42); + } + expect: { + (function f({ + p: f, + [console.log(void 0 === f ? "PASS" : "FAIL")]: a, + }) {})(42); + } + expect_stdout: "PASS" + node_version: ">=6" +}