Skip to content

Commit

Permalink
fix corner case in comparisons (#5486)
Browse files Browse the repository at this point in the history
fixes #5485
alexlamsl authored Jun 4, 2022
1 parent ad5f5ef commit a025392
Showing 4 changed files with 52 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
@@ -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);
14 changes: 14 additions & 0 deletions test/compress/default-values.js
Original file line number Diff line number Diff line change
@@ -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"
}
20 changes: 20 additions & 0 deletions test/compress/destructured.js
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit a025392

Please sign in to comment.