Skip to content

Commit 4d1cde6

Browse files
committed
Keep import statement if all of specifiers are type-only one
1 parent 8cb6dc0 commit 4d1cde6

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

packages/babel-plugin-transform-typescript/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export default declare((api, opts) => {
288288
}
289289
}
290290

291-
if (isAllSpecifiersElided()) {
291+
if (!onlyRemoveTypeImports && isAllSpecifiersElided()) {
292292
stmt.remove();
293293
} else {
294294
for (const importPath of importsToRemove) {

packages/babel-plugin-transform-typescript/test/fixtures/imports/only-remove-type-imports/output.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import d, { d2 } from "d";
55
import e, { e3 as e4 } from "e";
66
import "f";
77
import "g";
8+
import "k";
89
import { L2 } from "l";
910
;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { type A } from "x";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"plugins": [
3+
[
4+
"transform-typescript",
5+
{
6+
"onlyRemoveTypeImports": true
7+
}
8+
]
9+
]
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "x";

0 commit comments

Comments
 (0)