Skip to content

Commit

Permalink
Try to detect named type import specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmalov committed Oct 5, 2019
1 parent 67ff5b8 commit 76e936d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,24 @@ ExportMap.parse = function (path, content, context) {
if (declaration.importKind === 'type') return null // skip Flow type imports
const importedSpecifiers = new Set()
const supportedTypes = new Set(['ImportDefaultSpecifier', 'ImportNamespaceSpecifier'])
let hasImportedType = false
if (declaration.specifiers) {
declaration.specifiers.forEach(specifier => {
if (supportedTypes.has(specifier.type)) {
const isType = specifier.importKind === 'type'
hasImportedType = hasImportedType || isType

if (supportedTypes.has(specifier.type) && !isType) {
importedSpecifiers.add(specifier.type)
}
if (specifier.type === 'ImportSpecifier') {
if (specifier.type === 'ImportSpecifier' && !isType) {
importedSpecifiers.add(specifier.imported.name)
}
})
}

// only Flow types were imported
if (hasImportedType && importedSpecifiers.size === 0) return null

const p = remotePath(declaration.source.value)
if (p == null) return null
const existing = m.imports.get(p)
Expand Down
2 changes: 1 addition & 1 deletion tests/files/cycles/flow-types-depth-one.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import type { FooType } from './flow-types-depth-two';
import bar from './flow-types-depth-two';
import { type BarType, bar } from './flow-types-depth-two';

export { bar }
1 change: 1 addition & 0 deletions tests/files/cycles/flow-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import type { FooType } from './flow-types-depth-two';
import { type BarType } from './flow-types-depth-two';

export const bar = 1;

0 comments on commit 76e936d

Please sign in to comment.