Remove import declaration when stripping flowtypes if only type/typeof specifiers (#5782)

This commit is contained in:
Brian Ng
2017-05-26 14:36:46 -05:00
committed by Henry Zhu
parent 9e2ef0cf9e
commit 4ae39239b5
3 changed files with 20 additions and 2 deletions

View File

@@ -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();
},

View File

@@ -104,3 +104,4 @@ import {typeof V2} from "foo";
import {typeof V3, V4} from "foo";
export interface foo5 { p: number }
export interface foo6<T> { p: T }
import 'foo';

View File

@@ -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';