Repository: babel/babel (TypeScript)

Issue:
[Bug]: "Support for the experimental syntax 'importReflection' isn't currently enabled" triggered incorrectly on some import statements
### 💻

- [ ] Would you like to work on a fix?

### How are you using Babel?

babel-loader (webpack)

### Input code

https://babel.dev/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=PTAEHcHsCcGsGcBQBLAtgBxgF1KyATAVwBsBTUAM2klVAHI8iy6BuRECGBFDbUAb1ABjaKQCGWUgCVSAR0LJRoAL6VqtBgRKlW7MACNRY7mkzQcjbQBoBwo5JnzF5VVRr1LzFkA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=&prettier=false&targets=&version=7.20.4&externalPlugins=&assumptions=%7B%7D

### Configuration file name

_No response_

### Configuration

_No response_

### Current and expected behavior

In our monorepo, one of the packages has a line like:

`import module, { createRequire } from 'module';`

for the actual [node Module API](https://nodejs.org/api/module.html). On a recent upgrade attempt (@babel/parser 7.19.4 -> 7.20.1 I believe), we were seeing `Support for the experimental syntax 'importReflection' isn't currently enabled`, however, this is not an attempted usage of importReflection. I suspect the logic [introduced in this PR](https://github.com/babel/babel/pull/14926/files#diff-dde20a4c39ac9fc963a227ec21025e1af1368f92d8c0d1db85274b199adb1cf4R2666) incorrectly flags this case as importReflection.

Workaround was to simply change the default import name.

Expected behavior would be for `module` to work as a default import name when also importing named functions, regardless of `importReflection` status.

### Environment

  System:
    OS: Linux 5.4 Ubuntu 18.04.5 LTS (Bionic Beaver)
  Binaries:
    Node: 16.13.2 - /nail/tmp/xfs-d1ce38f1/node
    Yarn: 3.2.0 - /nail/tmp/xfs-d1ce38f1/yarn
    npm: 8.1.2 - /opt/nodejs/node-v16.13.2/bin/npm
  Monorepos:
    Yarn Workspaces: 3.2.0
    Lerna: 3.18.3
  npmPackages:
    @babel/core: ^7.15.5 => 7.19.3
    babel-jest: ^29.1.2 => 29.1.2
    babel-plugin-smart-webpack-import: ^2.0.0 => 2.0.0
    jest: ^29.1.2 => 29.1.2
    lerna: ^3.16.4 => 3.18.3

### Possible solution

Likely a slight tweak to this logic: https://github.com/babel/babel/blob/31386b9eb4863eb07ec2d302e2cfcfa039eaf644/packages/babel-parser/src/parser/statement.ts#L2746

### Additional context

_No response_


Hints:
Hey @jpm4! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant [Slack community](https://babeljs.slack.com) that typically always has someone willing to help. You can sign-up [here](https://slack.babeljs.io/) for an invite.

Patch:
diff --git a/packages/babel-parser/src/parser/statement.ts b/packages/babel-parser/src/parser/statement.ts
--- a/packages/babel-parser/src/parser/statement.ts
+++ b/packages/babel-parser/src/parser/statement.ts
@@ -2747,8 +2747,9 @@ export default abstract class StatementParser extends ExpressionParser {
     let isImportReflection = false;
     if (this.isContextual(tt._module)) {
       const lookahead = this.lookahead();
-      if (tokenIsIdentifier(lookahead.type)) {
-        if (lookahead.type !== tt._from) {
+      const nextType = lookahead.type;
+      if (tokenIsIdentifier(nextType)) {
+        if (nextType !== tt._from) {
           // import module x
           isImportReflection = true;
         } else {
@@ -2760,9 +2761,10 @@ export default abstract class StatementParser extends ExpressionParser {
             isImportReflection = true;
           }
         }
-      } else {
+      } else if (nextType !== tt.comma) {
         // import module { x } ...
-        // This is invalid, we will continue parsing and throw
+        // import module "foo"
+        // They are invalid, we will continue parsing and throw
         // a recoverable error later
         isImportReflection = true;
       }


Test patch:
diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-module-as-default-binding-2/input.mjs b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-module-as-default-binding-2/input.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-module-as-default-binding-2/input.mjs
@@ -0,0 +1 @@
+import module, { createRequire } from "module";
diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-module-as-default-binding-2/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-module-as-default-binding-2/output.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-module-as-default-binding-2/output.json
@@ -0,0 +1,52 @@
+{
+  "type": "File",
+  "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":47,"index":47}},
+  "program": {
+    "type": "Program",
+    "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":47,"index":47}},
+    "sourceType": "module",
+    "interpreter": null,
+    "body": [
+      {
+        "type": "ImportDeclaration",
+        "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":47,"index":47}},
+        "specifiers": [
+          {
+            "type": "ImportDefaultSpecifier",
+            "start":7,"end":13,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":13,"index":13}},
+            "local": {
+              "type": "Identifier",
+              "start":7,"end":13,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":13,"index":13},"identifierName":"module"},
+              "name": "module"
+            }
+          },
+          {
+            "type": "ImportSpecifier",
+            "start":17,"end":30,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":30,"index":30}},
+            "imported": {
+              "type": "Identifier",
+              "start":17,"end":30,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":30,"index":30},"identifierName":"createRequire"},
+              "name": "createRequire"
+            },
+            "local": {
+              "type": "Identifier",
+              "start":17,"end":30,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":30,"index":30},"identifierName":"createRequire"},
+              "name": "createRequire"
+            }
+          }
+        ],
+        "module": false,
+        "source": {
+          "type": "StringLiteral",
+          "start":38,"end":46,"loc":{"start":{"line":1,"column":38,"index":38},"end":{"line":1,"column":46,"index":46}},
+          "extra": {
+            "rawValue": "module",
+            "raw": "\"module\""
+          },
+          "value": "module"
+        }
+      }
+    ],
+    "directives": []
+  }
+}