Skip to content

Commit

Permalink
fix: do not remove type import used in TS import= (#14913)
Browse files Browse the repository at this point in the history
* fix: do not remove type import used in TS import=

* tweak typing
  • Loading branch information
JLHwung committed Sep 6, 2022
1 parent 5295cbe commit 4b3f619
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/babel-plugin-transform-typescript/src/index.ts
Expand Up @@ -13,13 +13,19 @@ import transpileNamespace from "./namespace";
function isInType(path: NodePath) {
switch (path.parent.type) {
case "TSTypeReference":
case "TSQualifiedName":
case "TSExpressionWithTypeArguments":
case "TSTypeQuery":
return true;
case "TSQualifiedName":
return (
// `import foo = ns.bar` is transformed to `var foo = ns.bar` and should not be removed
path.parentPath.findParent(path => path.type !== "TSQualifiedName")
.type !== "TSImportEqualsDeclaration"
);
case "ExportSpecifier":
return (
(path.parentPath.parent as t.ExportNamedDeclaration).exportKind ===
// @ts-expect-error: DeclareExportDeclaration does not have `exportKind`
(path.parentPath as NodePath<t.ExportSpecifier>).parent.exportKind ===
"type"
);
default:
Expand Down
@@ -0,0 +1,5 @@
import nsa from "./module-a";
import foo = nsa.bar;

import nsb from "./module-b";
import bar = nsb.foo.bar;
@@ -0,0 +1,3 @@
{
"plugins": ["transform-typescript"]
}
@@ -0,0 +1,4 @@
import nsa from "./module-a";
var foo = nsa.bar;
import nsb from "./module-b";
var bar = nsb.foo.bar;

0 comments on commit 4b3f619

Please sign in to comment.