Skip to content

Commit

Permalink
Merge 76e936d into 5e143b2
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmalov committed Oct 5, 2019
2 parents 5e143b2 + 76e936d commit 8d1aa94
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,19 +397,27 @@ ExportMap.parse = function (path, content, context) {

function captureDependency(declaration) {
if (declaration.source == null) return null
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
6 changes: 6 additions & 0 deletions tests/files/cycles/flow-types-depth-one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow

import type { FooType } 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-depth-two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { foo } from './depth-one'
6 changes: 6 additions & 0 deletions tests/files/cycles/flow-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow

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

export const bar = 1;
9 changes: 9 additions & 0 deletions tests/src/rules/no-cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ ruleTester.run('no-cycle', rule, {
code: 'import type { FooType, BarType } from "./depth-one"',
parser: require.resolve('babel-eslint'),
}),
test({
code: 'import { bar } from "./flow-types"',
parser: require.resolve('babel-eslint'),
}),
],
invalid: [
test({
Expand Down Expand Up @@ -120,6 +124,11 @@ ruleTester.run('no-cycle', rule, {
errors: [error(`Dependency cycle via ./depth-two:1=>./depth-one:1`)],
parser: require.resolve('babel-eslint'),
}),
test({
code: 'import { bar } from "./flow-types-depth-one"',
parser: require.resolve('babel-eslint'),
errors: [error(`Dependency cycle via ./flow-types-depth-two:4=>./depth-one:1`)],
}),
],
})
// })

0 comments on commit 8d1aa94

Please sign in to comment.