fix corner case in `ie8` (#4230)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 19 Oct 2020 22:13:23 +0000 (23:13 +0100)
committerGitHub <noreply@github.com>
Mon, 19 Oct 2020 22:13:23 +0000 (06:13 +0800)
fixes #4229

lib/scope.js
test/compress/const.js
test/compress/let.js

index 4abf406..208633d 100644 (file)
@@ -294,6 +294,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
             node.redef = true;
             node.thedef = new_def;
             node.reference(options);
+            if (node instanceof AST_SymbolConst || node instanceof AST_SymbolLet) new_def.orig.push(node);
         });
         if (old_def.lambda) new_def.lambda = true;
         if (new_def.undeclared) self.variables.set(name, new_def);
index 8bb9a94..b20c4c5 100644 (file)
@@ -1045,3 +1045,23 @@ issue_4225: {
     }
     expect_stdout: true
 }
+
+issue_4229: {
+    options = {
+        ie8: true,
+        side_effects: true,
+    }
+    input: {
+        (function f() {
+            f;
+            const f = 42;
+        })();
+    }
+    expect: {
+        (function f() {
+            f;
+            const f = 42;
+        })();
+    }
+    expect_stdout: true
+}
index 74e8fd8..c40ae9e 100644 (file)
@@ -840,3 +840,34 @@ issue_4225: {
     expect_stdout: true
     node_version: ">=4"
 }
+
+issue_4229: {
+    options = {
+        ie8: true,
+        side_effects: true,
+    }
+    input: {
+        "use strict";
+        try {
+            (function f() {
+                f;
+                let f;
+            })();
+        } catch (e) {
+            console.log("PASS");
+        }
+    }
+    expect: {
+        "use strict";
+        try {
+            (function f() {
+                f;
+                let f;
+            })();
+        } catch (e) {
+            console.log("PASS");
+        }
+    }
+    expect_stdout: "PASS"
+    node_version: ">=4"
+}