aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-10-24 23:43:19 +0800
committerGitHub <noreply@github.com>2019-10-24 23:43:19 +0800
commit82b3eed5ef7fa8c3b031778817b325f26db7b5cb (patch)
tree60d30b7c7e8bc3b1423ee6fdf554fb533f1d4884
parent0f7aa41e339b574ee0f67c093438d356a8a85477 (diff)
downloadtracifyjs-82b3eed5ef7fa8c3b031778817b325f26db7b5cb.tar.gz
tracifyjs-82b3eed5ef7fa8c3b031778817b325f26db7b5cb.zip
fix corner case in `ie8` & `mangle` (#3524)
fixes #3523
-rw-r--r--lib/scope.js8
-rw-r--r--test/compress/ie8.js380
2 files changed, 387 insertions, 1 deletions
diff --git a/lib/scope.js b/lib/scope.js
index 6e33365c..edefc29b 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -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);
diff --git a/test/compress/ie8.js b/test/compress/ie8.js
index 4637451c..1a840262 100644
--- a/test/compress/ie8.js
+++ b/test/compress/ie8.js
@@ -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"
+}