Skip to content

Commit 4b3f619

Browse files
authored
fix: do not remove type import used in TS import= (#14913)
* fix: do not remove type import used in TS import= * tweak typing
1 parent 5295cbe commit 4b3f619

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ import transpileNamespace from "./namespace";
1313
function isInType(path: NodePath) {
1414
switch (path.parent.type) {
1515
case "TSTypeReference":
16-
case "TSQualifiedName":
1716
case "TSExpressionWithTypeArguments":
1817
case "TSTypeQuery":
1918
return true;
19+
case "TSQualifiedName":
20+
return (
21+
// `import foo = ns.bar` is transformed to `var foo = ns.bar` and should not be removed
22+
path.parentPath.findParent(path => path.type !== "TSQualifiedName")
23+
.type !== "TSImportEqualsDeclaration"
24+
);
2025
case "ExportSpecifier":
2126
return (
22-
(path.parentPath.parent as t.ExportNamedDeclaration).exportKind ===
27+
// @ts-expect-error: DeclareExportDeclaration does not have `exportKind`
28+
(path.parentPath as NodePath<t.ExportSpecifier>).parent.exportKind ===
2329
"type"
2430
);
2531
default:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import nsa from "./module-a";
2+
import foo = nsa.bar;
3+
4+
import nsb from "./module-b";
5+
import bar = nsb.foo.bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["transform-typescript"]
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import nsa from "./module-a";
2+
var foo = nsa.bar;
3+
import nsb from "./module-b";
4+
var bar = nsb.foo.bar;

0 commit comments

Comments
 (0)