Skip to content

Commit

Permalink
fix corner case in ie8 & mangle (#3524)
Browse files Browse the repository at this point in the history
fixes #3523
  • Loading branch information
alexlamsl committed Oct 24, 2019
1 parent 0f7aa41 commit 82b3eed
Show file tree
Hide file tree
Showing 2 changed files with 387 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/scope.js
Expand Up @@ -214,7 +214,13 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
function redefine(node, scope) {
var name = node.name;
var old_def = node.thedef;
var new_def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
var new_def = scope.find_variable(name);
if (new_def) {
var redef;
while (redef = new_def.redefined()) new_def = redef;
} else {
new_def = self.globals.get(name) || scope.def_variable(node);
}
old_def.orig.concat(old_def.references).forEach(function(node) {
node.thedef = new_def;
node.reference(options);
Expand Down
380 changes: 380 additions & 0 deletions test/compress/ie8.js
Expand Up @@ -1959,3 +1959,383 @@ issue_3493_ie8: {
}
expect_stdout: "PASS"
}

issue_3523: {
mangle = {
ie8: false,
toplevel: false,
}
input: {
var a = 0, b, c = "FAIL";
(function() {
var f, g, h, i, j, k, l, m, n, o, p, q, r, s;
})();
try {
throw 0;
} catch (t) {
(function() {
(function t() {
c = "PASS";
})();
})();
(function e() {
try {} catch (t) {}
})();
}
console.log(c);
}
expect: {
var a = 0, b, c = "FAIL";
(function() {
var c, n, t, o, a, r, f, i, u, h, l, v, y, A;
})();
try {
throw 0;
} catch (n) {
(function() {
(function n() {
c = "PASS";
})();
})();
(function c() {
try {} catch (c) {}
})();
}
console.log(c);
}
expect_stdout: "PASS"
}

issue_3523_ie8: {
mangle = {
ie8: true,
toplevel: false,
}
input: {
var a = 0, b, c = "FAIL";
(function() {
var f, g, h, i, j, k, l, m, n, o, p, q, r, s;
})();
try {
throw 0;
} catch (t) {
(function() {
(function t() {
c = "PASS";
})();
})();
(function e() {
try {} catch (t) {}
})();
}
console.log(c);
}
expect: {
var a = 0, b, c = "FAIL";
(function() {
var c, t, n, o, a, r, f, i, u, h, e, l, v, y;
})();
try {
throw 0;
} catch (t) {
(function() {
(function t() {
c = "PASS";
})();
})();
(function e() {
try {} catch (t) {}
})();
}
console.log(c);
}
expect_stdout: "PASS"
}

issue_3523_toplevel: {
mangle = {
ie8: false,
toplevel: true,
}
input: {
var a = 0, b, c = "FAIL";
(function() {
var f, g, h, i, j, k, l, m, n, o, p, q, r, s;
})();
try {
throw 0;
} catch (t) {
(function() {
(function t() {
c = "PASS";
})();
})();
(function e() {
try {} catch (t) {}
})();
}
console.log(c);
}
expect: {
var c = 0, n, t = "FAIL";
(function() {
var c, n, t, o, r, a, f, i, u, h, l, v, y, A;
})();
try {
throw 0;
} catch (c) {
(function() {
(function c() {
t = "PASS";
})();
})();
(function c() {
try {} catch (c) {}
})();
}
console.log(t);
}
expect_stdout: "PASS"
}

issue_3523_ie8_toplevel: {
mangle = {
ie8: true,
toplevel: true,
}
input: {
var a = 0, b, c = "FAIL";
(function() {
var f, g, h, i, j, k, l, m, n, o, p, q, r, s;
})();
try {
throw 0;
} catch (t) {
(function() {
(function t() {
c = "PASS";
})();
})();
(function e() {
try {} catch (t) {}
})();
}
console.log(c);
}
expect: {
var c = 0, n, t = "FAIL";
(function() {
var c, n, t, o, r, a, f, i, u, h, l, v, y, A;
})();
try {
throw 0;
} catch (o) {
(function() {
(function o() {
t = "PASS";
})();
})();
(function r() {
try {} catch (o) {}
})();
}
console.log(t);
}
expect_stdout: "PASS"
}

issue_3523_rename: {
rename = true
mangle = {
ie8: false,
toplevel: false,
}
input: {
var a = 0, b, c = "FAIL";
(function() {
var d, e, f, g, h, i, j, k, l, m, o, p, q, r;
})();
try {
throw 0;
} catch (e) {
(function() {
(function e() {
c = "PASS";
})();
})();
(function d() {
try {
} catch (e) {
}
})();
}
console.log(c);
}
expect: {
var a = 0, b, c = "FAIL";
(function() {
var c, n, t, o, a, r, f, i, u, h, l, v, y, A;
})();
try {
throw 0;
} catch (n) {
(function() {
(function n() {
c = "PASS";
})();
})();
(function c() {
try {} catch (c) {}
})();
}
console.log(c);
}
expect_stdout: "PASS"
}

issue_3523_rename_ie8: {
rename = true
mangle = {
ie8: true,
toplevel: false,
}
input: {
var a = 0, b, c = "FAIL";
(function() {
var d, e, f, g, h, i, j, k, l, m, o, p, q, r;
})();
try {
throw 0;
} catch (e) {
(function() {
(function e() {
c = "PASS";
})();
})();
(function d() {
try {
} catch (e) {
}
})();
}
console.log(c);
}
expect: {
var a = 0, b, c = "FAIL";
(function() {
var c, n, t, o, a, r, f, i, u, e, h, l, v, y;
})();
try {
throw 0;
} catch (e) {
(function() {
(function n() {
c = "PASS";
})();
})();
(function d() {
try {} catch (e) {}
})();
}
console.log(c);
}
expect_stdout: "PASS"
}

issue_3523_rename_toplevel: {
rename = true
mangle = {
ie8: false,
toplevel: true,
}
input: {
var a = 0, b, c = "FAIL";
(function() {
var d, e, f, g, h, i, j, k, l, m, o, p, q, r;
})();
try {
throw 0;
} catch (e) {
(function() {
(function e() {
c = "PASS";
})();
})();
(function d() {
try {
} catch (e) {
}
})();
}
console.log(c);
}
expect: {
var c = 0, n, t = "FAIL";
(function() {
var c, n, t, o, r, a, f, i, u, h, l, v, y, A;
})();
try {
throw 0;
} catch (c) {
(function() {
(function c() {
t = "PASS";
})();
})();
(function c() {
try {} catch (c) {}
})();
}
console.log(t);
}
expect_stdout: "PASS"
}

issue_3523_rename_ie8_toplevel: {
rename = true
mangle = {
ie8: true,
toplevel: true,
}
input: {
var a = 0, b, c = "FAIL";
(function() {
var d, e, f, g, h, i, j, k, l, m, o, p, q, r;
})();
try {
throw 0;
} catch (e) {
(function() {
(function e() {
c = "PASS";
})();
})();
(function d() {
try {
} catch (e) {
}
})();
}
console.log(c);
}
expect: {
var c = 0, n, t = "FAIL";
(function() {
var c, n, t, o, r, a, f, i, u, h, l, v, y, A;
})();
try {
throw 0;
} catch (o) {
(function() {
(function o() {
t = "PASS";
})();
})();
(function r() {
try {} catch (o) {}
})();
}
console.log(t);
}
expect_stdout: "PASS"
}

0 comments on commit 82b3eed

Please sign in to comment.