Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix corner case in ie #5962

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
}