diff --git a/packages/babel-plugin-transform-typescript/src/index.ts b/packages/babel-plugin-transform-typescript/src/index.ts index 1aa42d08e00f..1ef9ebcbcf24 100644 --- a/packages/babel-plugin-transform-typescript/src/index.ts +++ b/packages/babel-plugin-transform-typescript/src/index.ts @@ -24,9 +24,12 @@ function isInType(path: NodePath) { ); case "ExportSpecifier": return ( + // export { type foo }; + path.parent.exportKind === "type" || + // export type { foo }; // @ts-expect-error: DeclareExportDeclaration does not have `exportKind` (path.parentPath as NodePath).parent.exportKind === - "type" + "type" ); default: return false; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-1/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-1/input.ts new file mode 100644 index 000000000000..56dfd0ba142f --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-1/input.ts @@ -0,0 +1,4 @@ +import { foo, bar, type baz } from "Foo"; +export { type foo }; +export type { bar }; +export { baz }; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-1/output.mjs b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-1/output.mjs new file mode 100644 index 000000000000..cb0ff5c3b541 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-1/output.mjs @@ -0,0 +1 @@ +export {}; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/input.ts new file mode 100644 index 000000000000..56dfd0ba142f --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/input.ts @@ -0,0 +1,4 @@ +import { foo, bar, type baz } from "Foo"; +export { type foo }; +export type { bar }; +export { baz }; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/options.json new file mode 100644 index 000000000000..ce280969f6e9 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [[ + "transform-typescript", + { + "onlyRemoveTypeImports": true + } + ]] +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/output.mjs b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/output.mjs new file mode 100644 index 000000000000..f112d980d494 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/imports/type-only-export-specifier-2/output.mjs @@ -0,0 +1,2 @@ +import { foo, bar } from "Foo"; +export {};