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: remove imported types from export #13800

Merged
merged 2 commits into from Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions packages/babel-plugin-transform-typescript/src/index.ts
Expand Up @@ -47,8 +47,8 @@ function isGlobalType(path, name) {
return false;
}

function registerGlobalType(programScope, name) {
GLOBAL_TYPES.get(programScope.path.node).add(name);
function registerGlobalType(programNode, name) {
GLOBAL_TYPES.get(programNode).add(name);
}

export default declare((api, opts) => {
Expand Down Expand Up @@ -188,9 +188,10 @@ export default declare((api, opts) => {
const { file } = state;
let fileJsxPragma = null;
let fileJsxPragmaFrag = null;
const programNode = path.node;

if (!GLOBAL_TYPES.has(path.node)) {
GLOBAL_TYPES.set(path.node, new Set());
if (!GLOBAL_TYPES.has(programNode)) {
GLOBAL_TYPES.set(programNode, new Set());
}

if (file.ast.comments) {
Expand Down Expand Up @@ -225,6 +226,9 @@ export default declare((api, opts) => {
}

if (stmt.node.importKind === "type") {
for (const specifier of stmt.node.specifiers) {
registerGlobalType(programNode, specifier.local.name);
}
stmt.remove();
continue;
}
Expand Down Expand Up @@ -287,7 +291,7 @@ export default declare((api, opts) => {

if (stmt.isVariableDeclaration({ declare: true })) {
for (const name of Object.keys(stmt.getBindingIdentifiers())) {
registerGlobalType(path.scope, name);
registerGlobalType(programNode, name);
}
} else if (
stmt.isTSTypeAliasDeclaration() ||
Expand All @@ -298,7 +302,7 @@ export default declare((api, opts) => {
(stmt.isTSModuleDeclaration({ declare: true }) &&
stmt.get("id").isIdentifier())
) {
registerGlobalType(path.scope, stmt.node.id.name);
registerGlobalType(programNode, stmt.node.id.name);
}
}
},
Expand Down
@@ -0,0 +1,5 @@
import type A from "A";
import type { B } from "B";
import C from "C";

export { A, B, C } // <-- A and B will be removed
@@ -0,0 +1,2 @@
import C from "C";
export { C }; // <-- A and B will be removed