Skip to content

Commit ccb6323

Browse files
authored
Rewrite .tsx extension when using rewriteImportExtensions (#16022)
1 parent d25f265 commit ccb6323

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

packages/babel-preset-typescript/src/plugin-rewrite-ts-imports.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export default declare(function ({ types: t }) {
1616
? node.importKind
1717
: node.exportKind;
1818
if (kind === "value" && source && /[\\/]/.test(source.value)) {
19-
source.value = source.value.replace(/(\.[mc]?)ts$/, "$1js");
19+
source.value = source.value
20+
.replace(/(\.[mc]?)ts$/, "$1js")
21+
.replace(/\.tsx$/, ".js");
2022
}
2123
},
2224
},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import "./a.ts";
22
import "./a.mts";
33
import "./a.cts";
4+
import "./react.tsx";
5+
// .mtsx and .ctsx are not valid and should not be transformed.
6+
import "./react.mtsx";
7+
import "./react.ctsx";
48
import "a-package/file.ts";
59
// Bare import, it's either a node package or remapped by an import map
610
import "soundcloud.ts";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import "./a.js";
22
import "./a.mjs";
33
import "./a.cjs";
4+
import "./react.js";
5+
// .mtsx and .ctsx are not valid and should not be transformed.
6+
import "./react.mtsx";
7+
import "./react.ctsx";
48
import "a-package/file.js";
59
// Bare import, it's either a node package or remapped by an import map
610
import "soundcloud.ts";

0 commit comments

Comments
 (0)