parse dynamic `import` correctly (#4671)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 20 Feb 2021 22:54:15 +0000 (22:54 +0000)
committerGitHub <noreply@github.com>
Sat, 20 Feb 2021 22:54:15 +0000 (06:54 +0800)
lib/parse.js
test/compress/imports.js

index 04b4014..39465d7 100644 (file)
@@ -848,8 +848,10 @@ function parse($TEXT, options) {
                 next();
                 return export_();
               case "import":
-                next();
-                return import_();
+                if (!is_token(peek(), "punc", "(")) {
+                    next();
+                    return import_();
+                }
               case "yield":
                 if (S.in_generator) return simple_statement();
                 break;
index cdc239c..03ebf99 100644 (file)
@@ -47,6 +47,13 @@ dynamic: {
     expect_exact: '(async a=>await import(a))("foo").then(bar);'
 }
 
+dynamic_nought: {
+    input: {
+        import(foo);
+    }
+    expect_exact: "import(foo);"
+}
+
 import_meta: {
     input: {
         console.log(import.meta, import.meta.url);