Skip to content

Commit

Permalink
fix corner case in ie (#5962)
Browse files Browse the repository at this point in the history
fixes #5961
  • Loading branch information
alexlamsl authored Nov 16, 2024
1 parent 9d148fb commit d02156d
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -14372,7 +14372,13 @@ Compressor.prototype.compress = function(node) {
if (!all(def.orig, function(sym) {
if (sym instanceof AST_SymbolConst) return false;
if (sym instanceof AST_SymbolFunarg) return !sym.unused && def.scope.resolve() !== fn;
if (sym instanceof AST_SymbolLambda) return !compressor.option("ie") || sym.scope === def.scope;
if (sym instanceof AST_SymbolLambda) {
if (!compressor.option("ie")) return true;
if (sym.scope === def.scope) return true;
return !all(def.orig, function(decl) {
return !(decl instanceof AST_SymbolVar);
});
}
if (sym instanceof AST_SymbolLet) return false;
return true;
})) return;
Expand Down
109 changes: 109 additions & 0 deletions test/compress/ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3476,6 +3476,43 @@ issue_5350_ie: {
}

issue_5958: {
options = {
dead_code: true,
evaluate: true,
ie: false,
inline: true,
loops: true,
sequences: true,
toplevel: true,
}
input: {
"use strict";
while (function() {
if (a === console.log("PASS")) {
var a = function b() {};
try {
a++;
} catch (b) {
b[a];
}
}
}());
}
expect: {
"use strict";
if (a = void 0, a === console.log("PASS")) {
var a = function b() {};
try {
a++;
} catch (b) {
b[a];
}
}
}
expect_stdout: "PASS"
}

issue_5958_ie: {
options = {
dead_code: true,
evaluate: true,
Expand Down Expand Up @@ -3511,3 +3548,75 @@ issue_5958: {
}
expect_stdout: "PASS"
}

issue_5961: {
options = {
ie: false,
inline: true,
toplevel: true,
}
input: {
for (var a in [ 1, 2 ]) {
(function() {
try {
(function f() {});
} finally {
var b = f, f = "FAIL";
console.log(b || "PASS");
}
})();
}
}
expect: {
for (var a in [ 1, 2 ]) {
b = void 0;
f = void 0;
try {
(function f() {});
} finally {
var b = f, f = "FAIL";
console.log(b || "PASS");
}
}
}
expect_stdout: [
"PASS",
"PASS",
]
}

issue_5961_ie: {
options = {
ie: true,
inline: true,
toplevel: true,
}
input: {
for (var a in [ 1, 2 ]) {
(function() {
try {
(function f() {});
} finally {
var b = f, f = "FAIL";
console.log(b || "PASS");
}
})();
}
}
expect: {
for (var a in [ 1, 2 ]) {
b = void 0;
f = void 0;
try {
(function f() {});
} finally {
var b = f, f = "FAIL";
console.log(b || "PASS");
}
}
}
expect_stdout: [
"PASS",
"PASS",
]
}

0 comments on commit d02156d

Please sign in to comment.