Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not remove type import used in TS import= #14913

Merged
merged 2 commits into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;