From e05422b4fc21a34dc98aaa5a07822f40967d0c65 Mon Sep 17 00:00:00 2001 From: Jeff Morrison Date: Sat, 24 Dec 2016 17:30:13 -0600 Subject: [PATCH] Strip Flow's new shorthand import-type specifiers --- .../babel-plugin-transform-flow-strip-types/src/index.js | 9 ++++++++- .../strip-types/strip-type-annotations/actual.js | 4 ++++ .../strip-types/strip-type-annotations/expected.js | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) 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 c64abb9a52fe..cae92de95b28 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -57,7 +57,14 @@ export default function ({ types: t }) { node = node.expression; } while (t.isTypeCastExpression(node)); path.replaceWith(node); - } + }, + + ImportSpecifier(path) { + const { node } = path; + if (node.importKind !== null) { + 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 36cfd7f425e9..f602db2cbc4d 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 @@ -97,5 +97,9 @@ import type2, { foo3 } from "bar"; import type * as namespace from "bar"; export type { foo }; export type { foo2 } from "bar"; +import {type T} from "foo"; +import {type T2, V1} from "foo"; +import {typeof V2} from "foo"; +import {typeof V3, V4} from "foo"; export interface foo5 { p: number } export interface foo6 { p: T } 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 62bf507aaecf..a6c982a6a32f 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 @@ -90,3 +90,8 @@ var identity; import type from "foo"; import type2, { foo3 } from "bar"; + +import "foo"; +import { V1 } from "foo"; +import "foo"; +import { V4 } from "foo";