Repository: babel/babel (TypeScript)

Issue:
`rewriteImportExtensions` option for TS preset does not work with .tsx files
### 💻

- [x] Would you like to work on this feature?

### What problem are you trying to solve?

#15913 introduced a useful option for the TS preset which allows TS code authored using `"moduleResolution": "NodeNext"` and `"allowImportingTsExtensions": true` to be transpiled to JS without breaking imports. Unfortunately, this setting does not currently apply to TSX files and imports.

### Describe the solution you'd like

Include .tsx files in the new behavior introduced by the flag.

### Describe alternatives you've considered

Don't use `"moduleResolution": "NodeNext"` or `"allowImportingTsExtensions": true`.

### Documentation, Adoption, Migration Strategy

Unclear if this would be considered a breaking change? Seems like a fix to me.


Hints:
Hey @jimmydief! 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-preset-typescript/src/plugin-rewrite-ts-imports.ts b/packages/babel-preset-typescript/src/plugin-rewrite-ts-imports.ts
--- a/packages/babel-preset-typescript/src/plugin-rewrite-ts-imports.ts
+++ b/packages/babel-preset-typescript/src/plugin-rewrite-ts-imports.ts
@@ -16,7 +16,9 @@ export default declare(function ({ types: t }) {
           ? node.importKind
           : node.exportKind;
         if (kind === "value" && source && /[\\/]/.test(source.value)) {
-          source.value = source.value.replace(/(\.[mc]?)ts$/, "$1js");
+          source.value = source.value
+            .replace(/(\.[mc]?)ts$/, "$1js")
+            .replace(/\.tsx$/, ".js");
         }
       },
     },


Test patch:
diff --git a/packages/babel-preset-typescript/test/fixtures/opts/rewriteImportExtensions/input.ts b/packages/babel-preset-typescript/test/fixtures/opts/rewriteImportExtensions/input.ts
--- a/packages/babel-preset-typescript/test/fixtures/opts/rewriteImportExtensions/input.ts
+++ b/packages/babel-preset-typescript/test/fixtures/opts/rewriteImportExtensions/input.ts
@@ -1,6 +1,10 @@
 import "./a.ts";
 import "./a.mts";
 import "./a.cts";
+import "./react.tsx";
+// .mtsx and .ctsx are not valid and should not be transformed.
+import "./react.mtsx";
+import "./react.ctsx";
 import "a-package/file.ts";
 // Bare import, it's either a node package or remapped by an import map
 import "soundcloud.ts";
diff --git a/packages/babel-preset-typescript/test/fixtures/opts/rewriteImportExtensions/output.mjs b/packages/babel-preset-typescript/test/fixtures/opts/rewriteImportExtensions/output.mjs
--- a/packages/babel-preset-typescript/test/fixtures/opts/rewriteImportExtensions/output.mjs
+++ b/packages/babel-preset-typescript/test/fixtures/opts/rewriteImportExtensions/output.mjs
@@ -1,6 +1,10 @@
 import "./a.js";
 import "./a.mjs";
 import "./a.cjs";
+import "./react.js";
+// .mtsx and .ctsx are not valid and should not be transformed.
+import "./react.mtsx";
+import "./react.ctsx";
 import "a-package/file.js";
 // Bare import, it's either a node package or remapped by an import map
 import "soundcloud.ts";