diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index 12f5f4bb8c..28b1330f27 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -19,6 +19,22 @@ export default function ({ types: t }) { } }, + ImportDeclaration(path) { + if (!path.node.specifiers.length) return; + + let typeCount = 0; + + path.node.specifiers.forEach(({ importKind }) => { + if (importKind === "type" || importKind === "typeof") { + typeCount++; + } + }); + + if (typeCount === path.node.specifiers.length) { + path.remove(); + } + }, + Flow(path) { path.remove(); }, diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js index 3d96731ccf..aff79bc078 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js @@ -104,3 +104,4 @@ import {typeof V2} from "foo"; import {typeof V3, V4} from "foo"; export interface foo5 { p: number } export interface foo6 { p: T } +import 'foo'; diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js index adec467fc7..f8caa71ce1 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js @@ -92,7 +92,8 @@ var identity; import type from "foo"; import type2, { foo3 } from "bar"; -import "foo"; import { V1 } from "foo"; -import "foo"; + import { V4 } from "foo"; + +import 'foo';