fix corner case with `import` (#4672)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 21 Feb 2021 02:00:34 +0000 (02:00 +0000)
committerGitHub <noreply@github.com>
Sun, 21 Feb 2021 02:00:34 +0000 (10:00 +0800)
lib/scope.js
test/compress/imports.js

index f638890..9702727 100644 (file)
@@ -197,7 +197,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
         } else if (node instanceof AST_SymbolLet) {
             scope.def_variable(node).exported = exported;
         } else if (node instanceof AST_SymbolVar) {
-            defun.def_variable(node, null).exported = exported;
+            defun.def_variable(node, node instanceof AST_SymbolImport ? undefined : null).exported = exported;
             entangle(defun, scope);
         }
 
index 03ebf99..f8313b0 100644 (file)
@@ -128,3 +128,19 @@ rename_mangle: {
         import * as r from "moz";
     }
 }
+
+keep_ref: {
+    options = {
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        import foo from "bar";
+        foo();
+    }
+    expect: {
+        import foo from "bar";
+        foo();
+    }
+}