From: Alex Lam S.L Date: Tue, 15 Oct 2019 06:18:12 +0000 (+0800) Subject: fix corner case in `ie8` & `mangle` (#3476) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f86f615d836049fbae03271b59a67b8a9ca90ef7;p=UglifyJS.git fix corner case in `ie8` & `mangle` (#3476) fixes #3475 --- diff --git a/lib/scope.js b/lib/scope.js index 1b570515..bd6cb26a 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -201,7 +201,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { } if (node instanceof AST_SymbolLambda) { var def = node.thedef; - redefine(node, node.scope.parent_scope); + redefine(node, node.scope.parent_scope.resolve()); node.thedef.init = def.init; return true; } diff --git a/test/compress/ie8.js b/test/compress/ie8.js index 9fc2becd..586955d9 100644 --- a/test/compress/ie8.js +++ b/test/compress/ie8.js @@ -1189,3 +1189,135 @@ issue_3473_ie8_toplevel: { } expect_stdout: "100 10 1" } + +issue_3475: { + rename = true + mangle = { + ie8: false, + toplevel: false, + } + input: { + "ooooo ddddd"; + var a = "FAIL"; + try { + throw 42; + } catch (b) { + (function f() { + a = "PASS"; + })(); + } + console.log(a); + } + expect: { + "ooooo ddddd"; + var a = "FAIL"; + try { + throw 42; + } catch (o) { + (function o() { + a = "PASS"; + })(); + } + console.log(a); + } + expect_stdout: "PASS" +} + +issue_3475_ie8: { + rename = true + mangle = { + ie8: true, + toplevel: false, + } + input: { + "ooooo ddddd"; + var a = "FAIL"; + try { + throw 42; + } catch (b) { + (function f() { + a = "PASS"; + })(); + } + console.log(a); + } + expect: { + "ooooo ddddd"; + var a = "FAIL"; + try { + throw 42; + } catch (b) { + (function f() { + a = "PASS"; + })(); + } + console.log(a); + } + expect_stdout: "PASS" +} + +issue_3475_toplevel: { + rename = true + mangle = { + ie8: false, + toplevel: true, + } + input: { + "ooooo ddddd"; + var a = "FAIL"; + try { + throw 42; + } catch (b) { + (function f() { + a = "PASS"; + })(); + } + console.log(a); + } + expect: { + "ooooo ddddd"; + var d = "FAIL"; + try { + throw 42; + } catch (o) { + (function o() { + d = "PASS"; + })(); + } + console.log(d); + } + expect_stdout: "PASS" +} + +issue_3475_ie8_toplevel: { + rename = true + mangle = { + ie8: true, + toplevel: true, + } + input: { + "ooooo ddddd"; + var a = "FAIL"; + try { + throw 42; + } catch (b) { + (function f() { + a = "PASS"; + })(); + } + console.log(a); + } + expect: { + "ooooo ddddd"; + var o = "FAIL"; + try { + throw 42; + } catch (d) { + (function c() { + o = "PASS"; + })(); + } + console.log(o); + } + expect_stdout: "PASS" +} diff --git a/test/compress/rename.js b/test/compress/rename.js index eab989b1..08429d7c 100644 --- a/test/compress/rename.js +++ b/test/compress/rename.js @@ -579,7 +579,7 @@ function_do_catch_ie8: { console.log(b, c); } expect: { - var t = 1, u = 1, y = 0; + var u = 1, y = 1, a = 0; function c(c) { var d; do { @@ -587,7 +587,7 @@ function_do_catch_ie8: { try { var e = void 0; } catch (i) { - --t && w("ddddddddeeeeeeegggggggggiiiiilllllllnnnnntuuuuuuuuyyyyyyy"); + --u && w("ddddddddeeeeeeegggggggggiiiiilllllllnnnnntuuuuuuuuyyyyyyy"); 0; 0; 0; @@ -596,18 +596,18 @@ function_do_catch_ie8: { d[1]; } catch (l) { var g; - switch(function x() { - y++; + switch (function n() { + a++; }()) { - case e + --g: + case e + --g: } } - } catch (n) {} + } catch (t) {} } while (--d); - u--; + y--; } c(); - console.log(u, y); + console.log(y, a); } expect_stdout: "0 1" }