diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-06-15 01:29:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 01:29:01 +0800 |
commit | 8b2cfd45fa8dd4f01d9535ad43bc37ce4953e78d (patch) | |
tree | 81da2985dbaa0af9fa0056b5287081fe961842ae | |
parent | ae9f56be109ccc27003868e997143823957f874d (diff) | |
download | tracifyjs-8b2cfd45fa8dd4f01d9535ad43bc37ce4953e78d.tar.gz tracifyjs-8b2cfd45fa8dd4f01d9535ad43bc37ce4953e78d.zip |
fix corner case in `rename` (#4000)
fixes #3999
-rw-r--r-- | lib/scope.js | 7 | ||||
-rw-r--r-- | test/compress/ie8.js | 41 |
2 files changed, 41 insertions, 7 deletions
diff --git a/lib/scope.js b/lib/scope.js index 2f49df76..66314766 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -543,11 +543,8 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) { var redef = def.redefined(); var name = redef ? redef.rename || redef.name : next_name(); def.rename = name; - def.orig.forEach(function(sym) { - sym.name = name; - }); - def.references.forEach(function(sym) { - sym.name = name; + def.orig.concat(def.references).forEach(function(sym) { + if (sym.definition() === def) sym.name = name; }); } }); diff --git a/test/compress/ie8.js b/test/compress/ie8.js index e11e3651..c0049766 100644 --- a/test/compress/ie8.js +++ b/test/compress/ie8.js @@ -2223,13 +2223,13 @@ issue_3523_rename_ie8: { expect: { var a = 0, b, c = "FAIL"; (function() { - var c, n, t, o, a, r, f, i, u, e, h, l, v, y; + var c, n, t, o, a, r, e, f, i, u, h, l, v, y; })(); try { throw 0; } catch (e) { (function() { - (function n() { + (function e() { c = "PASS"; })(); })(); @@ -2522,3 +2522,40 @@ issue_3918: { } expect_stdout: "PASS" } + +issue_3999: { + rename = true + mangle = { + ie8: true, + } + input: { + (function() { + (function f() { + for (var i = 0; i < 2; i++) + try { + f[0]; + } catch (f) { + var f = 0; + console.log(i); + } + })(); + })(typeof f); + } + expect: { + (function() { + (function f() { + for (var c = 0; c < 2; c++) + try { + f[0]; + } catch (f) { + var f = 0; + console.log(c); + } + })(); + })(typeof f); + } + expect_stdout: [ + "0", + "1", + ] +} |