fix corner case in comparisons (#5486)

fixes #5485
This commit is contained in:
Alex Lam S.L
2022-06-04 17:47:38 +01:00
committed by GitHub
parent ad5f5ef2a3
commit a025392a30
4 changed files with 52 additions and 1 deletions

View File

@@ -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.

View File

@@ -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);

View File

@@ -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"
}

View File

@@ -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"
}